Package edu.cmu.tetrad.util
Class MultiDimIntTable
java.lang.Object
edu.cmu.tetrad.util.MultiDimIntTable
Stores a table of cells with int values of arbitrary dimension. The dimensionality of the table is set in the reset() method; if a dimensionality is set in the constructor, it will be passed to the reset() method. Every time the dimensionality is changed, the table is reset to zero throughout. If the dimensionality is set to null, the table cannot be used until a non-null dimensionality is set.> 0
- Author:
- josephramsey
-
Constructor Summary
ConstructorsConstructorDescriptionMultiDimIntTable
(int[] dims) Constructs a new multidimensional table of integer cells, with the given (fixed) dimensions. -
Method Summary
Modifier and TypeMethodDescriptionint
getCellIndex
(int[] coords) int[]
getCoordinates
(int cellIndex) int
getDimension
(int var) DescribegetDimension
method here.int[]
int
getDims
(int varIndex) int
int
long
getValue
(int[] coords) long
increment
(int[] coords, int value) Increments the value at the given coordinates by the specified amount, returning the new value.final void
reset
(int[] dims) Resets the table, allowing a different dimensionality.long
setValue
(int[] coords, int value) Sets the value at the given coordinates to the given value, returning the new value.
-
Constructor Details
-
MultiDimIntTable
public MultiDimIntTable(int[] dims) Constructs a new multidimensional table of integer cells, with the given (fixed) dimensions. Each dimension must be an integer greater than zero.- Parameters:
dims
- An int[] array of length > 0, each element of which specifies the number of values of that dimension (> 0).
-
-
Method Details
-
getCellIndex
public int getCellIndex(int[] coords) - Parameters:
coords
- The coordinates of the cell. Each value must be less than the number of possible value for the corresponding dimension in the table. (Enforced.)- Returns:
- the row in the table for the given node and combination of parent values.
-
getCoordinates
public int[] getCoordinates(int cellIndex) - Parameters:
cellIndex
- anint
value- Returns:
- the array representing the combination of parent values for this row.
-
increment
public long increment(int[] coords, int value) Increments the value at the given coordinates by the specified amount, returning the new value.- Parameters:
coords
- The coordinates of the table cell to update.value
- The amount by which the table cell at these coordinates should be incremented (an integer).- Returns:
- the new value at that table cell.
-
setValue
public long setValue(int[] coords, int value) Sets the value at the given coordinates to the given value, returning the new value.- Parameters:
coords
- The coordinates of the table cell to update.value
- The amount by which the table cell at these coordinates should be incremented (an integer).- Returns:
- the new value at that table cell.
-
getValue
public long getValue(int[] coords) - Parameters:
coords
- The coordinates of the table cell to update.- Returns:
- the new value at that table cell.
-
getNumCells
public int getNumCells()- Returns:
- this number.
-
getDimensions
public int[] getDimensions()- Returns:
- this number.
-
getDimension
public int getDimension(int var) DescribegetDimension
method here.- Parameters:
var
- anint
value- Returns:
- an
int
value
-
getNumDimensions
public int getNumDimensions()- Returns:
- an
int
value
-
reset
public final void reset(int[] dims) Resets the table, allowing a different dimensionality. All cells are reset to zero. The underlying data array is reused if possible.- Parameters:
dims
- anint[]
value
-
getDims
public int getDims(int varIndex)
-