append and remove

This commit is contained in:
Jiaqi 2020-09-04 11:17:29 +08:00
parent 4781021c1d
commit 777e624515
1 changed files with 7 additions and 0 deletions

View File

@ -19,6 +19,7 @@ from ..cell import Cell
__all__ = ['SequentialCell', 'CellList']
def _valid_index(cell_num, index):
if not isinstance(index, int):
raise TypeError("Index {} is not int type")
@ -145,6 +146,12 @@ class SequentialCell(Cell):
for cell in self._cells.values():
cell.set_grad(flag)
def append(self, cell):
"""Appends a given cell to the end of the list."""
if _valid_cell(cell):
self._cells[str(len(self))] = cell
return self
def construct(self, input_data):
for cell in self.cell_list:
input_data = cell(input_data)