Package org.apache.sysds.runtime.data
Class DenseBlock
java.lang.Object
org.apache.sysds.runtime.data.DenseBlock
- All Implemented Interfaces:
Serializable,Block
- Direct Known Subclasses:
DenseBlockDRB,DenseBlockLDRB
This DenseBlock is an abstraction for different dense, row-major
matrix formats. For efficient dense operations, this API does not
expose a row but a row-block abstraction, where a block can contain
one or many contiguous rows.
- See Also:
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionabstract intGet the number of rows per block, except last one.abstract intblockSize(int bix) Get the number of rows of the given block.abstract longcapacity()Get the total length of allocated blocks.booleancontains(double pattern) contains(double[] pattern, boolean earlyAbort) booleancontains(double pattern, int rl, int ru) Checks if the block contains at least one value of the given pattern.abstract longCompute the number of non-zero values, which potentially makes a full pass over the underlying blocks.abstract intcountNonZeros(int r) Compute the number of non-zero values for the given row, which potentially makes a full pass over the underlying row.abstract longcountNonZeros(int rl, int ru, int cl, int cu) Compute the number of non-zero values, which potentially makes a full pass over the underlying blocks in the row range.booleanbooleanequals(DenseBlock o, double eps) Verify if the values in this dense block is equivalent to that dense block, not taking into account the dimensions of the contained values.static doubleestimateMemory(long nrows, long ncols) voidfill(double value) abstract voidfillBlock(int bix, int fromIndex, int toIndex, double v) Fill a certain range of elements of a block.abstract voidfillRow(int r, double v) Fill the DenseBlock row index with the value specified.abstract doubleget(int[] ix) Get the value of a given cellabstract doubleget(int r, int c) Get the value for a given row and column.final intgetCumODims(int i) Get the ith cumulative dimensions size of the dense block, without row.final intgetDim(int i) Get the ith dimensions size of the dense block.abstract longgetLong(int[] ix) Get the value of a given cell as longvoidgetNextIndexes(int[] ix) Calculates the next index array.abstract StringgetString(int[] ix) Get the value of a given cell as a Stringabstract voidincr(int r, int c) Increments the given value for a given row and column.abstract voidincr(int r, int c, double delta) Increments the given value for a given row and column by delta.abstract intindex(int r) Get the block index for a given row.abstract booleanIndicates if the dense block has a single underlying block, i.e., if numBlocks==1.abstract booleanisContiguous(int rl, int ru) Indicates if the dense block has a single underlying block for the given row range.abstract booleanIndicates if the dense block is numeric.abstract booleanIndicates if the dense block is a specific numeric value type.abstract intGet the number of allocated blocks.final intnumCols()Get the number of columns / first dimensionfinal intnumDims()Get the number of dimensions.final intnumRows()Get the number of rows.abstract intpos(int r) Get the position for a given row within its associated block.abstract intpos(int[] ix) Get the position for a given cell within the associated block.abstract intpos(int r, int c) Get the position for a given row and column within the associated block.final voidreset()Resets the dense block by deleting non-zero values.final voidreset(int[] dims) Resets the dense block by deleting non-zero values.final voidreset(int[] dims, double v) Resets the dense block by deleting non-zeros.final voidreset(int rlen, int clen) Resets the dense block by deleting non-zeros.final voidreset(int rlen, int[] odims) Resets the dense block by deleting non-zeros.abstract voidreset(int rlen, int[] odims, double v) Resets the dense block by setting the given value.final voidreset(int rlen, int clen, double v) Resets the dense block by setting the given value.final voidresetNoFill(int rlen, int clen) abstract voidresetNoFill(int rlen, int[] odims) abstract DenseBlockset(double v) Set the given value for the entire dense block (fill).abstract DenseBlockset(int[] ix, double v) Set the specified cell to the given value.abstract DenseBlockset(int[] ix, long v) Set the specified cell to the given value.abstract DenseBlockSet the specified cell to the given value.abstract DenseBlockset(int r, double[] v) Copy the given vector into the given row.abstract DenseBlockset(int r, int c, double v) Set the given value for a given row and column.abstract DenseBlockset(int rl, int ru, int cl, int cu, double v) Set the given value for an entire index range of the dense block (fill).set(int rl, int ru, int cl, int cu, DenseBlock db) Copy the given dense block into the specified index range.set(int r, KahanObject kbuff) Copy the given kahan object sum and correction into the given row.Set the given string for the entire dense block (fill).abstract DenseBlockset(DenseBlock db) Copy the given dense block.set(KahanObject kbuff) Copy the given kahan object sum and correction.voidsetDims(int[] dims) Set the dimensions of the dense MatrixBlock.final longsize()Get the length of the dense block as the product of all dimensions.abstract intsize(int bix) Get the length of the given block.toString()abstract double[]values(int r) Get the allocated block for the given row.abstract double[]valuesAt(int bix) Get an allocated block.
-
Method Details
-
getDim
public final int getDim(int i) Get the ith dimensions size of the dense block. 0 is rows , 1 is cols, etc.- Parameters:
i- the number of dimension to get- Returns:
- the size of the dimension
-
getCumODims
public final int getCumODims(int i) Get the ith cumulative dimensions size of the dense block, without row.- Parameters:
i- the number of the cumulative dimension to get (0 equals the second dimension!)- Returns:
- the size of the dimension cumulative with all following dimensions
-
reset
public final void reset()Resets the dense block by deleting non-zero values. After this call all countNonZeros() calls are guaranteed to return 0. -
reset
public final void reset(int[] dims) Resets the dense block by deleting non-zero values. After this call all countNonZeros() calls are guaranteed to return 0. If the new dimensions exceed the current capacity, the underlying storage is extended accordingly.- Parameters:
dims- length and size of dimensions.
-
reset
public final void reset(int[] dims, double v) Resets the dense block by deleting non-zeros.- Parameters:
dims- lenth and size of dimensionsv- value
-
reset
public final void reset(int rlen, int clen) Resets the dense block by deleting non-zeros.- Parameters:
rlen- number of rowsclen- number of columns
-
reset
public final void reset(int rlen, int[] odims) Resets the dense block by deleting non-zeros.- Parameters:
rlen- number of rowsodims- offsets of other dimensions
-
reset
public final void reset(int rlen, int clen, double v) Resets the dense block by setting the given value.- Parameters:
rlen- number of rowsclen- number of columnsv- value
-
reset
public abstract void reset(int rlen, int[] odims, double v) Resets the dense block by setting the given value.- Parameters:
rlen- number of rowsodims- other dimensionsv- value
-
resetNoFill
public final void resetNoFill(int rlen, int clen) -
resetNoFill
public abstract void resetNoFill(int rlen, int[] odims) -
estimateMemory
public static double estimateMemory(long nrows, long ncols) -
setDims
public void setDims(int[] dims) Set the dimensions of the dense MatrixBlock.- Parameters:
dims- The dimensions to set, first dimension is rows, second cols.
-
numRows
public final int numRows()Get the number of rows.- Returns:
- number of rows
-
numCols
public final int numCols()Get the number of columns / first dimension- Returns:
- number of columns
-
numDims
public final int numDims()Get the number of dimensions.- Returns:
- number of dimensions, min 2
-
numBlocks
public abstract int numBlocks()Get the number of allocated blocks.- Returns:
- number of blocks
-
blockSize
public abstract int blockSize()Get the number of rows per block, except last one.- Returns:
- number of rows in block
-
blockSize
public abstract int blockSize(int bix) Get the number of rows of the given block.- Parameters:
bix- block index- Returns:
- number of rows in block
-
isNumeric
public abstract boolean isNumeric()Indicates if the dense block is numeric.- Returns:
- true if numeric (FP, INT, BOOLEAN)
-
isNumeric
Indicates if the dense block is a specific numeric value type.- Parameters:
vt- value type to check- Returns:
- true if numeric and of value type vt
-
isContiguous
public abstract boolean isContiguous()Indicates if the dense block has a single underlying block, i.e., if numBlocks==1.- Returns:
- true if single block
-
isContiguous
public abstract boolean isContiguous(int rl, int ru) Indicates if the dense block has a single underlying block for the given row range.- Parameters:
rl- row lower indexru- row upper index (inclusive)- Returns:
- true if single block in row range
-
size
public final long size()Get the length of the dense block as the product of all dimensions.- Returns:
- length
-
size
public abstract int size(int bix) Get the length of the given block.- Parameters:
bix- block index- Returns:
- length
-
capacity
public abstract long capacity()Get the total length of allocated blocks.- Returns:
- capacity
-
countNonZeros
public abstract long countNonZeros()Compute the number of non-zero values, which potentially makes a full pass over the underlying blocks.- Returns:
- number of non-zeros
-
countNonZeros
public abstract int countNonZeros(int r) Compute the number of non-zero values for the given row, which potentially makes a full pass over the underlying row.- Parameters:
r- row index- Returns:
- number of non-zeros
-
countNonZeros
public abstract long countNonZeros(int rl, int ru, int cl, int cu) Compute the number of non-zero values, which potentially makes a full pass over the underlying blocks in the row range.- Parameters:
rl- row lower indexru- row upper index (exclusive)cl- column lower indexcu- column upper index (exclusive)- Returns:
- number of non-zeros
-
values
public abstract double[] values(int r) Get the allocated block for the given row. This call is equivalent to valuesAt(indexes(r)).- Parameters:
r- row index- Returns:
- block
-
valuesAt
public abstract double[] valuesAt(int bix) Get an allocated block.- Parameters:
bix- block index- Returns:
- block
-
index
public abstract int index(int r) Get the block index for a given row.- Parameters:
r- row index- Returns:
- block index
-
pos
public abstract int pos(int r) Get the position for a given row within its associated block.- Parameters:
r- row index- Returns:
- block position
-
pos
public abstract int pos(int r, int c) Get the position for a given row and column within the associated block.- Parameters:
r- row indexc- column index- Returns:
- block position
-
pos
public abstract int pos(int[] ix) Get the position for a given cell within the associated block.- Parameters:
ix- cell indexes- Returns:
- block position
-
incr
public abstract void incr(int r, int c) Increments the given value for a given row and column.- Parameters:
r- row indexc- column index
-
incr
public abstract void incr(int r, int c, double delta) Increments the given value for a given row and column by delta.- Parameters:
r- row indexc- column indexdelta- increment value
-
fillBlock
public abstract void fillBlock(int bix, int fromIndex, int toIndex, double v) Fill a certain range of elements of a block.- Parameters:
bix- index of blockfromIndex- starting index in blocktoIndex- ending index in block (exclusive)v- value
-
fillRow
public abstract void fillRow(int r, double v) Fill the DenseBlock row index with the value specified.- Parameters:
r- The row to fillv- The value to fill it with.
-
set
Set the given value for the entire dense block (fill).- Parameters:
v- value- Returns:
- self
-
set
Set the given string for the entire dense block (fill). Generally the string will be parsed, except for string DenseBlock.- Parameters:
s- string- Returns:
- self
-
set
Set the given value for an entire index range of the dense block (fill).- Parameters:
rl- row lower indexru- row upper index (exclusive)cl- column lower indexcu- column upper index (exclusive)v- value- Returns:
- self
-
set
Set the given value for a given row and column.- Parameters:
r- row indexc- column indexv- value- Returns:
- self
-
set
Copy the given vector into the given row.- Parameters:
r- row indexv- value vector- Returns:
- self
-
set
Copy the given dense block.- Parameters:
db- dense block- Returns:
- self
-
set
Copy the given dense block into the specified index range.- Parameters:
rl- row lower indexru- row upper index (exclusive)cl- column lower indexcu- column upper index (exclusive)db- dense block- Returns:
- self
-
getNextIndexes
public void getNextIndexes(int[] ix) Calculates the next index array. Note that if the given index array was the last element, the next index will be outside of range.- Parameters:
ix- the index array which will be incremented to the next index array
-
set
Copy the given kahan object sum and correction.- Parameters:
kbuff- kahan object- Returns:
- self
-
set
Set the specified cell to the given value.- Parameters:
ix- cell indexesv- value- Returns:
- self
-
set
Set the specified cell to the given value.- Parameters:
ix- cell indexesv- value- Returns:
- self
-
set
Set the specified cell to the given value.- Parameters:
ix- cell indexesv- value as String- Returns:
- self
-
set
Copy the given kahan object sum and correction into the given row.- Parameters:
r- row indexkbuff- kahan object- Returns:
- self
-
get
public abstract double get(int r, int c) Get the value for a given row and column. -
get
public abstract double get(int[] ix) Get the value of a given cell- Parameters:
ix- cell indexes- Returns:
- value
-
getString
Get the value of a given cell as a String- Parameters:
ix- cell indexes- Returns:
- value as String
-
getLong
public abstract long getLong(int[] ix) Get the value of a given cell as long- Parameters:
ix- cell indexes- Returns:
- value as long
-
contains
public boolean contains(double pattern, int rl, int ru) Checks if the block contains at least one value of the given pattern. Implementations need to handle NaN patterns as well (note that NaN==NaN yields false).- Parameters:
pattern- checked patternrl- row lower bound (inclusive)ru- row upper bound (exclusive)- Returns:
- true if pattern appears at least once, otherwise false
-
contains
public boolean contains(double pattern) -
contains
-
equals
-
equals
Verify if the values in this dense block is equivalent to that dense block, not taking into account the dimensions of the contained values. Note in some cases one or the other block is allocated bigger than the other, so the values compared is only the values of the smaller block.- Parameters:
o- Other blockeps- Epsilon allowed- Returns:
- If the blocs are equivalent.
-
fill
public void fill(double value) -
toString
-