Class BlockDenseDoubleMatrix2D

All Implemented Interfaces:
Serializable, Cloneable, Comparable<Matrix>, HasMetaData, BaseMatrix, BooleanCalculations, CanPerformCalculations, DenseMatrix, DenseMatrix2D, DenseMatrixMultiD, BaseDoubleMatrix, BasicDoubleCalculations, DoubleCalculations, BasicEntrywiseDoubleCalculations, CreatorDoubleCalculations, EntrywiseDoubleCalculations, HyperbolicDoubleCalculations, MiscEntrywiseDoubleCalculations, RoundingDoubleCalculations, TrigonometricDoubleCalculations, DecompositionDoubleCalculations, DiscretizeCalculations, GeneralDoubleCalculations, MiscGeneralDoubleCalculations, MissingValueDoubleCalculations, StatisticalDoubleCalculations, DenseDoubleMatrix, DenseDoubleMatrix2D, DenseDoubleMatrixMultiD, DoubleMatrix, DoubleMatrix2D, DoubleMatrixMultiD, SparseDoubleMatrix, SparseDoubleMatrix2D, SparseDoubleMatrixMultiD, BaseGenericMatrix<Double>, DenseGenericMatrix<Double>, DenseGenericMatrix2D<Double>, DenseGenericMatrixMultiD<Double>, GenericMatrix<Double>, GenericMatrix2D<Double>, GenericMatrixMultiD<Double>, SparseGenericMatrix<Double>, SparseGenericMatrix2D<Double>, SparseGenericMatrixMultiD<Double>, BaseMatrixProperties, Clearable, Conversions, CoordinateFunctions, CoreObject, DistanceMeasures, ExtendedMatrixProperties, GettersAndSetters, HasBlockDoubleArray2D, HasDescription, HasGUIObject, HasId, HasLabel, IntCalculations, Matrix, Matrix2D, MatrixMultiD, BaseNumberMatrix<Double>, DenseNumberMatrix<Double>, DenseNumberMatrix2D<Double>, DenseNumberMatrixMultiD<Double>, NumberMatrix<Double>, NumberMatrix2D<Double>, NumberMatrixMultiD<Double>, SparseNumberMatrix<Double>, SparseNumberMatrix2D<Double>, SparseNumberMatrixMultiD<Double>, ObjectCalculations, SparseMatrix, SparseMatrix2D, SparseMatrixMultiD, StringCalculations

public class BlockDenseDoubleMatrix2D extends AbstractDenseDoubleMatrix2D implements HasBlockDoubleArray2D
A dense 2D matrix with square block layout. The data in the matrix is re-organised as a block, tiled layout, which on modern CPUs with multiple caches reduces the number of cache misses, by providing better cache locality and cache temporality.

Block Layout (example)

Example: a 4x4 matrix with block size 2x2 is internally re-organised into 4 separate blocks :

|(0,0) , (0, 1) | (0, 2) , (0, 3) |
|(1,0) , (1, 1) | (1, 2) , (1, 3) |
|----------------------------------
|(2,0) , (2, 1) | (2, 2) , (2, 3) |
|(3,0) , (3, 1) | (3, 2) , (3, 3) |

This can be described as a matrix of the following blocks:

| A | B |
| C | D |

Each block is mapped to a separate one-dimensional array. For example block A:

[ (0,0), (1,0), (0, 1), (1, 1)]

This layout is similar to what's described in [ref: II fig. 4b].

Choice of block size:

The blocks may be square and can be configured by the user at runtime. However, matrix multiplication performance will be sensitive to the choice of block size, depending on the amount of CPU cache available on the system.

See Also:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      See Also:
    • data

      private double[][] data
      Matrix data by block number.
    • layout

      protected BlockMatrixLayout layout
      Layout of matrix and blocks.
  • Constructor Details

    • BlockDenseDoubleMatrix2D

      public BlockDenseDoubleMatrix2D(double[][] values)
    • BlockDenseDoubleMatrix2D

      public BlockDenseDoubleMatrix2D(double[][] values, int blockStripeSize, BlockMatrixLayout.BlockOrder blockOrder)
      Create a block matrix from a jagged array.
      All rows of the values array must have the same length.
      Parameters:
      values - - the data to populate the matrix with.
      blockStripeSize - - length of one side of a block
      blockOrder - - see BlockMatrixLayout.BlockOrder.
      Throws:
      NullPointerException - if values is null, or values[0] is null.
      ArrayIndexOutOfBoundsException - if any row is shorter than the first row.
    • BlockDenseDoubleMatrix2D

      public BlockDenseDoubleMatrix2D(int rows, int cols, int blockStripeSize, BlockMatrixLayout.BlockOrder blockOrder)
      Create a new matrix with the specified size, and specified block stripe size.
      Parameters:
      rows - - number of rows of the matrix.
      cols - - number of columns of the matrix.
      blockStripeSize - - length of one side of a square block.
      Throws:
      IllegalArgumentException - if rows, cols or blockStripeSize are 0 or less, or blockOrder is null.
    • BlockDenseDoubleMatrix2D

      public BlockDenseDoubleMatrix2D(int rows, int cols, BlockMatrixLayout.BlockOrder blockOrder)
      Create a new matrix with the given size (rows, cols) and block layout.
      See Also:
      • #BlockMatrix(int, int)
    • BlockDenseDoubleMatrix2D

      public BlockDenseDoubleMatrix2D(int rows, int cols)
      Create a new matrix with the specified size, and specified block stripe size.
      Parameters:
      rows - - number of rows of the matrix.
      cols - - number of columns of the matrix.
      Throws:
      IllegalArgumentException - if rows, cols are 0 or less.
    • BlockDenseDoubleMatrix2D

      public BlockDenseDoubleMatrix2D(Matrix m)
      Constructor which takes an existing Matrix to copy data and structure from.
      Block stripe size will be defaulted internally.
      Parameters:
      m - - matrix to copy data from.
    • BlockDenseDoubleMatrix2D

      public BlockDenseDoubleMatrix2D(BlockDenseDoubleMatrix2D m)
      Constructor which takes an existing BlockMatrix to copy data and structure from.
    • BlockDenseDoubleMatrix2D

      public BlockDenseDoubleMatrix2D(Matrix m, int blockStripeSize)
      Constructor which takes a Matrix and a proposed default block stripe size.
      Parameters:
      m - - matrix containing existing values.
      blockStripeSize - - proposed default block size.
    • BlockDenseDoubleMatrix2D

      public BlockDenseDoubleMatrix2D(Matrix m, int blockStripeSize, BlockMatrixLayout.BlockOrder blockOrder)
      Constructor which takes a Matrix and a proposed default block stripe size.
      Parameters:
      m - - matrix containing existing values.
      blockStripeSize - - proposed default block size.
      blockOrder - row major or column major
  • Method Details