NuPIC Core
Core algorithms for NuPIC(the Numenta Platform for Intelligent Computing), implemented in C++
 All Classes Namespaces Files Functions Typedefs Enumerations Enumerator Friends Pages
List of all members
nupic::Dimensions Class Reference

Represents the dimensions of a Region. More...

#include <Dimensions.hpp>

Inheritance diagram for nupic::Dimensions:

Constructors

 Dimensions ()
 Create a new Dimensions object. More...
 
 Dimensions (std::vector< size_t > v)
 Create a new Dimensions object from a std::vector<size_t>. More...
 
 Dimensions (size_t x)
 Create a new 1-dimension Dimensions object. More...
 
 Dimensions (size_t x, size_t y)
 Create a new 2-dimension Dimensions. More...
 
 Dimensions (size_t x, size_t y, size_t z)
 Create a new 3-dimension Dimensions. More...
 

Properties

size_t getCount () const
 Get the count of cells in the grid, which is the product of the sizes of the dimensions. More...
 
size_t getDimensionCount () const
 Get the number of dimensions. More...
 
size_t getDimension (size_t index) const
 Get the size of a dimension. More...
 

Boolean properties

There are two "special" values for dimensions:

bool isUnspecified () const
 Tells whether the Dimensions object is "unspecified". More...
 
bool isDontcare () const
 Tells whether the Dimensions object is "don't care". More...
 
bool isSpecified () const
 Tells whether the Dimensions object is "specified". More...
 
bool isOnes () const
 Tells whether the sizes of all dimensions are 1. More...
 
bool isValid () const
 Tells whether Dimensions is "valid". More...
 

Coordinate<->index mapping

Coordinate<->index mapping is in lower-major 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 lower-major order). More...
 
Coordinate getCoordinate (const size_t index) const
 Convert a linear index (in lower-major order) to a Coordinate. More...
 

Misc

std::string toString (bool humanReadable=true) const
 Convert the Dimensions object to string representation. More...
 
void promote (size_t newDimensionality)
 Promote the Dimensions object to a new dimensionality. More...
 
bool operator== (const Dimensions &dims2) const
 The equivalence operator. More...
 
bool operator!= (const Dimensions &dims2) const
 The in-equivalence operator, the opposite of operator==(). More...
 

Additional Inherited Members

- Public Attributes inherited from std::vector< T >
elements
 STL member.
 

Detailed Description

Represents the dimensions of a Region.

A Dimensions object is an n-dimensional 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 n-dimensional grid, identified by a Coordinate.

It's implemented by a vector of size_t plus a few methods for convenience and for wrapping.

Definition at line 73 of file Dimensions.hpp.

Constructor & Destructor Documentation

nupic::Dimensions::Dimensions ( )

Create a new Dimensions object.

Note
Default dimensions are unspecified, see isUnspecified()
nupic::Dimensions::Dimensions ( std::vector< size_t >  v)

Create a new Dimensions object from a std::vector<size_t>.

Parameters
vA std::vector of size_t, the value with the index of n is the size of the n th dimension
nupic::Dimensions::Dimensions ( size_t  x)

Create a new 1-dimension Dimensions object.

Parameters
xThe size of the 1st dimension
nupic::Dimensions::Dimensions ( size_t  x,
size_t  y 
)

Create a new 2-dimension Dimensions.

Parameters
xThe size of the 1st dimension
yThe size of the 2nd dimension
nupic::Dimensions::Dimensions ( size_t  x,
size_t  y,
size_t  z 
)

Create a new 3-dimension Dimensions.

Parameters
xThe size of the 1st dimension
yThe size of the 2nd dimension
zThe size of the 3rd dimension

Member Function Documentation

Coordinate nupic::Dimensions::getCoordinate ( const size_t  index) const

Convert a linear index (in lower-major order) to a Coordinate.

Parameters
indexThe linear index to be converted
Returns
The Coordinate corresponding to index
size_t nupic::Dimensions::getCount ( ) const

Get the count of cells in the grid, which is the product of the sizes of the dimensions.

Returns
The count of cells in the grid.
size_t nupic::Dimensions::getDimension ( size_t  index) const

Get the size of a dimension.

Parameters
indexThe index of the dimension
Returns
The size of the dimension with the index of index
Note
Do not confuse index with "linear index" as in getIndex()
size_t nupic::Dimensions::getDimensionCount ( ) const

Get the number of dimensions.

Returns
number of dimensions
size_t nupic::Dimensions::getIndex ( const Coordinate coordinate) const

Convert a Coordinate to a linear index (in lower-major order).

Parameters
coordinateThe coordinate to be converted
Returns
The linear index corresponding to coordinate
bool nupic::Dimensions::isDontcare ( ) const

Tells whether the Dimensions object is "don't care".

Returns
Whether the Dimensions object is "don't care"
bool nupic::Dimensions::isOnes ( ) const

Tells whether the sizes of all dimensions are 1.

Returns
Whether the sizes of all dimensions are 1, e.g. [1], [1 1], [1 1 1], etc.
bool nupic::Dimensions::isSpecified ( ) const

Tells whether the Dimensions object is "specified".

A "specified" Dimensions object satisfies all following conditions:

  • "valid"
  • NOT "unspecified"
  • NOT "don't care"
Returns
Whether the Dimensions object is "specified"
Note
It's not the opposite of isUnspecified()!
bool nupic::Dimensions::isUnspecified ( ) const

Tells whether the Dimensions object is "unspecified".

Returns
Whether the Dimensions object is "unspecified"
See Also
isSpecified()
bool nupic::Dimensions::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")

Returns
Whether Dimensions is "valid"
bool nupic::Dimensions::operator!= ( const Dimensions dims2) const

The in-equivalence operator, the opposite of operator==().

Parameters
dims2The Dimensions object being compared
Returns
Whether this Dimensions object is not equivalent to dims2.
bool nupic::Dimensions::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.
Parameters
dims2The Dimensions object being compared
Returns
Whether this Dimensions object is equivalent to dims2.
void nupic::Dimensions::promote ( size_t  newDimensionality)

Promote the Dimensions object to a new dimensionality.

Parameters
newDimensionalityThe new dimensionality to promote to, it can be greater than, smaller than or equal to current dimensionality
Note
The sizes of all dimensions must be 1( i.e. isOnes() returns true), or an exception will be thrown.
std::string nupic::Dimensions::toString ( bool  humanReadable = true) const

Convert the Dimensions object to string representation.

In most cases, we want a human-readable string, but for serialization we want only the actual dimension values

Parameters
humanReadableThe default is true, make the string human-readable, set to false for serialization
Returns
The string representation of the Dimensions object

The documentation for this class was generated from the following file: