nupic-legacy icon indicating copy to clipboard operation
nupic-legacy copied to clipboard

Support better extensibility of Connections

Open oxtopus opened this issue 8 years ago • 2 comments

As a developer, I want to subclass CellData, or otherwise control some aspect of the creation of the CellData instance in my subclass. Currently, Connections.__init__() references CellData directly, requiring the user to either completely reimplement __init__() in their subclass, or rely on some super() trickery to fixup the Connections instance after the fact.

oxtopus avatar Sep 13 '16 00:09 oxtopus

The CellData is not part of the public interface of the Connections. I'm not sure we should support extending it. It's an internal detail that we should be able to change without breaking anyone.

In your subclass of Connections you should be able to store extra cell data on the self. There's no reason we need to insert it into the CellData. For example, you could have a self.isDead list of bools.

mrcslws avatar Sep 14 '16 15:09 mrcslws

Fair enough. If that's the case, we should do a better job of conveying that intent by naming it something like _CellData or PrivateCellData. For that matter, given that it only exists as a container for attrs, create a type that is encapsulated within, and private to Connections e.g.:

class Connections(object):
  ...
  def __init__(...):
    ...
    def _cellDataInit(cellData):
      cellData._segments=[]
      cellData._numDestroyedSegments=0

    _CellData = type('_CellData', (object,), dict(__slots__=("_segments", "_numDestroyedSegments"), __init__=_cellDataInit))

    self._cells = [_CellData() for _ in xrange(numCells)]
    ...

oxtopus avatar Sep 14 '16 16:09 oxtopus