Input / Output

Input

class nupic::Input

Represents a named input to a Region.

(e.g. bottomUpIn)

Note
Input is not available in the public API, but is visible by the RegionImpl.

Public Types

typedef std::vector<std::vector<size_t>> SplitterMap

See
Link.buildSplitterMap()

Public Functions

Input(Region &region, NTA_BasicType type, bool isRegionLevel)

Constructor.

Parameters
  • region: The region that the input belongs to.
  • type: The type of the input, i.e. TODO
  • isRegionLevel: Whether the input is region level, i.e. TODO

~Input()

Destructor.

void setName(const std::string &name)

Set the name for the input.

Inputs need to know their own name for error messages.

Parameters
  • name: The name of the input

const std::string &getName() const

Get the name of the input.

Return
The name of the input

void addLink(Link *link, Output *srcOutput)

Add the given link to this input and to the list of links on the output.

Parameters
  • link: The link to add.
  • srcOutput: The output of previous Region, which is also the source of the input

Link *findLink(const std::string &srcRegionName, const std::string &srcOutputName)

Locate an existing Link to the input.

It’s called by Network.removeLink() and internally when adding a link

Return
The link if found or NULL if no such link exists
Parameters
  • srcRegionName: The name of the source Region
  • srcOutputName: The name of the source Output

Removing an existing link from the input.

It’s called in four cases:

  1. Network.removeLink()
  2. Network.removeRegion() when given srcRegion
  3. Network.removeRegion() when given destRegion
  4. Network.~Network()

It is an error to call this if our containing region is uninitialized.

Note
This method will set the Link pointer to NULL on return (to avoid a dangling reference)
Parameters
  • link: The Link to remove, possibly retrieved by findLink(), note that it is a reference to the pointer, not the pointer itself.

void prepare()

Make input data available.

Called by Region.prepareInputs()

const Array &getData() const

Get the data of the input.

Return
A mutable reference to the data of the input as an Array

Region &getRegion()

Get the Region that the input belongs to.

Return
The mutable reference to the Region that the input belongs to

const std::vector<Link *> &getLinks()

Get all the Link objects added to the input.

Return
All the Link objects added to the input

bool isRegionLevel()

Tells whether the input is region level.

Return
Whether the input is region level, i.e. TODO

size_t evaluateLinks()

Called by Region.evaluateLinks() as part of network initialization.

  1. Tries to make sure that dimensions at both ends of a link are specified by calling setSourceDimensions() if possible, and then calling getDestDimensions()
  2. Ensures that region dimensions are consistent with either by setting destination region dimensions (this is where links “induce” dimensions) or by raising an exception if they are inconsistent.

Return
Number of links that could not be fully evaluated, i.e. incomplete

void initialize()

Initialize the Input .

After the input has all the information it needs, it is initialized by this method. Volatile data structures (e.g. the input buffer) are set up。

bool isInitialized()

Tells whether the Input is initialized.

Return
Whether the Input is initialized

const SplitterMap &getSplitterMap() const

Get splitter map from an initialized input.

Return
The splitter map

template <typename T>
void getInputForNode(size_t nodeIndex, std::vector<T> &input) const

explicitly instantiated for various types

Output

class nupic::Output

Represents a named output to a Region.

Public Functions

Output(Region &region, NTA_BasicType type, bool isRegionLevel)

Constructor.

Parameters
  • region: The region that the output belongs to.
  • type: The type of the output, TODO
  • isRegionLevel: Whether the output is region level, i.e. TODO

~Output()

Destructor.

void setName(const std::string &name)

Set the name for the output.

Output need to know their own name for error messages.

Parameters
  • name: The name of the output

const std::string &getName() const

Get the name of the output.

Return
The name of the output

void initialize(size_t size)

Initialize the Output .

Note
It’s safe to reinitialize an initialized Output with the same parameters.
Parameters
  • size: The count of node output element, i.e. TODO

Add a Link to the Output .

Called by Input.addLink()

Note
The Output does NOT take ownership of link, it’s created and owned by an Input Object.

Parameters
  • link: The Link to add

Removing an existing link from the output.

Note
Called only by Input.removeLink() even if triggered by Network.removeRegion() while removing the region that contains us.
Parameters
  • link: The Link to remove

bool hasOutgoingLinks()

Tells whether the output has outgoing links.

Note
We cannot delete a region if there are any outgoing links This allows us to check in Network.removeRegion() and Network.~Network().
Return
Whether the output has outgoing links

const Array &getData() const

Get the data of the output.

Return
A constant reference to the data of the output as an Array
Note
It’s mportant to return a const array so caller can’t reallocate the buffer.

bool isRegionLevel() const

Tells whether the output is region level.

Return
Whether the output is region level, i.e. TODO

Region &getRegion() const

Get the Region that the output belongs to.

Return
The mutable reference to the Region that the output belongs to

size_t getNodeOutputElementCount() const

Get the count of node output element.

Return
The count of node output element, previously set by initialize().