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:
- Joseph Ramsey
-
Constructor Summary
ConstructorsConstructorDescriptionMultiDimIntTable(int[] dims) Constructs a new multidimensional table of integer cells, with the given (fixed) dimensions. -
Method Summary
Modifier and TypeMethodDescriptionintgetCellIndex(int[] coords) int[]getCoordinates(int cellIndex) intgetDimension(int var) DescribegetDimensionmethod here.int[]intgetDims(int varIndex) intintlonggetValue(int[] coords) longincrement(int[] coords, int value) Increments the value at the given coordinates by the specified amount, returning the new value.final voidreset(int[] dims) Resets the table, allowing a different dimensionality.longsetValue(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- anintvalue- 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) DescribegetDimensionmethod here.- Parameters:
var- anintvalue- Returns:
- an
intvalue
-
getNumDimensions
public int getNumDimensions()- Returns:
- an
intvalue
-
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)
-