mikera.matrixx
Class AMatrix
- java.lang.Object
-
- mikera.arrayz.impl.AbstractArray<AVector>
-
- mikera.matrixx.AMatrix
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<INDArray>, java.lang.Iterable<AVector>, INDArray, IMatrix
- Direct Known Subclasses:
- ABandedMatrix, APrimitiveMatrix, ARectangularMatrix, MatrixBuilder
public abstract class AMatrix extends AbstractArray<AVector> implements IMatrix
Abstract 2D matrix class. All Vectorz 2D matrices inherit from this class. Implements generic version of most key matrix operations.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description AMatrix()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method and Description voidabs()Replaces all elements of this array with their absolute values, according to Math.abs(double)voidadd(AMatrix m)Adds another matrix to this matrix.voidadd(AVector v)Adds a vector to every row of this matrix.voidadd(double d)Adds a double value to all elements in this array.voidadd(INDArray a)Adds all the elements of another array to this array, in an elementwise order.voidadd2(AMatrix a, AMatrix b)Adds two matrices to this matrix.voidaddAt(int i, int j, double d)Adds a value at a specific position in the matrix, mutating the matrix Does not perform bounds checking - this in an unsafe operationAMatrixaddCopy(AMatrix a)Adds another matrix to this matrix, returning a new matrixMatrixaddCopy(AStridedMatrix a)Adds a dense matrix to this matrix, returning a new dense MatrixAMatrixaddCopy(AVector v)Adds a vector to every row of this matrix, returning a new matrixAMatrixaddCopy(double d)Creates a new array equal to this array with a constant value added to every elementINDArrayaddCopy(INDArray a)Creates a new array equal to the sum of this array with another array.voidaddInnerProduct(AMatrix a, AMatrix b)Adds the inner product (matrix multiply) of two matrices to this matrixvoidaddInnerProduct(AMatrix a, INDArray b)Adds the inner product of a matrix and an array to this arrayvoidaddInnerProduct(INDArray a, INDArray b)Adds the inner product of two arrays to this array.voidaddMultiple(AMatrix m, double factor)Adds a scalar multiple of another matrix to this matrixvoidaddMultiple(AVector v, double factor)Adds a scalar multiple of a vector to every row of this matrixvoidaddMultiple(INDArray src, double factor)Adds a scaled multiple of another array to this arrayvoidaddOuterProduct(AVector a, AVector b)Adds the outer product of two vectors to this matrixvoidaddOuterProduct(INDArray a, INDArray b)Adds the outer product of two arrays to this array.voidaddOuterProductSparse(AVector a, AVector b)Adds the outer product of two vectors to this matrix.voidaddOuterProductSparse(INDArray a, INDArray b)Adds the outer product of two arrays to this array.voidaddRowMultiple(int src, int dst, double factor)Adds a multiple of a source row to a destination row This is an elementary row operationvoidaddSparse(AVector a)Adds the corresponding elements of the source vector to the non-sparse elements in rows of this matrixvoidaddSparse(INDArray a)Adds the corresponding elements of the source array the non-sparse elements of this arrayvoidaddToArray(double[] data, int offset)Adds all the elements of this array to a double array at the specified offset, in row-major ordervoidapplyOp(IOperator op)Applies a unary operator to all elements of the array (in-place)voidapplyOp(Op op)Applies a unary operator to all elements of the array (in-place)voidapplyOp(Op2 op, AMatrix b)voidapplyOp(Op2 op, AVector b)voidapplyOp(Op2 op, double b)Applies a binary operator to this array and a double value.voidapplyOp(Op2 op, INDArray b)Applies a binary operator to this array and a second array.AMatrixapplyOpCopy(Op op)Applies a unary operator to all elements of the array (creating a new array)double[]asDoubleArray()Returns the underlying double array representing the densely packed elements of this array.java.util.List<java.lang.Double>asElementList()Returns a Listcontaining all elements of this array AVectorasVector()Returns the matrix values as a single reference Vector in the form [row0 row1 row2....]intbandIndex(int i, int j)Returns the band index number for a specified position in the matrix.intbandLength(int band)Returns the length of a band of the matrix.intbandPosition(int i, int j)Returns the band position for a specified (i,j) index in the matrix.intbandStartColumn(int band)Returns the start column of a given band.intbandStartRow(int band)Returns the start row of a given band.INDArraybroadcast(int... targetShape)Returns a view of this array broadcasted up to a larger shapeINDArraybroadcastCloneLike(INDArray target)Creates a mutable clone of the array, broadcasted upwards if necessary to match the shape of the target.INDArraybroadcastCopyLike(INDArray target)Creates a copy of the array, broadcasted upwards if necessary to match the shape of the target Like broadCastCloneLike, but does not guarantee a fully mutable clone - hence may be faster when used with immutable or specialized arraysAMatrixbroadcastLike(AMatrix target)Broadcasts an array to match the shape of the target matrixINDArraybroadcastLike(INDArray target)Broadcasts an array to match the shape of the targetintcheckColumn(int column)Checks if the given column index is valid for this matrix.intcheckRow(int row)Checks if the given rows index is valid for this matrix.intcheckSquare()Checks if a matrix is square.voidclamp(double min, double max)Clamps all the elements of this array within the specified [min,max] rangeAMatrixclone()Returns a clone of the array data, as a new array which will be fully mutable and may be of a different class to the original.voidcomposeWith(AMatrix a)AMatrixcopy()Returns a defensive copy of the array data.voidcopyColumnTo(int j, double[] dest, int destOffset)Copies the elements in a selected row of this matrix to a double arrayvoidcopyRowTo(int i, double[] dest, int destOffset)Copies the elements in a selected row of this matrix to a double arrayAMatrixdense()Coerces this INDArray to a dense format, without changing its element values.MatrixdenseClone()Creates a fully mutable dense clone of this array.doubledeterminant()Calculates the determinant of the matrix.doublediagonalProduct()Computes the product of entries on the main diagonal of a matrixintdimensionality()Returns the dimensionality of the array (i.e.voiddivide(AMatrix m)Divides this matrix in-place by another in an entrywise manner.voiddivide(AVector v)Divides every row of this matrix by the given vectorvoiddivide(double factor)Divides all elements by a given factorvoiddivide(INDArray a)Divides all elements in place by the equivalent elements in a second arrayAMatrixdivideCopy(double d)Returns a copy of the array with all elements divided by a single constant valuelongelementCount()Returns the total number of elements in this array.java.util.Iterator<java.lang.Double>elementIterator()Returns an iterator over all elements in this array, in row-major orderbooleanelementsEqual(double value)Returns true if all elements are equal to a specific valuedoubleelementSquaredSum()Returns the squared sum of all elements in this matrixdoubleelementSum()Returns the sum of all elements in this matrixAMatrixensureMutable()Ensures the array is a fully mutable representation.booleanepsilonEquals(AMatrix a)Returns true if this matrix is approximately equal to a second matrix, up to a default tolerance levelbooleanepsilonEquals(AMatrix a, double epsilon)booleanepsilonEquals(INDArray a, double epsilon)Tests is this array is approximately equal to another array, up to a given tolerance (epsilon) The arrays must have the same shapebooleanequals(AMatrix a)Returns true if this matrix is exactly equal to another matrixbooleanequals(INDArray v)Checks if two arrays are equal exactly in terms of both value and shape Element equality checks are consistent with compareTobooleanequals(java.lang.Object o)booleanequalsArray(double[] data, int offset)Returns true if the elements in this array exactly match the elements in the given array, in row-major orderbooleanequalsTranspose(AMatrix a)Tests if this matrix is exactly equal to the transpose of another matrixabstract AMatrixexactClone()Creates a deep clone of an array, using the same class implementation as the original arrayvoidexp()Computes the function e^x (in-place) for all array elementsvoidfill(double value)Fills this array with a single double value.doubleget()Returns the double value of a scalar arraydoubleget(AIndex ix)Returns the double value at the specified position in the arraydoubleget(int... indexes)Returns the double value at the specified index position in an arraydoubleget(int row)Returns the double value at the specified position in a 1D vectorabstract doubleget(int i, int j)Returns the double value at the specified position in a 2D matrixAVectorgetBand(int band)Gets a specific band of the matrix, as a view vector.AVectorgetBandWrapped(int band)AVectorgetColumn(int column)Returns a column of the matrix.AVectorgetColumnClone(int column)Returns a column of the matrix as a new cloned, mutable vector The cloned column may be modified without affecting the original matrix.java.util.List<AVector>getColumns()Gets a List of columns of a matrix.AVectorgetColumnView(int column)Returns a column of the matrix as a vector view.doublegetElement(long i)Gets a specific element of this array, indexed in row-major ordervoidgetElements(double[] dest, int offset)Copies all elements of this array a double array at the specified offsetAVectorgetLeadingDiagonal()Returns a vector view of the leading diagonal values of the matrixlong[]getLongShape()Returns the shape of the array as an array of longs.AVectorgetRow(int row)Returns a row of the matrix.AVectorgetRowClone(int row)Returns a row of the matrix as a new cloned, mutable vector.java.util.List<AVector>getRows()Gets a List of rows of a matrix.AVectorgetRowView(int row)Returns a row of the matrix as a vector view.int[]getShape()Returns the shape of the array as an array of ints.intgetShape(int dim)Returns the dimension size for a specific dimension in the array's shapeint[]getShapeClone()Returns the shape of the array as an array of ints, guaranteed to be a new array i.e.java.util.List<AVector>getSlices()Returns a list of all major slices of this array.java.util.List<AVector>getSlices(int dimension)Returns a list of all slices of this array along a given dimension.java.util.List<INDArray>getSliceViews()Returns a list of slices as mutable INDArray views.AMatrixgetTranspose()Returns the transpose of this array.AMatrixgetTransposeCopy()Gets a mutable transposed clone of the matrixAMatrixgetTransposeView()Returns a transposed view of the array.inthashCode()booleanhasOrthonormalColumns()Tests whether all columns in the matrix are orthonormal vectorsbooleanhasOrthonormalRows()Tests whether all rows in the matrix are orthonormal vectorsbooleanhasUncountable()Checks to see if any element in the matrix is NaN of Infinite.INDArrayimmutable()Returns an immutable version of this array.AMatrixinnerProduct(AMatrix a)Computes the inner product of this matrix with another.AMatrixinnerProduct(AScalar s)Calculates the inner product of this array with a scalarAVectorinnerProduct(AVector v)Computes the inner product of this array with a vectorAMatrixinnerProduct(double d)Calculates the inner product of this array with a double valueINDArrayinnerProduct(INDArray a)Calculates the inner product of this array with another array.VectorinnerProduct(Vector v)Transforms a dense source Vector using matrix multiplication (inner product).intinputDimensions()Returns the number of dimensions required for input vectorsAMatrixinverse()Computes the inverse of a matrix.booleanisBoolean()Returns true if the array is boolean (contains only 0.0 or 1.0 values)booleanisDiagonal()Returns true iff this matrix is a square diagonal matrixbooleanisElementConstrained()Returns true if this array has some constraints on element valuesabstract booleanisFullyMutable()If this method returns true, the INDArray is guaranteed to be fully mutable in all positions i.e.booleanisHermitian()Returns true if a matrix is Hermitian This is equivalent to isSymmetric(), since all Vectorz matrices have real values.booleanisIdentity()Checks if this is an identity matrix (i.e.booleanisInvertible()Checks if this is an invertible matrix (i.e.booleanisLowerTriangular()Returns true if a matrix is lower triangular.booleanisMutable()Returns true if the INDArray is mutable (at least partially)booleanisOrthogonal()Check to see if the matrix is orthogonal (default tolerance: 1e-8)booleanisOrthogonal(double tolerance)Check to see if the matrix is orthogonalbooleanisPositiveDefinite()Returns true if a matrix is positive definitebooleanisRectangularDiagonal()Returns true iff this matrix is a diagonal matrix (might not be square)booleanisSameShape(AMatrix a)Returns true iff this matrix is exactly the same shape as another matrixbooleanisSameShape(INDArray a)Returns true if this array is the same shape as another arraybooleanisSquare()Checks if this is a square matrixbooleanisSymmetric()Returns true if a matrix is symmetricbooleanisUpperTriangular()Returns true if a matrix is upper triangular An upper triangular matrix is defined as having all elements equal to 0.0 where i > jbooleanisView()Return true if this array is considered as a view type.booleanisZero()Returns true if the matrix is the zero matrix (all components zero)java.util.Iterator<AVector>iterator()Returns an iterator over rows in this MatrixINDArrayjoin(INDArray a, int dimension)Joins an array with another array along a specified dimension.voidlog()Computes the natural logarithm (in-place) for all array elementsintlowerBandwidth()Computes the lower bandwidth of a matrix, i.e.intlowerBandwidthLimit()A limit on the lower bandwidth of the banded matrix.voidmul(AMatrix a)"Multiplies" this matrix by another, composing the transformationvoidmultiply(AMatrix m)Multiplies this matrix in-place by another in an entrywise manner (Hadamard product).voidmultiply(AVector v)Multiply each row in this matrix by a vector.voidmultiply(double factor)Multiplies all elements of the array in place by a given double valuevoidmultiply(INDArray a)Multiplies all elements by the equivalent elements in a second array, i.e.AMatrixmultiplyCopy(double factor)Returns a copy of the array with all elements multiplied by a single constant valuevoidmultiplyRow(int i, double factor)Multiplies a row by a constant factor This is an elementary row operationAMatrixmutable()Coerces this INDArray to a fully mutable format.voidnegate()Negates all elements in the array in placelongnonZeroCount()Returns the number of non-zero elements in the array.INDArrayouterProduct(INDArray a)Calculates the outer product of this array with another array.intoutputDimensions()Returns the number of dimensions required for output vectorsvoidpow(double exponent)Raises all elements of the array to a specified power in placeintrank()Calculate the rank of a matrix.voidreciprocal()Replaces all elements in the array with their reciprocaldoublereduce(Op2 op)Reduces over all elements of the array in row-major order.doublereduce(Op2 op, double init)Reduces over all elements of the array in row-major order.AVectorreduceSlices(Op2 op)Reduces each vector slice of the array by the given binary operator Reduces down to a single vectorAVectorreduceSlices(Op2 op, double init)Reduces each slice of the array by the given binary operator.AMatrixreorder(int[] order)Returns a re-ordered array by taking the specified order of slices along dimension 0AMatrixreorder(int dim, int[] order)Returns a re-ordered array by taking the specified order of slices along a given dimension May or may not use views of underlying slices (i.e.voidreplaceColumn(int i, AVector row)Replaces a column in a matrix, adding the column to the internal structure of the matrix.voidreplaceRow(int i, AVector row)Replaces a row in a matrix, adding the row to the internal structure of the matrix.INDArrayreshape(int... dimensions)Returns a new array by rearranging the elements of this array into the desired shape Truncates or zero-pads the elements as required to fill the new shapeMatrixreshape(int rows, int cols)INDArrayrotateView(int dimension, int shift)Returns rotated view of this arraydoublerowDotProduct(int i, AVector a)Returns the dot product of a specific row with a vector.voidscaleAdd(double factor, double constant)Scales all elements of the array by a given double value and adds a constant valuevoidscaleAdd(double factor, INDArray b, double bfactor, double constant)Scales all elements of the array by a given double value, adds a scaled second array and adds a constant valuevoidset(AMatrix a)Sets this matrix with the element values from another matrix.voidset(AVector v)Sets every row of this matrix with the element values from a vector.voidset(double value)Sets all elements of an array to a specific double valuevoidset(INDArray a)Sets this array to the element values contained in another array.voidset(int[] indexes, double value)Sets the element at the given indexed position in a mutable arrayvoidset(int row, double value)Sets a value at a given position in a mutable 1D arrayabstract voidset(int i, int j, double value)Sets a value at a given position in a mutable 2D arrayvoidset(long[] indexes, double value)Sets the element at the given indexed position in a mutable arrayvoidset(java.lang.Object o)Sets this array to the element values contained in the given object.voidsetApplyOp(Op op, AMatrix a)Sets this matrix to the result of applying an operator to another matrixvoidsetApplyOp(Op op, INDArray a)Sets this array to the result of applying an operation to a source arrayvoidsetColumn(int i, AVector col)Sets a column in a matrix.voidsetElements(double... values)Sets all elements in an array using the given double valuesvoidsetElements(double[] values, int offset)Sets all elements in an array using the given double valuesvoidsetMultiple(AMatrix a, AMatrix b)Sets this matrix to the elementwise product of two other matricesvoidsetMultiple(AMatrix a, double b)Sets this matrix to a multiple of another matrixvoidsetMultiple(AVector a, double b)Sets every row of this matrix to a multiple of a vectorvoidsetMultiple(INDArray a, double b)Sets this array to be the multiple of another array.voidsetMultiple(INDArray a, INDArray b)Sets this array to the element-wise multiple of two arrays.voidsetRow(int i, AVector row)Sets a row in a matrix to the value specified by the given vectorvoidsetSparse(AMatrix a)Sets the non-sparse elements in this matrix to the corresponding values in the source matrixvoidsetSparse(INDArray a)Sets the non-sparse elements of this array to the corresponding elements of the source arrayvoidsignum()Calculates the signum of all elements of this mutable array Sets each component of the array to its sign value (-1, 0 or 1)AVectorslice(int row)Returns the specified major slice of this array as a view (slice along dimension 0) 0 dimensional slice results are permitted, but attempting to slice a 0 dimensional array will result in an error.AVectorslice(int dimension, int index)Returns a slice view of this array along the specified dimensionintsliceCount()Returns the number of major slices in this array (i.e.AMatrixsparse()Coerces this INDArray to a sparse format, without changing its element values.AMatrixsparseClone()Creates a fully mutable clone of this array.voidsqrt()Computes the square root of all elements in the arrayvoidsquare()Squares all elements of the array in placevoidsub(AMatrix m)Subtracts another matrix from this onevoidsub(AVector v)Subtracts a vector from every row of this matrix.voidsub(INDArray a)Subtracts all the elements of another array from this array, in an elementwise order.AMatrixsubArray(int[] offsets, int[] shape)Returns a subarray view of a larger arrayAMatrixsubCopy(AMatrix m)Subtracts another matrix from this one, returning a new matrixAMatrixsubMatrix(int rowStart, int rows, int colStart, int cols)Gets a rectangular submatrix view of part of a matrixvoidswapColumns(int i, int j)Swaps two columns of the matrix in placevoidswapRows(int i, int j)Swaps two rows of the matrix in place This is an elementary row operationAAffineTransformtoAffineTransform()double[]toDoubleArray()Copies the elements of this array to a new double[] array.voidtoDoubleBuffer(java.nio.DoubleBuffer dest)Copies the elements of this INDArray to the specified double buffer.MatrixtoMatrix()Coerces the matrix to the standard mutable Matrix type in row major order.MatrixtoMatrixTranspose()Coerces the transpose of a matrix to the standard mutable Matrix type in row major order.AMatrixtoMutableMatrix()Creates a fully mutable deep copy of this matrixdouble[][]toNestedDoubleArrays()Converts this matrix to nested double[][] arrayAVector[]toSliceArray()Copies the slices of this array to a new INDArray[] Throws an error if the array has no slices (i.e.java.lang.StringtoString()java.lang.StringtoStringFull()VectortoVector()Coerces the array into a flattened dense Vector, in row-major order.doubletrace()Computes the trace of a matrix, i.e.voidtransform(AVector source, AVector dest)Transforms a source vector into a destination vector, using matrix multiplication (inner product).voidtransform(Vector source, Vector dest)voidtransformInPlace(ADenseArrayVector v)voidtransformInPlace(AVector v)AMatrixtransposeInnerProduct(AMatrix s)AMatrixtransposeInnerProduct(Matrix s)voidtransposeInPlace()Transposes a matrix in place, if possible.doubleunsafeGet(int i, int j)Gets an element in the matrix in an unsafe fashion, without performing bound checks The result is undefined if the row and column are out of bounds.voidunsafeSet(int i, int j, double value)Sets an element value in the matrix in an unsafe fashion, without performing bound checks The result is undefined if the row and column are out of bounds.intupperBandwidth()Computes the upper bandwidth of a matrix, i.e.intupperBandwidthLimit()A limit on the upper bandwidth of the banded matrix.voidvalidate()Validates the internal data structure of the INDArray.-
Methods inherited from class mikera.arrayz.impl.AbstractArray
absCopy, absDiff, absDiffCopy, add, addApplyOp, addAt, addCopy, addInnerProduct, addInnerProduct, addMultipleSparse, addPower, addPower, addSparse, broadcastLike, compareTo, componentCount, density, divideCopy, elementAbsPowSum, elementMax, elementMaxAbs, elementMin, elementPowSum, elementProduct, epsilonEquals, equals, equalsArray, get, get, get, get, getComponent, getComponents, getElements, getElements, getElements, isDense, isSparse, join, multiplyCopy, negateCopy, reciprocalCopy, scale, scaleCopy, setElements, setInnerProduct, setSparse, signumCopy, sliceValue, squareCopy, sub, sub, subCopy, withComponents
-
Methods inherited from interface mikera.matrixx.IMatrix
columnCount, rowCount
-
Methods inherited from interface mikera.arrayz.INDArray
absCopy, absDiff, absDiffCopy, addApplyOp, addAt, addInnerProduct, addMultipleSparse, addPower, addPower, addSparse, broadcastLike, componentCount, divideCopy, elementAbsPowSum, elementMax, elementMaxAbs, elementMin, elementPowSum, elementProduct, epsilonEquals, equalsArray, get, get, get, get, getComponent, getComponents, getElements, getElements, getElements, isDense, isSparse, join, multiplyCopy, negateCopy, reciprocalCopy, scale, scaleCopy, setElements, setInnerProduct, setSparse, signumCopy, sliceValue, squareCopy, sub, subCopy, withComponents
-
-
-
-
Method Detail
-
get
public abstract double get(int i, int j)Description copied from interface:INDArrayReturns the double value at the specified position in a 2D matrix
-
set
public abstract void set(int i, int j, double value)Description copied from interface:INDArraySets a value at a given position in a mutable 2D array
-
get
public final double get(int row)
Description copied from interface:INDArrayReturns the double value at the specified position in a 1D vector- Specified by:
getin interfaceINDArray- Specified by:
getin classAbstractArray<AVector>
-
get
public final double get()
Description copied from interface:INDArrayReturns the double value of a scalar array- Specified by:
getin interfaceINDArray- Specified by:
getin classAbstractArray<AVector>
-
set
public void set(int row, double value)Description copied from interface:INDArraySets a value at a given position in a mutable 1D array- Specified by:
setin interfaceINDArray- Overrides:
setin classAbstractArray<AVector>
-
set
public final void set(double value)
Description copied from interface:INDArraySets all elements of an array to a specific double value- Specified by:
setin interfaceINDArray- Overrides:
setin classAbstractArray<AVector>
-
fill
public void fill(double value)
Description copied from interface:INDArrayFills this array with a single double value. Requires the array to be mutable.- Specified by:
fillin interfaceINDArray- Overrides:
fillin classAbstractArray<AVector>
-
unsafeSet
public void unsafeSet(int i, int j, double value)Sets an element value in the matrix in an unsafe fashion, without performing bound checks The result is undefined if the row and column are out of bounds.- Parameters:
i-j-
-
unsafeGet
public double unsafeGet(int i, int j)Gets an element in the matrix in an unsafe fashion, without performing bound checks The result is undefined if the row and column are out of bounds.- Parameters:
i-j-- Returns:
-
clamp
public void clamp(double min, double max)Description copied from interface:INDArrayClamps all the elements of this array within the specified [min,max] range- Specified by:
clampin interfaceINDArray- Overrides:
clampin classAbstractArray<AVector>
-
pow
public void pow(double exponent)
Description copied from interface:INDArrayRaises all elements of the array to a specified power in place- Specified by:
powin interfaceINDArray- Overrides:
powin classAbstractArray<AVector>
-
square
public void square()
Description copied from interface:INDArraySquares all elements of the array in place- Specified by:
squarein interfaceINDArray- Overrides:
squarein classAbstractArray<AVector>
-
set
public void set(int[] indexes, double value)Description copied from interface:INDArraySets the element at the given indexed position in a mutable array
-
set
public void set(long[] indexes, double value)Description copied from interface:INDArraySets the element at the given indexed position in a mutable array- Specified by:
setin interfaceINDArray- Overrides:
setin classAbstractArray<AVector>
-
dimensionality
public final int dimensionality()
Description copied from interface:INDArrayReturns the dimensionality of the array (i.e. the number of dimensions in the array shape) e.g. 0 for a scalar, 1 for a vector, 2 for a matrix etc.- Specified by:
dimensionalityin interfaceINDArray
-
inputDimensions
public final int inputDimensions()
Returns the number of dimensions required for input vectors- Returns:
-
outputDimensions
public final int outputDimensions()
Returns the number of dimensions required for output vectors- Returns:
-
elementCount
public long elementCount()
Description copied from interface:INDArrayReturns the total number of elements in this array. Equivalent to the product of all dimension sizes.- Specified by:
elementCountin interfaceINDArray
-
slice
public final AVector slice(int row)
Description copied from interface:INDArrayReturns the specified major slice of this array as a view (slice along dimension 0) 0 dimensional slice results are permitted, but attempting to slice a 0 dimensional array will result in an error.
-
slice
public AVector slice(int dimension, int index)
Description copied from interface:INDArrayReturns a slice view of this array along the specified dimension
-
sliceCount
public int sliceCount()
Description copied from interface:INDArrayReturns the number of major slices in this array (i.e. the size of dimension 0)- Specified by:
sliceCountin interfaceINDArray
-
getSlices
public final java.util.List<AVector> getSlices()
Description copied from interface:INDArrayReturns a list of all major slices of this array. Returns a list of Double values if a 1-dimensional array is sliced, otherwise a list of INDArray instances- Specified by:
getSlicesin interfaceINDArray- Overrides:
getSlicesin classAbstractArray<AVector>
-
getRows
public java.util.List<AVector> getRows()
Description copied from interface:IMatrixGets a List of rows of a matrix. May return either copies or views, depending on the specific matrix type.
-
getColumns
public java.util.List<AVector> getColumns()
Description copied from interface:IMatrixGets a List of columns of a matrix. May return either copies or views, depending on the specific matrix type.- Specified by:
getColumnsin interfaceIMatrix- Returns:
-
getSlices
public final java.util.List<AVector> getSlices(int dimension)
Description copied from interface:INDArrayReturns a list of all slices of this array along a given dimension. Returns a list of Double values if a 1-dimensional array is sliced, otherwise a list of INDArray instances- Specified by:
getSlicesin interfaceINDArray- Overrides:
getSlicesin classAbstractArray<AVector>
-
getSliceViews
public java.util.List<INDArray> getSliceViews()
Description copied from interface:INDArrayReturns a list of slices as mutable INDArray views. Note: will return a list of AScalar values when this array is a 1D vector- Specified by:
getSliceViewsin interfaceINDArray- Overrides:
getSliceViewsin classAbstractArray<AVector>
-
join
public INDArray join(INDArray a, int dimension)
Description copied from interface:INDArrayJoins an array with another array along a specified dimension. Guarantees a view that combines the two joined arrays.- Specified by:
joinin interfaceINDArray- Overrides:
joinin classAbstractArray<AVector>
-
getShape
public int[] getShape()
Description copied from interface:INDArrayReturns the shape of the array as an array of ints. WARNING: May return the internal int[] array describing the shape. Modifying this may cause undefined behaviour. If you want to guarantee a new int[] array that can be safely modified, use getShapeClone() instead
-
getShapeClone
public int[] getShapeClone()
Description copied from interface:INDArrayReturns the shape of the array as an array of ints, guaranteed to be a new array i.e. will perform a defensive copy of any internal shape array if required.- Specified by:
getShapeClonein interfaceINDArray- Overrides:
getShapeClonein classAbstractArray<AVector>
-
getShape
public int getShape(int dim)
Description copied from interface:INDArrayReturns the dimension size for a specific dimension in the array's shape- Specified by:
getShapein interfaceINDArray- Overrides:
getShapein classAbstractArray<AVector>
-
getLongShape
public long[] getLongShape()
Description copied from interface:INDArrayReturns the shape of the array as an array of longs.- Specified by:
getLongShapein interfaceINDArray- Overrides:
getLongShapein classAbstractArray<AVector>
-
get
public double get(int... indexes)
Description copied from interface:INDArrayReturns the double value at the specified index position in an array
-
get
public final double get(AIndex ix)
Description copied from interface:INDArrayReturns the double value at the specified position in the array- Specified by:
getin interfaceINDArray- Overrides:
getin classAbstractArray<AVector>
-
getElement
public double getElement(long i)
Description copied from interface:INDArrayGets a specific element of this array, indexed in row-major order- Specified by:
getElementin interfaceINDArray- Returns:
- The element value
-
getLeadingDiagonal
public AVector getLeadingDiagonal()
Returns a vector view of the leading diagonal values of the matrix- Returns:
-
toAffineTransform
public AAffineTransform toAffineTransform()
-
isIdentity
public boolean isIdentity()
Description copied from interface:IMatrixChecks if this is an identity matrix (i.e. 1.0 in leading diagonal, 0.0 elsewhere)- Specified by:
isIdentityin interfaceIMatrix- Returns:
- true if this matrix is a square identity matrix, false otherwise.
-
isSquare
public boolean isSquare()
Description copied from interface:IMatrixChecks if this is a square matrix
-
isOrthogonal
public boolean isOrthogonal()
Check to see if the matrix is orthogonal (default tolerance: 1e-8)- Returns:
-
isOrthogonal
public boolean isOrthogonal(double tolerance)
Check to see if the matrix is orthogonal- Parameters:
tolerance- inner product of a column with all of the next columns should be less than tolerance- Returns:
-
hasOrthonormalColumns
public boolean hasOrthonormalColumns()
Tests whether all columns in the matrix are orthonormal vectors- Returns:
-
hasOrthonormalRows
public boolean hasOrthonormalRows()
Tests whether all rows in the matrix are orthonormal vectors- Returns:
-
reshape
public INDArray reshape(int... dimensions)
Description copied from interface:INDArrayReturns a new array by rearranging the elements of this array into the desired shape Truncates or zero-pads the elements as required to fill the new shape- Specified by:
reshapein interfaceINDArray- Overrides:
reshapein classAbstractArray<AVector>
-
reshape
public Matrix reshape(int rows, int cols)
-
reorder
public AMatrix reorder(int[] order)
Description copied from interface:INDArrayReturns a re-ordered array by taking the specified order of slices along dimension 0- Specified by:
reorderin interfaceINDArray- Overrides:
reorderin classAbstractArray<AVector>
-
reorder
public AMatrix reorder(int dim, int[] order)
Description copied from interface:INDArrayReturns a re-ordered array by taking the specified order of slices along a given dimension May or may not use views of underlying slices (i.e. may be a reordered view)- Specified by:
reorderin interfaceINDArray- Overrides:
reorderin classAbstractArray<AVector>
-
subMatrix
public AMatrix subMatrix(int rowStart, int rows, int colStart, int cols)
Description copied from interface:IMatrixGets a rectangular submatrix view of part of a matrix
-
subArray
public final AMatrix subArray(int[] offsets, int[] shape)
Description copied from interface:INDArrayReturns a subarray view of a larger array- Specified by:
subArrayin interfaceINDArray- Overrides:
subArrayin classAbstractArray<AVector>
-
rotateView
public INDArray rotateView(int dimension, int shift)
Description copied from interface:INDArrayReturns rotated view of this array- Specified by:
rotateViewin interfaceINDArray- Overrides:
rotateViewin classAbstractArray<AVector>
-
transform
public void transform(AVector source, AVector dest)
Description copied from interface:IMatrixTransforms a source vector into a destination vector, using matrix multiplication (inner product). The destination vector is overwritten.
-
transformInPlace
public void transformInPlace(AVector v)
- Specified by:
transformInPlacein interfaceIMatrix
-
transformInPlace
public void transformInPlace(ADenseArrayVector v)
-
getRow
public AVector getRow(int row)
Description copied from interface:IMatrixReturns a row of the matrix. May or may not be a view, depending on matrix type. Intended for the fastest possible read access of the row. This often means a view, but might not be (e.g. getRow on a Matrix33 returns a Vector3).
-
getColumn
public AVector getColumn(int column)
Description copied from interface:IMatrixReturns a column of the matrix. May or may not be a view, depending on matrix type. Intended for the fastest possible read access of the column. This often means a view, but might not be (e.g. getColumn on a Matrix33 returns a Vector3).
-
getRowView
public AVector getRowView(int row)
Description copied from interface:IMatrixReturns a row of the matrix as a vector view. May be used to modify the original matrix.- Specified by:
getRowViewin interfaceIMatrix
-
getColumnView
public AVector getColumnView(int column)
Description copied from interface:IMatrixReturns a column of the matrix as a vector view. May be used to modify the original matrix.- Specified by:
getColumnViewin interfaceIMatrix
-
getRowClone
public AVector getRowClone(int row)
Description copied from interface:IMatrixReturns a row of the matrix as a new cloned, mutable vector. The cloned row may be modified without affecting the original matrix.- Specified by:
getRowClonein interfaceIMatrix
-
getColumnClone
public AVector getColumnClone(int column)
Description copied from interface:IMatrixReturns a column of the matrix as a new cloned, mutable vector The cloned column may be modified without affecting the original matrix.- Specified by:
getColumnClonein interfaceIMatrix
-
set
public void set(AMatrix a)
Sets this matrix with the element values from another matrix. Source matrix must have the same shape.- Parameters:
a-
-
set
public void set(INDArray a)
Description copied from interface:INDArraySets this array to the element values contained in another array. Broadcasts the source array if necessary to the shape of this array. Throws an exception if the shapes are incompatible.- Specified by:
setin interfaceINDArray- Overrides:
setin classAbstractArray<AVector>
-
set
public void set(AVector v)
Sets every row of this matrix with the element values from a vector.- Parameters:
a-
-
set
public void set(java.lang.Object o)
Description copied from interface:INDArraySets this array to the element values contained in the given object. Attempts to interpret the object as an array, and broadcasts the object to the shape of this array if required.- Specified by:
setin interfaceINDArray- Overrides:
setin classAbstractArray<AVector>
-
getElements
public void getElements(double[] dest, int offset)Description copied from interface:INDArrayCopies all elements of this array a double array at the specified offset- Specified by:
getElementsin interfaceINDArray- Overrides:
getElementsin classAbstractArray<AVector>
-
setElements
public final void setElements(double... values)
Description copied from interface:INDArraySets all elements in an array using the given double values- Specified by:
setElementsin interfaceINDArray- Overrides:
setElementsin classAbstractArray<AVector>- Parameters:
values- Element values in a double[] array. There must be at least as many element values as elements in this array.
-
setMultiple
public final void setMultiple(INDArray a, double b)
Description copied from interface:INDArraySets this array to be the multiple of another array. Must have compatible shapes.- Specified by:
setMultiplein interfaceINDArray- Overrides:
setMultiplein classAbstractArray<AVector>
-
setMultiple
public void setMultiple(INDArray a, INDArray b)
Description copied from interface:INDArraySets this array to the element-wise multiple of two arrays. Must have compatible shapes.- Specified by:
setMultiplein interfaceINDArray- Overrides:
setMultiplein classAbstractArray<AVector>
-
setMultiple
public void setMultiple(AMatrix a, AMatrix b)
Sets this matrix to the elementwise product of two other matrices- Parameters:
a-b-
-
setMultiple
public final void setMultiple(AMatrix a, double b)
Sets this matrix to a multiple of another matrix- Parameters:
a-b-
-
setMultiple
public final void setMultiple(AVector a, double b)
Sets every row of this matrix to a multiple of a vector- Parameters:
a-b-
-
setElements
public void setElements(double[] values, int offset)Description copied from interface:INDArraySets all elements in an array using the given double values- Specified by:
setElementsin interfaceINDArray- Overrides:
setElementsin classAbstractArray<AVector>- Parameters:
values- Element values in a double[] array. There must be at least as many element values as elements in this array.offset- Position in the values array from which to start taking values.
-
isFullyMutable
public abstract boolean isFullyMutable()
Description copied from interface:INDArrayIf this method returns true, the INDArray is guaranteed to be fully mutable in all positions i.e. every position can store any valid double value- Specified by:
isFullyMutablein interfaceINDArray- Overrides:
isFullyMutablein classAbstractArray<AVector>
-
isMutable
public boolean isMutable()
Description copied from interface:INDArrayReturns true if the INDArray is mutable (at least partially)- Specified by:
isMutablein interfaceINDArray- Overrides:
isMutablein classAbstractArray<AVector>
-
isElementConstrained
public boolean isElementConstrained()
Description copied from interface:INDArrayReturns true if this array has some constraints on element values- Specified by:
isElementConstrainedin interfaceINDArray- Overrides:
isElementConstrainedin classAbstractArray<AVector>
-
clone
public AMatrix clone()
Description copied from interface:INDArrayReturns a clone of the array data, as a new array which will be fully mutable and may be of a different class to the original. Clone should attempt to return the most efficient possible array type. Clone should preserve sparsity property where possible, but this is not guaranteed.- Specified by:
clonein interfaceINDArray- Overrides:
clonein classAbstractArray<AVector>
-
copy
public AMatrix copy()
Description copied from interface:INDArrayReturns a defensive copy of the array data. Use this if the original array might change and you need a defensive copy. May return the same array if the original was immutable, otherwise will return a defensive copy.- Specified by:
copyin interfaceINDArray- Overrides:
copyin classAbstractArray<AVector>
-
sparseClone
public AMatrix sparseClone()
Description copied from interface:INDArrayCreates a fully mutable clone of this array. Will use a sparse format if possible.- Specified by:
sparseClonein interfaceINDArray- Overrides:
sparseClonein classAbstractArray<AVector>
-
ensureMutable
public AMatrix ensureMutable()
Description copied from interface:INDArrayEnsures the array is a fully mutable representation. Returns either the same array or a new clone.- Specified by:
ensureMutablein interfaceINDArray- Overrides:
ensureMutablein classAbstractArray<AVector>
-
determinant
public double determinant()
Calculates the determinant of the matrix.
-
rank
public int rank()
Calculate the rank of a matrix. This is equivalent to the maximum number of linearly independent rows or columns.
-
toMutableMatrix
public AMatrix toMutableMatrix()
Creates a fully mutable deep copy of this matrix- Returns:
- A new matrix
-
transposeInPlace
public void transposeInPlace()
Description copied from interface:IMatrixTransposes a matrix in place, if possible. Throws an exception if this is not possible (e.g. if the matrix is not square or not sufficiently mutable)- Specified by:
transposeInPlacein interfaceIMatrix
-
getTranspose
public AMatrix getTranspose()
Description copied from interface:INDArrayReturns the transpose of this array. A transpose of an array is equivalent to reversing the order of dimensions. May or may not return a view depending on the array type.- Specified by:
getTransposein interfaceINDArray- Specified by:
getTransposein interfaceIMatrix- Overrides:
getTransposein classAbstractArray<AVector>- Returns:
- the transpose of this matrix
-
getTransposeView
public AMatrix getTransposeView()
Description copied from interface:INDArrayReturns a transposed view of the array. May throw UnsupportedOperationException if the array type does not support this capability- Specified by:
getTransposeViewin interfaceINDArray- Specified by:
getTransposeViewin interfaceIMatrix- Overrides:
getTransposeViewin classAbstractArray<AVector>- Returns:
- the transpose of this matrix, as a view
-
getTransposeCopy
public AMatrix getTransposeCopy()
Gets a mutable transposed clone of the matrix- Specified by:
getTransposeCopyin interfaceINDArray- Overrides:
getTransposeCopyin classAbstractArray<AVector>
-
add
public void add(AMatrix m)
Adds another matrix to this matrix. Matrices must be the same size.
-
add
public void add(AVector v)
Adds a vector to every row of this matrix.
-
sub
public void sub(AVector v)
Subtracts a vector from every row of this matrix.
-
scaleAdd
public final void scaleAdd(double factor, double constant)Description copied from interface:INDArrayScales all elements of the array by a given double value and adds a constant value- Specified by:
scaleAddin interfaceINDArray- Overrides:
scaleAddin classAbstractArray<AVector>
-
scaleAdd
public void scaleAdd(double factor, INDArray b, double bfactor, double constant)Description copied from interface:INDArrayScales all elements of the array by a given double value, adds a scaled second array and adds a constant value- Specified by:
scaleAddin interfaceINDArray- Overrides:
scaleAddin classAbstractArray<AVector>
-
multiply
public void multiply(double factor)
Description copied from interface:INDArrayMultiplies all elements of the array in place by a given double value- Specified by:
multiplyin interfaceINDArray- Overrides:
multiplyin classAbstractArray<AVector>
-
multiplyCopy
public AMatrix multiplyCopy(double factor)
Description copied from interface:INDArrayReturns a copy of the array with all elements multiplied by a single constant value- Specified by:
multiplyCopyin interfaceINDArray- Overrides:
multiplyCopyin classAbstractArray<AVector>- Parameters:
factor- A scalar factor- Returns:
- A new array, with all element values scaled by the given factor
-
divideCopy
public AMatrix divideCopy(double d)
Description copied from interface:INDArrayReturns a copy of the array with all elements divided by a single constant value- Specified by:
divideCopyin interfaceINDArray- Overrides:
divideCopyin classAbstractArray<AVector>- Returns:
- A new array, with all element values scaled by the given factor
-
elementSum
public double elementSum()
Returns the sum of all elements in this matrix- Specified by:
elementSumin interfaceINDArray- Overrides:
elementSumin classAbstractArray<AVector>- Parameters:
m-- Returns:
-
elementSquaredSum
public double elementSquaredSum()
Returns the squared sum of all elements in this matrix- Specified by:
elementSquaredSumin interfaceINDArray- Overrides:
elementSquaredSumin classAbstractArray<AVector>- Parameters:
m-- Returns:
-
elementIterator
public java.util.Iterator<java.lang.Double> elementIterator()
Description copied from interface:INDArrayReturns an iterator over all elements in this array, in row-major order- Specified by:
elementIteratorin interfaceINDArray- Overrides:
elementIteratorin classAbstractArray<AVector>
-
isBoolean
public boolean isBoolean()
Description copied from interface:INDArrayReturns true if the array is boolean (contains only 0.0 or 1.0 values)- Specified by:
isBooleanin interfaceINDArray- Overrides:
isBooleanin classAbstractArray<AVector>
-
nonZeroCount
public long nonZeroCount()
Description copied from interface:INDArrayReturns the number of non-zero elements in the array.- Specified by:
nonZeroCountin interfaceINDArray- Overrides:
nonZeroCountin classAbstractArray<AVector>
-
sub
public void sub(AMatrix m)
Subtracts another matrix from this one- Parameters:
m-
-
subCopy
public AMatrix subCopy(AMatrix m)
Subtracts another matrix from this one, returning a new matrix- Parameters:
m-
-
negate
public void negate()
Description copied from interface:INDArrayNegates all elements in the array in place- Specified by:
negatein interfaceINDArray- Overrides:
negatein classAbstractArray<AVector>
-
reciprocal
public void reciprocal()
Description copied from interface:INDArrayReplaces all elements in the array with their reciprocal- Specified by:
reciprocalin interfaceINDArray- Overrides:
reciprocalin classAbstractArray<AVector>
-
abs
public void abs()
Description copied from interface:INDArrayReplaces all elements of this array with their absolute values, according to Math.abs(double)- Specified by:
absin interfaceINDArray- Overrides:
absin classAbstractArray<AVector>
-
sqrt
public void sqrt()
Description copied from interface:INDArrayComputes the square root of all elements in the array- Specified by:
sqrtin interfaceINDArray- Overrides:
sqrtin classAbstractArray<AVector>
-
log
public void log()
Description copied from interface:INDArrayComputes the natural logarithm (in-place) for all array elements- Specified by:
login interfaceINDArray- Overrides:
login classAbstractArray<AVector>
-
exp
public void exp()
Description copied from interface:INDArrayComputes the function e^x (in-place) for all array elements- Specified by:
expin interfaceINDArray- Overrides:
expin classAbstractArray<AVector>
-
signum
public void signum()
Description copied from interface:INDArrayCalculates the signum of all elements of this mutable array Sets each component of the array to its sign value (-1, 0 or 1)- Specified by:
signumin interfaceINDArray- Overrides:
signumin classAbstractArray<AVector>
-
multiply
public void multiply(AMatrix m)
Multiplies this matrix in-place by another in an entrywise manner (Hadamard product).- Parameters:
m-
-
divide
public void divide(AMatrix m)
Divides this matrix in-place by another in an entrywise manner.- Parameters:
m-
-
mul
public void mul(AMatrix a)
"Multiplies" this matrix by another, composing the transformation- Parameters:
a-
-
multiplyRow
public void multiplyRow(int i, double factor)Multiplies a row by a constant factor This is an elementary row operation
-
addRowMultiple
public void addRowMultiple(int src, int dst, double factor)Adds a multiple of a source row to a destination row This is an elementary row operation
-
addInnerProduct
public void addInnerProduct(INDArray a, INDArray b)
Description copied from interface:INDArrayAdds the inner product of two arrays to this array.- Specified by:
addInnerProductin interfaceINDArray- Overrides:
addInnerProductin classAbstractArray<AVector>
-
addInnerProduct
public final void addInnerProduct(AMatrix a, INDArray b)
Description copied from class:AbstractArrayAdds the inner product of a matrix and an array to this array- Overrides:
addInnerProductin classAbstractArray<AVector>
-
addInnerProduct
public void addInnerProduct(AMatrix a, AMatrix b)
Adds the inner product (matrix multiply) of two matrices to this matrix
-
addOuterProduct
public void addOuterProduct(INDArray a, INDArray b)
Description copied from interface:INDArrayAdds the outer product of two arrays to this array.- Specified by:
addOuterProductin interfaceINDArray- Overrides:
addOuterProductin classAbstractArray<AVector>
-
addOuterProductSparse
public void addOuterProductSparse(INDArray a, INDArray b)
Description copied from interface:INDArrayAdds the outer product of two arrays to this array. Only affects the mutable, non-sparse elements of this array.- Specified by:
addOuterProductSparsein interfaceINDArray- Overrides:
addOuterProductSparsein classAbstractArray<AVector>
-
addOuterProductSparse
public void addOuterProductSparse(AVector a, AVector b)
Adds the outer product of two vectors to this matrix. Mutates only the non-sparse elements in this matrix- Parameters:
a-b-
-
addOuterProduct
public void addOuterProduct(AVector a, AVector b)
Adds the outer product of two vectors to this matrix- Parameters:
a-b-
-
addSparse
public void addSparse(INDArray a)
Description copied from interface:INDArrayAdds the corresponding elements of the source array the non-sparse elements of this array- Specified by:
addSparsein interfaceINDArray- Overrides:
addSparsein classAbstractArray<AVector>
-
addSparse
public void addSparse(AVector a)
Adds the corresponding elements of the source vector to the non-sparse elements in rows of this matrix- Parameters:
a-
-
setSparse
public final void setSparse(INDArray a)
Description copied from interface:INDArraySets the non-sparse elements of this array to the corresponding elements of the source array- Specified by:
setSparsein interfaceINDArray- Overrides:
setSparsein classAbstractArray<AVector>
-
setSparse
public void setSparse(AMatrix a)
Sets the non-sparse elements in this matrix to the corresponding values in the source matrix- Parameters:
a-
-
addToArray
public void addToArray(double[] data, int offset)Description copied from interface:INDArrayAdds all the elements of this array to a double array at the specified offset, in row-major order- Specified by:
addToArrayin interfaceINDArray- Overrides:
addToArrayin classAbstractArray<AVector>
-
swapRows
public void swapRows(int i, int j)Swaps two rows of the matrix in place This is an elementary row operation
-
swapColumns
public void swapColumns(int i, int j)Swaps two columns of the matrix in place
-
composeWith
public void composeWith(AMatrix a)
-
isView
public boolean isView()
Description copied from interface:INDArrayReturn true if this array is considered as a view type. This indicates (but does not guarantee): a) Data is *likely* to be shared with other arrays, so mutation of one may affect others b) It is *unlikely* to be in the most efficient general purpose format isView is intended to be used as for heuristics. It should *not* be used where the outcome might affect correctness.
-
addMultiple
public void addMultiple(INDArray src, double factor)
Description copied from interface:INDArrayAdds a scaled multiple of another array to this array- Specified by:
addMultiplein interfaceINDArray- Overrides:
addMultiplein classAbstractArray<AVector>
-
addMultiple
public void addMultiple(AVector v, double factor)
Adds a scalar multiple of a vector to every row of this matrix- Parameters:
m-factor-
-
addMultiple
public void addMultiple(AMatrix m, double factor)
Adds a scalar multiple of another matrix to this matrix- Parameters:
m-factor-
-
iterator
public java.util.Iterator<AVector> iterator()
Returns an iterator over rows in this Matrix- Specified by:
iteratorin interfacejava.lang.Iterable<AVector>- Overrides:
iteratorin classAbstractArray<AVector>
-
epsilonEquals
public final boolean epsilonEquals(INDArray a, double epsilon)
Description copied from interface:INDArrayTests is this array is approximately equal to another array, up to a given tolerance (epsilon) The arrays must have the same shape- Specified by:
epsilonEqualsin interfaceINDArray- Overrides:
epsilonEqualsin classAbstractArray<AVector>
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classAbstractArray<AVector>
-
equals
public boolean equals(AMatrix a)
Returns true if this matrix is exactly equal to another matrix
-
equalsArray
public boolean equalsArray(double[] data, int offset)Description copied from interface:INDArrayReturns true if the elements in this array exactly match the elements in the given array, in row-major order- Specified by:
equalsArrayin interfaceINDArray- Overrides:
equalsArrayin classAbstractArray<AVector>- Parameters:
data- Array of double element values to check for equalityoffset- Offset into the data array- Returns:
-
elementsEqual
public boolean elementsEqual(double value)
Description copied from interface:INDArrayReturns true if all elements are equal to a specific value- Specified by:
elementsEqualin interfaceINDArray- Overrides:
elementsEqualin classAbstractArray<AVector>
-
equalsTranspose
public boolean equalsTranspose(AMatrix a)
Tests if this matrix is exactly equal to the transpose of another matrix- Parameters:
a-- Returns:
-
equals
public boolean equals(INDArray v)
Description copied from interface:INDArrayChecks if two arrays are equal exactly in terms of both value and shape Element equality checks are consistent with compareTo- Specified by:
equalsin interfaceINDArray- Overrides:
equalsin classAbstractArray<AVector>
-
epsilonEquals
public final boolean epsilonEquals(AMatrix a)
Returns true if this matrix is approximately equal to a second matrix, up to a default tolerance level
-
epsilonEquals
public boolean epsilonEquals(AMatrix a, double epsilon)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classAbstractArray<AVector>
-
toStringFull
public java.lang.String toStringFull()
- Overrides:
toStringFullin classAbstractArray<AVector>
-
hashCode
public int hashCode()
- Overrides:
hashCodein classAbstractArray<AVector>
-
asVector
public AVector asVector()
Returns the matrix values as a single reference Vector in the form [row0 row1 row2....]- Specified by:
asVectorin interfaceINDArray- Overrides:
asVectorin classAbstractArray<AVector>- Returns:
-
asElementList
public java.util.List<java.lang.Double> asElementList()
Description copied from interface:INDArrayReturns a Listcontaining all elements of this array - Specified by:
asElementListin interfaceINDArray- Overrides:
asElementListin classAbstractArray<AVector>
-
innerProduct
public AMatrix innerProduct(AMatrix a)
Description copied from interface:IMatrixComputes the inner product of this matrix with another. Equivalent to matrix x matrix multiplication- Specified by:
innerProductin interfaceIMatrix- Returns:
-
innerProduct
public Vector innerProduct(Vector v)
Description copied from interface:IMatrixTransforms a dense source Vector using matrix multiplication (inner product).- Specified by:
innerProductin interfaceIMatrix- Returns:
- A new dense vector
-
innerProduct
public AVector innerProduct(AVector v)
Description copied from interface:INDArrayComputes the inner product of this array with a vector- Specified by:
innerProductin interfaceINDArray- Specified by:
innerProductin interfaceIMatrix- Overrides:
innerProductin classAbstractArray<AVector>- Parameters:
v- A vector- Returns:
- A new array representing the inner product
-
innerProduct
public final AMatrix innerProduct(AScalar s)
Description copied from interface:INDArrayCalculates the inner product of this array with a scalar- Specified by:
innerProductin interfaceINDArray- Overrides:
innerProductin classAbstractArray<AVector>
-
innerProduct
public final AMatrix innerProduct(double d)
Description copied from interface:INDArrayCalculates the inner product of this array with a double value- Specified by:
innerProductin interfaceINDArray- Overrides:
innerProductin classAbstractArray<AVector>
-
innerProduct
public INDArray innerProduct(INDArray a)
Description copied from interface:INDArrayCalculates the inner product of this array with another array.- Specified by:
innerProductin interfaceINDArray- Overrides:
innerProductin classAbstractArray<AVector>
-
outerProduct
public INDArray outerProduct(INDArray a)
Description copied from interface:INDArrayCalculates the outer product of this array with another array.- Specified by:
outerProductin interfaceINDArray- Overrides:
outerProductin classAbstractArray<AVector>
-
rowDotProduct
public double rowDotProduct(int i, AVector a)Returns the dot product of a specific row with a vector. Unsafe operation: performs no bounds checking- Parameters:
i-a-- Returns:
-
inverse
public AMatrix inverse()
Computes the inverse of a matrix. Returns null if the matrix is singular. Throws an Exception is the matrix is not square
-
trace
public double trace()
Description copied from interface:IMatrixComputes the trace of a matrix, i.e. the sum of all elements on the leading diagonal
-
diagonalProduct
public double diagonalProduct()
Computes the product of entries on the main diagonal of a matrix- Specified by:
diagonalProductin interfaceIMatrix- Returns:
-
isInvertible
public boolean isInvertible()
Description copied from interface:IMatrixChecks if this is an invertible matrix (i.e. a square matrix with a non-zero determinant)- Specified by:
isInvertiblein interfaceIMatrix- Returns:
- true if invertible, false otherwise
-
toVector
public Vector toVector()
Description copied from interface:INDArrayCoerces the array into a flattened dense Vector, in row-major order. May return the same array if it is already a Vector instance.- Specified by:
toVectorin interfaceINDArray- Overrides:
toVectorin classAbstractArray<AVector>
-
toMatrix
public Matrix toMatrix()
Coerces the matrix to the standard mutable Matrix type in row major order. Performs a copy if necessary.
-
toMatrixTranspose
public Matrix toMatrixTranspose()
Coerces the transpose of a matrix to the standard mutable Matrix type in row major order. Performs a copy if necessary.
-
toDoubleBuffer
public void toDoubleBuffer(java.nio.DoubleBuffer dest)
Description copied from interface:INDArrayCopies the elements of this INDArray to the specified double buffer.- Specified by:
toDoubleBufferin interfaceINDArray- Overrides:
toDoubleBufferin classAbstractArray<AVector>
-
toDoubleArray
public double[] toDoubleArray()
Description copied from interface:INDArrayCopies the elements of this array to a new double[] array.- Specified by:
toDoubleArrayin interfaceINDArray- Overrides:
toDoubleArrayin classAbstractArray<AVector>
-
toNestedDoubleArrays
public double[][] toNestedDoubleArrays()
Description copied from interface:IMatrixConverts this matrix to nested double[][] array- Specified by:
toNestedDoubleArraysin interfaceIMatrix- Returns:
-
toSliceArray
public AVector[] toSliceArray()
Description copied from interface:INDArrayCopies the slices of this array to a new INDArray[] Throws an error if the array has no slices (i.e. is zero-dimensional)- Specified by:
toSliceArrayin interfaceINDArray- Overrides:
toSliceArrayin classAbstractArray<AVector>
-
asDoubleArray
public double[] asDoubleArray()
Description copied from interface:INDArrayReturns the underlying double array representing the densely packed elements of this array. Modifications to this double array will change the original array. Returns null if there is no such array.- Specified by:
asDoubleArrayin interfaceINDArray- Overrides:
asDoubleArrayin classAbstractArray<AVector>
-
applyOp
public void applyOp(Op op)
Description copied from interface:INDArrayApplies a unary operator to all elements of the array (in-place)- Specified by:
applyOpin interfaceINDArray- Overrides:
applyOpin classAbstractArray<AVector>
-
setApplyOp
public final void setApplyOp(Op op, INDArray a)
Description copied from interface:INDArraySets this array to the result of applying an operation to a source array- Specified by:
setApplyOpin interfaceINDArray- Overrides:
setApplyOpin classAbstractArray<AVector>
-
setApplyOp
public void setApplyOp(Op op, AMatrix a)
Sets this matrix to the result of applying an operator to another matrix- Parameters:
op-a-
-
applyOpCopy
public AMatrix applyOpCopy(Op op)
Description copied from interface:INDArrayApplies a unary operator to all elements of the array (creating a new array)- Specified by:
applyOpCopyin interfaceINDArray- Overrides:
applyOpCopyin classAbstractArray<AVector>
-
applyOp
public void applyOp(Op2 op, INDArray b)
Description copied from interface:INDArrayApplies a binary operator to this array and a second array. Broadcasts the second array to the shape of this array if required.- Specified by:
applyOpin interfaceINDArray- Overrides:
applyOpin classAbstractArray<AVector>
-
applyOp
public void applyOp(Op2 op, double b)
Description copied from interface:INDArrayApplies a binary operator to this array and a double value. Works as if the double value was broadcast to the shape of this array.- Specified by:
applyOpin interfaceINDArray- Overrides:
applyOpin classAbstractArray<AVector>
-
applyOp
public void applyOp(IOperator op)
Description copied from interface:INDArrayApplies a unary operator to all elements of the array (in-place)- Specified by:
applyOpin interfaceINDArray- Overrides:
applyOpin classAbstractArray<AVector>- Parameters:
op- The operator to apply to the array
-
reduce
public double reduce(Op2 op, double init)
Description copied from interface:INDArrayReduces over all elements of the array in row-major order. Applies the operator to the initial/previous result at each step. Returns the final result.- Specified by:
reducein interfaceINDArray- Overrides:
reducein classAbstractArray<AVector>
-
reduce
public double reduce(Op2 op)
Description copied from interface:INDArrayReduces over all elements of the array in row-major order. Applies the operator to the previous result at each step. Returns the final result.- Specified by:
reducein interfaceINDArray- Overrides:
reducein classAbstractArray<AVector>
-
reduceSlices
public AVector reduceSlices(Op2 op)
Description copied from interface:INDArrayReduces each vector slice of the array by the given binary operator Reduces down to a single vector- Specified by:
reduceSlicesin interfaceINDArray- Overrides:
reduceSlicesin classAbstractArray<AVector>
-
reduceSlices
public AVector reduceSlices(Op2 op, double init)
Description copied from interface:INDArrayReduces each slice of the array by the given binary operator. Results are returned in a vector with one element for each slice. Uses the specified initial value for reduction of each slice.- Specified by:
reduceSlicesin interfaceINDArray- Overrides:
reduceSlicesin classAbstractArray<AVector>
-
add
public void add(INDArray a)
Description copied from interface:INDArrayAdds all the elements of another array to this array, in an elementwise order.- Specified by:
addin interfaceINDArray- Overrides:
addin classAbstractArray<AVector>
-
multiply
public void multiply(AVector v)
Multiply each row in this matrix by a vector. Mutates this matrix.- Parameters:
v-
-
multiply
public void multiply(INDArray a)
Description copied from interface:INDArrayMultiplies all elements by the equivalent elements in a second array, i.e. performs elementwise multiplication. If matrix-style multiplication is required, use innerProduct instead.- Specified by:
multiplyin interfaceINDArray- Overrides:
multiplyin classAbstractArray<AVector>
-
divide
public void divide(AVector v)
Divides every row of this matrix by the given vector- Parameters:
v-
-
divide
public void divide(INDArray a)
Description copied from interface:INDArrayDivides all elements in place by the equivalent elements in a second array- Specified by:
dividein interfaceINDArray- Overrides:
dividein classAbstractArray<AVector>
-
divide
public void divide(double factor)
Description copied from interface:INDArrayDivides all elements by a given factor- Specified by:
dividein interfaceINDArray- Overrides:
dividein classAbstractArray<AVector>
-
sub
public void sub(INDArray a)
Description copied from interface:INDArraySubtracts all the elements of another array from this array, in an elementwise order.- Specified by:
subin interfaceINDArray- Overrides:
subin classAbstractArray<AVector>
-
add
public void add(double d)
Description copied from interface:INDArrayAdds a double value to all elements in this array. Implementations may optimize the case of 0.0- Specified by:
addin interfaceINDArray- Overrides:
addin classAbstractArray<AVector>
-
addAt
public void addAt(int i, int j, double d)Description copied from interface:IMatrixAdds a value at a specific position in the matrix, mutating the matrix Does not perform bounds checking - this in an unsafe operation
-
broadcast
public INDArray broadcast(int... targetShape)
Description copied from interface:INDArrayReturns a view of this array broadcasted up to a larger shape- Specified by:
broadcastin interfaceINDArray- Overrides:
broadcastin classAbstractArray<AVector>
-
broadcastLike
public INDArray broadcastLike(INDArray target)
Description copied from interface:INDArrayBroadcasts an array to match the shape of the target- Specified by:
broadcastLikein interfaceINDArray- Overrides:
broadcastLikein classAbstractArray<AVector>- Parameters:
target- The target array
-
broadcastLike
public AMatrix broadcastLike(AMatrix target)
Description copied from interface:INDArrayBroadcasts an array to match the shape of the target matrix- Specified by:
broadcastLikein interfaceINDArray- Overrides:
broadcastLikein classAbstractArray<AVector>- Parameters:
target- The target matrix
-
broadcastCloneLike
public INDArray broadcastCloneLike(INDArray target)
Description copied from interface:INDArrayCreates a mutable clone of the array, broadcasted upwards if necessary to match the shape of the target. If no upwards broadcasting is required, returns a regular clone() of this array.- Specified by:
broadcastCloneLikein interfaceINDArray- Overrides:
broadcastCloneLikein classAbstractArray<AVector>- Parameters:
target- The target array
-
broadcastCopyLike
public INDArray broadcastCopyLike(INDArray target)
Description copied from interface:INDArrayCreates a copy of the array, broadcasted upwards if necessary to match the shape of the target Like broadCastCloneLike, but does not guarantee a fully mutable clone - hence may be faster when used with immutable or specialized arrays- Specified by:
broadcastCopyLikein interfaceINDArray- Overrides:
broadcastCopyLikein classAbstractArray<AVector>- Parameters:
target- The target array
-
isZero
public boolean isZero()
Returns true if the matrix is the zero matrix (all components zero)- Specified by:
isZeroin interfaceINDArray- Overrides:
isZeroin classAbstractArray<AVector>
-
isPositiveDefinite
public boolean isPositiveDefinite()
Returns true if a matrix is positive definite
-
isDiagonal
public boolean isDiagonal()
Description copied from interface:IMatrixReturns true iff this matrix is a square diagonal matrix- Specified by:
isDiagonalin interfaceIMatrix
-
isSameShape
public boolean isSameShape(INDArray a)
Description copied from interface:INDArrayReturns true if this array is the same shape as another array- Specified by:
isSameShapein interfaceINDArray- Overrides:
isSameShapein classAbstractArray<AVector>
-
isSameShape
public boolean isSameShape(AMatrix a)
Returns true iff this matrix is exactly the same shape as another matrix- Parameters:
a-- Returns:
-
isRectangularDiagonal
public boolean isRectangularDiagonal()
Description copied from interface:IMatrixReturns true iff this matrix is a diagonal matrix (might not be square)- Specified by:
isRectangularDiagonalin interfaceIMatrix
-
isSymmetric
public boolean isSymmetric()
Returns true if a matrix is symmetric- Specified by:
isSymmetricin interfaceIMatrix- Returns:
-
isHermitian
public final boolean isHermitian()
Returns true if a matrix is Hermitian This is equivalent to isSymmetric(), since all Vectorz matrices have real values.
-
isUpperTriangular
public boolean isUpperTriangular()
Returns true if a matrix is upper triangular An upper triangular matrix is defined as having all elements equal to 0.0 where i > j
-
isLowerTriangular
public boolean isLowerTriangular()
Returns true if a matrix is lower triangular. A lower triangular matrix is defined as having all elements equal to 0.0 where i < j
-
upperBandwidthLimit
public int upperBandwidthLimit()
A limit on the upper bandwidth of the banded matrix. Actual upper bandwidth is guaranteed to be less than or equal to this value. Implementation should be O(1).- Returns:
-
lowerBandwidthLimit
public int lowerBandwidthLimit()
A limit on the lower bandwidth of the banded matrix. Actual lower bandwidth is guaranteed to be less than or equal to this value. Implementation should be O(1).- Returns:
-
bandLength
public int bandLength(int band)
Returns the length of a band of the matrix. Returns 0 if the band is outside the matrix.- Parameters:
band-- Returns:
-
bandStartRow
public final int bandStartRow(int band)
Returns the start row of a given band.- Parameters:
band-- Returns:
-
bandStartColumn
public final int bandStartColumn(int band)
Returns the start column of a given band.- Parameters:
band-- Returns:
-
bandIndex
public final int bandIndex(int i, int j)Returns the band index number for a specified position in the matrix.- Parameters:
i-j-- Returns:
-
bandPosition
public final int bandPosition(int i, int j)Returns the band position for a specified (i,j) index in the matrix.- Parameters:
i-j-- Returns:
-
upperBandwidth
public int upperBandwidth()
Computes the upper bandwidth of a matrix, i.e. the number of bands above the leading diagonal that cover all non-zero values- Returns:
-
lowerBandwidth
public int lowerBandwidth()
Computes the lower bandwidth of a matrix, i.e. the number of bands below the leading diagonal that cover all non-zero values- Returns:
-
getBand
public AVector getBand(int band)
Gets a specific band of the matrix, as a view vector. The band is truncated at the edges of the matrix, i.e. it does not wrap around the matrix.
-
getBandWrapped
public AVector getBandWrapped(int band)
-
setRow
public void setRow(int i, AVector row)Sets a row in a matrix to the value specified by the given vector- Parameters:
i-row-
-
replaceRow
public void replaceRow(int i, AVector row)Replaces a row in a matrix, adding the row to the internal structure of the matrix. Will throw UnsupportedOperationException if not possible for the given matrix type.- Parameters:
i-row-
-
replaceColumn
public void replaceColumn(int i, AVector row)Replaces a column in a matrix, adding the column to the internal structure of the matrix. Will throw UnsupportedOperationException if not possible for the given matrix type.- Parameters:
i-row-
-
setColumn
public void setColumn(int i, AVector col)Sets a column in a matrix.- Parameters:
i-row-
-
exactClone
public abstract AMatrix exactClone()
Description copied from interface:INDArrayCreates a deep clone of an array, using the same class implementation as the original array- Specified by:
exactClonein interfaceINDArray- Returns:
- A clone of the original array
-
immutable
public INDArray immutable()
Description copied from interface:INDArrayReturns an immutable version of this array. May return the same array if already immutable. Guarantees a defensive copy if the array is mutable.- Specified by:
immutablein interfaceINDArray- Overrides:
immutablein classAbstractArray<AVector>
-
mutable
public AMatrix mutable()
Description copied from interface:INDArrayCoerces this INDArray to a fully mutable format. May return the same INDArray if already fully mutable- Specified by:
mutablein interfaceINDArray- Overrides:
mutablein classAbstractArray<AVector>
-
sparse
public AMatrix sparse()
Description copied from interface:INDArrayCoerces this INDArray to a sparse format, without changing its element values. May return the same INDArray if already sparse. May also mutate the internal structure of the original NDArray, or create a view over parts of the original INDArray. You should take a defensive copy of the original NDArray if any of this concerns you. The returned sparse array may not be fully mutable in all elements.- Specified by:
sparsein interfaceINDArray- Overrides:
sparsein classAbstractArray<AVector>
-
dense
public AMatrix dense()
Description copied from interface:INDArrayCoerces this INDArray to a dense format, without changing its element values. May return the same INDArray if already dense. May also mutate the internal structure of the original NDArray, or create a view over parts of the original INDArray. You should take a defensive copy of the original NDArray if any of this concerns you. The returned dense array may not be fully mutable in all elements.- Specified by:
densein interfaceINDArray- Overrides:
densein classAbstractArray<AVector>
-
denseClone
public final Matrix denseClone()
Description copied from interface:INDArrayCreates a fully mutable dense clone of this array. Will always use a dense format, even if the array data is sparse.- Specified by:
denseClonein interfaceINDArray- Overrides:
denseClonein classAbstractArray<AVector>
-
validate
public void validate()
Description copied from interface:INDArrayValidates the internal data structure of the INDArray. Throws an exception on failure. Failure indicates a serious bug and/or data corruption.- Specified by:
validatein interfaceINDArray- Overrides:
validatein classAbstractArray<AVector>
-
copyRowTo
public void copyRowTo(int i, double[] dest, int destOffset)Copies the elements in a selected row of this matrix to a double array- Parameters:
i- The index of the selected rowdest- Destination double[] arraydestOffset- Offset into destination array
-
copyColumnTo
public void copyColumnTo(int j, double[] dest, int destOffset)Copies the elements in a selected row of this matrix to a double array- Parameters:
i- The index of the selected columndest- Destination double[] arraydestOffset-
-
addCopy
public final INDArray addCopy(INDArray a)
Description copied from interface:INDArrayCreates a new array equal to the sum of this array with another array.- Specified by:
addCopyin interfaceINDArray- Overrides:
addCopyin classAbstractArray<AVector>- Returns:
-
addCopy
public AMatrix addCopy(AMatrix a)
Description copied from interface:IMatrixAdds another matrix to this matrix, returning a new matrix
-
addCopy
public AMatrix addCopy(AVector v)
Description copied from interface:IMatrixAdds a vector to every row of this matrix, returning a new matrix
-
addCopy
public AMatrix addCopy(double d)
Description copied from interface:INDArrayCreates a new array equal to this array with a constant value added to every element- Specified by:
addCopyin interfaceINDArray- Overrides:
addCopyin classAbstractArray<AVector>- Returns:
-
addCopy
public Matrix addCopy(AStridedMatrix a)
Adds a dense matrix to this matrix, returning a new dense Matrix- Parameters:
m- A matrix. Not modified.- Returns:
- True if any element in the matrix is NaN of Infinite.
-
hasUncountable
public boolean hasUncountable()
Checks to see if any element in the matrix is NaN of Infinite.- Specified by:
hasUncountablein interfaceINDArray- Overrides:
hasUncountablein classAbstractArray<AVector>- Parameters:
m- A matrix. Not modified.- Returns:
- True if any element in the matrix is NaN of Infinite.
-
checkSquare
public int checkSquare()
Checks if a matrix is square. Returns the size if true, throws an exception otherwise;- Returns:
-
checkColumn
public int checkColumn(int column)
Checks if the given column index is valid for this matrix. Throws an exception if not.- Returns:
- the number of columns in this matrix
-
checkRow
public int checkRow(int row)
Checks if the given rows index is valid for this matrix. Throws an exception if not.- Returns:
- the number of rows in this matrix
-
-
DMelt 3.0 © DataMelt by jWork.ORG