Class DenseBlock

java.lang.Object
org.apache.sysds.runtime.data.DenseBlock
All Implemented Interfaces:
Serializable, Block
Direct Known Subclasses:
DenseBlockDRB, DenseBlockLDRB

public abstract class DenseBlock extends Object implements Serializable, Block
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
    Modifier and Type
    Class
    Description
    static enum 
     
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract int
    Get the number of rows per block, except last one.
    abstract int
    blockSize(int bix)
    Get the number of rows of the given block.
    abstract long
    Get the total length of allocated blocks.
    boolean
    contains(double pattern)
     
    contains(double[] pattern, boolean earlyAbort)
     
    boolean
    contains(double pattern, int rl, int ru)
    Checks if the block contains at least one value of the given pattern.
    abstract long
    Compute the number of non-zero values, which potentially makes a full pass over the underlying blocks.
    abstract int
    Compute the number of non-zero values for the given row, which potentially makes a full pass over the underlying row.
    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.
    boolean
     
    boolean
    equals(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 double
    estimateMemory(long nrows, long ncols)
     
    void
    fill(double value)
     
    abstract void
    fillBlock(int bix, int fromIndex, int toIndex, double v)
    Fill a certain range of elements of a block.
    abstract void
    fillRow(int r, double v)
    Fill the DenseBlock row index with the value specified.
    abstract double
    get(int[] ix)
    Get the value of a given cell
    abstract double
    get(int r, int c)
    Get the value for a given row and column.
    final int
    getCumODims(int i)
    Get the ith cumulative dimensions size of the dense block, without row.
    final int
    getDim(int i)
    Get the ith dimensions size of the dense block.
    abstract long
    getLong(int[] ix)
    Get the value of a given cell as long
    void
    getNextIndexes(int[] ix)
    Calculates the next index array.
    abstract String
    getString(int[] ix)
    Get the value of a given cell as a String
    abstract void
    incr(int r, int c)
    Increments the given value for a given row and column.
    abstract void
    incr(int r, int c, double delta)
    Increments the given value for a given row and column by delta.
    abstract int
    index(int r)
    Get the block index for a given row.
    abstract boolean
    Indicates if the dense block has a single underlying block, i.e., if numBlocks==1.
    abstract boolean
    isContiguous(int rl, int ru)
    Indicates if the dense block has a single underlying block for the given row range.
    abstract boolean
    Indicates if the dense block is numeric.
    abstract boolean
    Indicates if the dense block is a specific numeric value type.
    abstract int
    Get the number of allocated blocks.
    final int
    Get the number of columns / first dimension
    final int
    Get the number of dimensions.
    final int
    Get the number of rows.
    abstract int
    pos(int r)
    Get the position for a given row within its associated block.
    abstract int
    pos(int[] ix)
    Get the position for a given cell within the associated block.
    abstract int
    pos(int r, int c)
    Get the position for a given row and column within the associated block.
    final void
    Resets the dense block by deleting non-zero values.
    final void
    reset(int[] dims)
    Resets the dense block by deleting non-zero values.
    final void
    reset(int[] dims, double v)
    Resets the dense block by deleting non-zeros.
    final void
    reset(int rlen, int clen)
    Resets the dense block by deleting non-zeros.
    final void
    reset(int rlen, int[] odims)
    Resets the dense block by deleting non-zeros.
    abstract void
    reset(int rlen, int[] odims, double v)
    Resets the dense block by setting the given value.
    final void
    reset(int rlen, int clen, double v)
    Resets the dense block by setting the given value.
    final void
    resetNoFill(int rlen, int clen)
     
    abstract void
    resetNoFill(int rlen, int[] odims)
     
    abstract DenseBlock
    set(double v)
    Set the given value for the entire dense block (fill).
    abstract DenseBlock
    set(int[] ix, double v)
    Set the specified cell to the given value.
    abstract DenseBlock
    set(int[] ix, long v)
    Set the specified cell to the given value.
    abstract DenseBlock
    set(int[] ix, String v)
    Set the specified cell to the given value.
    abstract DenseBlock
    set(int r, double[] v)
    Copy the given vector into the given row.
    abstract DenseBlock
    set(int r, int c, double v)
    Set the given value for a given row and column.
    abstract DenseBlock
    set(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 DenseBlock
    Copy the given dense block.
    Copy the given kahan object sum and correction.
    void
    setDims(int[] dims)
    Set the dimensions of the dense MatrixBlock.
    final long
    Get the length of the dense block as the product of all dimensions.
    abstract int
    size(int bix)
    Get the length of the given block.
     
    abstract double[]
    values(int r)
    Get the allocated block for the given row.
    abstract double[]
    valuesAt(int bix)
    Get an allocated block.

    Methods inherited from class java.lang.Object

    getClass, hashCode, notify, notifyAll, wait, wait, wait
  • 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 dimensions
      v - value
    • reset

      public final void reset(int rlen, int clen)
      Resets the dense block by deleting non-zeros.
      Parameters:
      rlen - number of rows
      clen - number of columns
    • reset

      public final void reset(int rlen, int[] odims)
      Resets the dense block by deleting non-zeros.
      Parameters:
      rlen - number of rows
      odims - 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 rows
      clen - number of columns
      v - 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 rows
      odims - other dimensions
      v - 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

      public abstract boolean isNumeric(Types.ValueType vt)
      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 index
      ru - 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 index
      ru - row upper index (exclusive)
      cl - column lower index
      cu - 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 index
      c - 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 index
      c - 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 index
      c - column index
      delta - 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 block
      fromIndex - starting index in block
      toIndex - 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 fill
      v - The value to fill it with.
    • set

      public abstract DenseBlock set(double v)
      Set the given value for the entire dense block (fill).
      Parameters:
      v - value
      Returns:
      self
    • set

      public DenseBlock set(String s)
      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

      public abstract DenseBlock set(int rl, int ru, int cl, int cu, double v)
      Set the given value for an entire index range of the dense block (fill).
      Parameters:
      rl - row lower index
      ru - row upper index (exclusive)
      cl - column lower index
      cu - column upper index (exclusive)
      v - value
      Returns:
      self
    • set

      public abstract DenseBlock set(int r, int c, double v)
      Set the given value for a given row and column.
      Parameters:
      r - row index
      c - column index
      v - value
      Returns:
      self
    • set

      public abstract DenseBlock set(int r, double[] v)
      Copy the given vector into the given row.
      Parameters:
      r - row index
      v - value vector
      Returns:
      self
    • set

      public abstract DenseBlock set(DenseBlock db)
      Copy the given dense block.
      Parameters:
      db - dense block
      Returns:
      self
    • set

      public DenseBlock set(int rl, int ru, int cl, int cu, DenseBlock db)
      Copy the given dense block into the specified index range.
      Parameters:
      rl - row lower index
      ru - row upper index (exclusive)
      cl - column lower index
      cu - 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

      public DenseBlock set(KahanObject kbuff)
      Copy the given kahan object sum and correction.
      Parameters:
      kbuff - kahan object
      Returns:
      self
    • set

      public abstract DenseBlock set(int[] ix, double v)
      Set the specified cell to the given value.
      Parameters:
      ix - cell indexes
      v - value
      Returns:
      self
    • set

      public abstract DenseBlock set(int[] ix, long v)
      Set the specified cell to the given value.
      Parameters:
      ix - cell indexes
      v - value
      Returns:
      self
    • set

      public abstract DenseBlock set(int[] ix, String v)
      Set the specified cell to the given value.
      Parameters:
      ix - cell indexes
      v - value as String
      Returns:
      self
    • set

      public DenseBlock set(int r, KahanObject kbuff)
      Copy the given kahan object sum and correction into the given row.
      Parameters:
      r - row index
      kbuff - kahan object
      Returns:
      self
    • get

      public abstract double get(int r, int c)
      Get the value for a given row and column.
      Specified by:
      get in interface Block
      Parameters:
      r - row index
      c - column index
      Returns:
      value
    • get

      public abstract double get(int[] ix)
      Get the value of a given cell
      Parameters:
      ix - cell indexes
      Returns:
      value
    • getString

      public abstract String getString(int[] ix)
      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 pattern
      rl - 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

      public List<Integer> contains(double[] pattern, boolean earlyAbort)
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • equals

      public boolean equals(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. 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 block
      eps - Epsilon allowed
      Returns:
      If the blocs are equivalent.
    • fill

      public void fill(double value)
    • toString

      public String toString()
      Overrides:
      toString in class Object