Types¶
Dimensions¶

class
nupic::
Dimensions
¶ Represents the dimensions of a Region.
A Dimensions object is an ndimensional grid, consists of many cells, and each dimension has a size, i.e. how many cells can there be along this dimension.
A node within a Region is represented by a cell of a ndimensional grid, identified by a Coordinate.
It’s implemented by a
vector
ofsize_t
plus a few methods for convenience and for wrapping.Inherits from std::vector< size_t >
Constructors

Dimensions
()¶ Create a new Dimensions object.
 Note
 Default dimensions are unspecified, see isUnspecified()

Dimensions
(std::vector<size_t> v)¶ Create a new Dimensions object from a
std::vector<size_t>
. Parameters
v
: Astd::vector
ofsize_t
, the value with the index of n is the size of the n th dimension

Dimensions
(size_t x)¶ Create a new 1dimension Dimensions object.
 Parameters
x
: The size of the 1st dimension

Dimensions
(size_t x, size_t y)¶ Create a new 2dimension Dimensions.
 Parameters
x
: The size of the 1st dimensiony
: The size of the 2nd dimension

Dimensions
(size_t x, size_t y, size_t z)¶ Create a new 3dimension Dimensions.
 Parameters
x
: The size of the 1st dimensiony
: The size of the 2nd dimensionz
: The size of the 3rd dimension
Properties

size_t
getCount
() const¶ Get the count of cells in the grid, which is the product of the sizes of the dimensions.
 Return
 The count of cells in the grid.

size_t
getDimensionCount
() const¶ Get the number of dimensions.
 Return
 number of dimensions

size_t
getDimension
(size_t index) const¶ Get the size of a dimension.
 Return
 The size of the dimension with the index of index
 Note
 Do not confuse index with “linear index” as in getIndex()
 Parameters
index
: The index of the dimension
Boolean properties
There are two “special” values for dimensions:
 Dimensions of
[]
(dims.size()==0
) means “not yet known” aka “unspecified”, see isUnspecified()  Dimensions of
[0]
(dims.size()==1 && dims[0] == 0
) means “don’t care”, see isDontcare()

bool
isUnspecified
() const¶ Tells whether the Dimensions object is “unspecified”.
 Return
 Whether the Dimensions object is “unspecified”
 See
 isSpecified()

bool
isDontcare
() const¶ Tells whether the Dimensions object is “don’t care”.
 Return
 Whether the Dimensions object is “don’t care”

bool
isSpecified
() const¶ Tells whether the Dimensions object is “specified”.
A “specified” Dimensions object satisfies all following conditions:
 “valid”
 NOT “unspecified”
 NOT “don’t care”
 Return
 Whether the Dimensions object is “specified”
 Note
 It’s not the opposite of isUnspecified()!

bool
isOnes
() const¶ Tells whether the sizes of all dimensions are 1.
 Return
 Whether the sizes of all dimensions are 1, e.g. [1], [1 1], [1 1 1], etc.

bool
isValid
() const¶ Tells whether Dimensions is “valid”.
A Dimensions object is valid if it specifies actual dimensions, i.e. all dimensions have a size greater than 0, or is a special value (“unspecified”/”don’t care”).
A Dimensions object is invalid if any dimensions are 0 (except for “don’t care”)
 Return
 Whether Dimensions is “valid”
Coordinate<>index mapping
Coordinate<>index mapping is in lowermajor order, i.e.
for Region with dimensions
[2,3]
:[0,0] > index 0 [1,0] > index 1 [0,1] > index 2 [1,1] > index 3 [0,2] > index 4 [1,2] > index 5

size_t
getIndex
(const Coordinate &coordinate) const¶ Convert a Coordinate to a linear index (in lowermajor order).
 Return
 The linear index corresponding to coordinate
 Parameters
coordinate
: The coordinate to be converted

Coordinate
getCoordinate
(const size_t index) const¶ Convert a linear index (in lowermajor order) to a Coordinate.
 Return
 The Coordinate corresponding to index
 Parameters
index
: The linear index to be converted
Misc

std::string
toString
(bool humanReadable = true) const¶ Convert the Dimensions object to string representation.
In most cases, we want a humanreadable string, but for serialization we want only the actual dimension values
 Return
 The string representation of the Dimensions object
 Parameters
humanReadable
: The default istrue
, make the string humanreadable, set tofalse
for serialization

void
promote
(size_t newDimensionality)¶ Promote the Dimensions object to a new dimensionality.
 Note
 The sizes of all dimensions must be 1( i.e. isOnes() returns true), or an exception will be thrown.
 Parameters
newDimensionality
: The new dimensionality to promote to, it can be greater than, smaller than or equal to current dimensionality

bool
operator==
(const Dimensions &dims2) const¶ The equivalence operator.
Two Dimensions objects will be considered equivalent, if any of the following satisfies:
 They have the same number of dimensions and the same size for every dimension.
 Both of them have the size of 1 for everything dimensions, despite of how many dimensions they have, i.e. isOnes() returns
true
for both of them. Some linking scenarios require us to treat [1] equivalent to [1 1] etc.
 Return
 Whether this Dimensions object is equivalent to dims2.
 Parameters
dims2
: The Dimensions object being compared

bool
operator!=
(const Dimensions &dims2) const¶ The inequivalence operator, the opposite of operator==().
 Return
 Whether this Dimensions object is not equivalent to dims2.
 Parameters
dims2
: The Dimensions object being compared
