Performance of multidimensional arrays is a big concern in Java. This is because multidimensional arrays are stored as arrays of arrays, spanning this concept to as many depths as necessary. In C++, a multidimensional array is stored internally as a unidimensional array where depths are stacked together one after another. A very simple calculation is needed in order to map multiple dimensional indexes to an unidimensional index.
This class provides a C/C++ like approach of internal unidimensional array backing a conceptual bidimensional matrix. This mapping is provided by method The mentioned access method is provided by a concrete implementation of {@link Address} which is passed to constructors.Doing so, it is possible to access the same underlying unidimensional data storage in various different ways, which allows us obtain another Matrix (see method {@link Matrix#range(int,int,int,int) and alike}) from an existing Matrix without any need of copying the underlying data. Certain operations benefit a lot from such approach, like {@link Matrix#transpose()} whichpresents constant execution time. The price we have to pay for such flexibility and benefits is that an access method is necessary, which means that a the bytecode may potentially need a dereference to a class which contain the concrete implementation of method Assignment operations Algebraic products Vectorial products Decompositions Element iterators Miscellaneous (1): clone()
@note This class is not thread-safe
@author Richard Gomes
op(int row, int col)
which is responsible for returning the physical address of the desired tuple op(int row, int col)
. In order to keep this cost at minimum, implementation of access method keep indexes at hand whenever possible, in order to being able to calculate the actual unidimensional index as fast as possible. This additional dereference impacts performance more or less in the same ways dereference impacts performance when a bidimensional array (double[][]
) is employed. Contrary to the bidimensional implementation, our implementation can potentially benefit from bytecode inlining, which means that calculation of the unidimensional index can be performed potentially faster than calculation of address location when a bidimensional array (double[][]
) is used as underlying storage. opr method this right result --- ---------- ------- -------- ------ = assign Matrix Matrix (1) += addAssign Matrix Matrix this -= subAssign Matrix Matrix this *= mulAssign Matrix scalar this /= divAssign Matrix scalar this
opr method this right result --- ---------- ------- -------- ------ + add Matrix Matrix Matrix - sub Matrix Matrix Matrix - negative Matrix this * mul Matrix scalar Matrix / div Matrix scalar Matrix
method this right result -------------- ------- -------- ------ mul Matrix Array Array mul Matrix Matrix Matrix
method this right result -------------- ------- -------- ------ lu Matrix LUDecomposition qr Matrix QRDecomposition cholensky Matrix CholeskyDecomposition svd Matrix SingularValueDecomposition eigenvalue Matrix EigenvalueDecomposition
method this right result ------------ ------- -------- ------ rowIterator Matrix RowIterator columnIterator Matrix ColumnIterator
method this right result -------------- ------- -------- ------ transpose Matrix Matrix diagonal Matrix Array determinant Matrix double inverse Matrix Matrix solve Matrix Matrix swap Matrix Matrix this range Matrix Matrix Matrix
(2): Unary + is equivalent to: array.clone()
(3): Unary ? is equivalent to: array.clone().mulAssign(-1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|