mikera.matrixx
Class Matrix22
- java.lang.Object
-
- mikera.arrayz.impl.AbstractArray<AVector>
-
- mikera.matrixx.AMatrix
-
- mikera.matrixx.impl.APrimitiveMatrix
-
- mikera.matrixx.Matrix22
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<INDArray>, java.lang.Iterable<AVector>, INDArray, IMatrix, ISpecialisedTransform
public final class Matrix22 extends APrimitiveMatrix implements ISpecialisedTransform
Specialised 2*2 Matrix for Vector2 maths, using primitive matrix elements- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field and Description doublem00doublem01doublem10doublem11
-
Constructor Summary
Constructors Constructor and Description Matrix22()Matrix22(AMatrix m)Matrix22(double m00, double m01, double m10, double m11)Matrix22(Matrix22 source)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidadd(AMatrix a)Adds another matrix to this matrix.voidadd(Matrix22 a)voidapplyOp(Op op)Applies a unary operator to all elements of the array (in-place)intcheckSquare()Checks if a matrix is square.Matrix22clone()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.intcolumnCount()Gets the number of columns in this matrix (dimension 1)voidcopyRowTo(int row, double[] dest, int destOffset)Copies the elements in a selected row of this matrix to a double arraystatic Matrix22create(double a, double b, double c, double d)static Matrix22createIdentity()Creates a new mutable 2D identity matrixstatic Matrix22createReflectionMatrix(AVector normal)static Matrix22createReflectionMatrix(Vector2 normal)static Matrix22createRotationMatrix(double angle)static Matrix22createScaleMatrix(double d)doubledeterminant()Calculates the determinant of the matrix.longelementCount()Returns the total number of elements in this array.doubleelementMax()Returns the maximum element value in this array.doubleelementMin()Returns the maximum element value in this array.doubleelementSum()Returns the sum of all elements in this matrixbooleanequals(Matrix22 m)booleanequals(java.lang.Object o)Matrix22exactClone()Creates a deep clone of an array, using the same class implementation as the original arraydoubleget(int row, int column)Returns the double value at the specified position in a 2D matrixVector2getColumnClone(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.voidgetElements(double[] data, int offset)Copies all elements of this array a double array at the specified offsetVector2getRowClone(int row)Returns a row of the matrix as a new cloned, mutable vector.Matrix22getTranspose()Returns the transpose of this array.AMatrixinnerProduct(AMatrix a)Computes the inner product of this matrix with another.AVectorinnerProduct(AVector a)Computes the inner product of this array with a vectorMatrix22innerProduct(Matrix22 a)Vector2innerProduct(Vector2 a)Matrix22inverse()Computes the inverse of a matrix.booleanisSymmetric()Returns true if a matrix is symmetricbooleanisZero()Returns true if the matrix is the zero matrix (all components zero)voidmultiply(double factor)Multiplies all elements of the array in place by a given double valueintrowCount()Gets the number of rows in this matrix (dimension 0)voidset(AMatrix m)Sets this matrix with the element values from another matrix.voidset(int row, int column, double value)Sets a value at a given position in a mutable 2D arrayvoidset(Matrix22 a)voidsub(Matrix22 a)double[]toDoubleArray()Copies the elements of this array to a new double[] array.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).Vector2transform(Vector2 source)voidtransform(Vector2 source, AVector dest)voidtransform(Vector2 source, Vector2 dest)voidtransformInPlace(Vector2 dest)voidunsafeSet(AMatrix m)-
Methods inherited from class mikera.matrixx.impl.APrimitiveMatrix
copy, getColumn, getRow, isFullyMutable, isSquare
-
Methods inherited from class mikera.matrixx.AMatrix
abs, add, add, add, add2, addAt, addCopy, addCopy, addCopy, addCopy, addCopy, addInnerProduct, addInnerProduct, addInnerProduct, addMultiple, addMultiple, addMultiple, addOuterProduct, addOuterProduct, addOuterProductSparse, addOuterProductSparse, addRowMultiple, addSparse, addSparse, addToArray, applyOp, applyOp, applyOp, applyOp, applyOp, applyOpCopy, asDoubleArray, asElementList, asVector, bandIndex, bandLength, bandPosition, bandStartColumn, bandStartRow, broadcast, broadcastCloneLike, broadcastCopyLike, broadcastLike, broadcastLike, checkColumn, checkRow, clamp, composeWith, copyColumnTo, dense, denseClone, diagonalProduct, dimensionality, divide, divide, divide, divide, divideCopy, elementIterator, elementsEqual, elementSquaredSum, ensureMutable, epsilonEquals, epsilonEquals, epsilonEquals, equals, equals, equalsArray, equalsTranspose, exp, fill, get, get, get, get, getBand, getBandWrapped, getColumns, getColumnView, getElement, getLeadingDiagonal, getLongShape, getRows, getRowView, getShape, getShape, getShapeClone, getSlices, getSlices, getSliceViews, getTransposeCopy, getTransposeView, hashCode, hasOrthonormalColumns, hasOrthonormalRows, hasUncountable, immutable, innerProduct, innerProduct, innerProduct, innerProduct, inputDimensions, isBoolean, isDiagonal, isElementConstrained, isHermitian, isIdentity, isInvertible, isLowerTriangular, isMutable, isOrthogonal, isOrthogonal, isPositiveDefinite, isRectangularDiagonal, isSameShape, isSameShape, isUpperTriangular, isView, iterator, join, log, lowerBandwidth, lowerBandwidthLimit, mul, multiply, multiply, multiply, multiplyCopy, multiplyRow, mutable, negate, nonZeroCount, outerProduct, outputDimensions, pow, rank, reciprocal, reduce, reduce, reduceSlices, reduceSlices, reorder, reorder, replaceColumn, replaceRow, reshape, reshape, rotateView, rowDotProduct, scaleAdd, scaleAdd, set, set, set, set, set, set, set, setApplyOp, setApplyOp, setColumn, setElements, setElements, setMultiple, setMultiple, setMultiple, setMultiple, setMultiple, setRow, setSparse, setSparse, signum, slice, slice, sliceCount, sparse, sparseClone, sqrt, square, sub, sub, sub, subArray, subCopy, subMatrix, swapColumns, swapRows, toAffineTransform, toDoubleBuffer, toMatrix, toMatrixTranspose, toMutableMatrix, toNestedDoubleArrays, toSliceArray, toString, toStringFull, transform, transformInPlace, transformInPlace, transposeInnerProduct, transposeInnerProduct, transposeInPlace, unsafeGet, unsafeSet, upperBandwidth, upperBandwidthLimit, validate
-
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, elementMaxAbs, 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.arrayz.INDArray
absCopy, absDiff, absDiffCopy, addApplyOp, addAt, addInnerProduct, addMultipleSparse, addPower, addPower, addSparse, broadcastLike, componentCount, divideCopy, elementAbsPowSum, elementMaxAbs, 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
-
-
-
-
Field Detail
-
m00
public double m00
-
m01
public double m01
-
m10
public double m10
-
m11
public double m11
-
-
Constructor Detail
-
Matrix22
public Matrix22()
-
Matrix22
public Matrix22(Matrix22 source)
-
Matrix22
public Matrix22(double m00, double m01, double m10, double m11)
-
Matrix22
public Matrix22(AMatrix m)
-
-
Method Detail
-
set
public void set(Matrix22 a)
-
set
public void set(AMatrix m)
Description copied from class:AMatrixSets this matrix with the element values from another matrix. Source matrix must have the same shape.
-
unsafeSet
public void unsafeSet(AMatrix m)
-
create
public static Matrix22 create(double a, double b, double c, double d)
-
createRotationMatrix
public static Matrix22 createRotationMatrix(double angle)
-
createScaleMatrix
public static Matrix22 createScaleMatrix(double d)
-
createIdentity
public static Matrix22 createIdentity()
Creates a new mutable 2D identity matrix- Returns:
-
multiply
public void multiply(double factor)
Description copied from interface:INDArrayMultiplies all elements of the array in place by a given double value
-
determinant
public double determinant()
Description copied from class:AMatrixCalculates the determinant of the matrix.- Overrides:
determinantin classAMatrix
-
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- Overrides:
elementCountin classAMatrix
-
elementSum
public double elementSum()
Description copied from class:AMatrixReturns the sum of all elements in this matrix- Specified by:
elementSumin interfaceINDArray- Overrides:
elementSumin classAMatrix
-
elementMin
public double elementMin()
Description copied from interface:INDArrayReturns the maximum element value in this array. Throws an error if there are no elements.- Specified by:
elementMinin interfaceINDArray- Overrides:
elementMinin classAbstractArray<AVector>
-
elementMax
public double elementMax()
Description copied from interface:INDArrayReturns the maximum element value in this array. Throws an error if there are no elements.- Specified by:
elementMaxin interfaceINDArray- Overrides:
elementMaxin classAbstractArray<AVector>
-
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
-
inverse
public Matrix22 inverse()
Description copied from class:AMatrixComputes the inverse of a matrix. Returns null if the matrix is singular. Throws an Exception is the matrix is not square
-
rowCount
public int rowCount()
Description copied from interface:IMatrixGets the number of rows in this matrix (dimension 0)
-
columnCount
public int columnCount()
Description copied from interface:IMatrixGets the number of columns in this matrix (dimension 1)- Specified by:
columnCountin interfaceIMatrix- Returns:
-
checkSquare
public int checkSquare()
Description copied from class:AMatrixChecks if a matrix is square. Returns the size if true, throws an exception otherwise;- Specified by:
checkSquarein classAPrimitiveMatrix- Returns:
-
add
public void add(AMatrix a)
Description copied from class:AMatrixAdds another matrix to this matrix. Matrices must be the same size.
-
add
public void add(Matrix22 a)
-
sub
public void sub(Matrix22 a)
-
applyOp
public void applyOp(Op op)
Description copied from interface:INDArrayApplies a unary operator to all elements of the array (in-place)
-
getRowClone
public Vector2 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- Overrides:
getRowClonein classAMatrix
-
getColumnClone
public Vector2 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- Overrides:
getColumnClonein classAMatrix
-
copyRowTo
public void copyRowTo(int row, double[] dest, int destOffset)Description copied from class:AMatrixCopies the elements in a selected row of this matrix to a double array
-
get
public double get(int row, int column)Description copied from interface:INDArrayReturns the double value at the specified position in a 2D matrix
-
set
public void set(int row, int column, double value)Description copied from interface:INDArraySets a value at a given position in a mutable 2D array
-
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- Overrides:
innerProductin classAMatrix- Returns:
-
innerProduct
public AVector innerProduct(AVector a)
Description copied from interface:INDArrayComputes the inner product of this array with a vector- Specified by:
innerProductin interfaceINDArray- Specified by:
innerProductin interfaceIMatrix- Overrides:
innerProductin classAMatrix- Parameters:
a- A vector- Returns:
- A new array representing the inner product
-
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(Vector2 dest)
-
isSymmetric
public boolean isSymmetric()
Description copied from class:AMatrixReturns true if a matrix is symmetric- Specified by:
isSymmetricin interfaceIMatrix- Overrides:
isSymmetricin classAMatrix- Returns:
-
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.
-
getTranspose
public Matrix22 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 classAMatrix- Returns:
- the transpose of this matrix
-
getElements
public void getElements(double[] data, 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 classAMatrix
-
equals
public boolean equals(Matrix22 m)
-
clone
public Matrix22 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.
-
exactClone
public Matrix22 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- Specified by:
exactClonein classAMatrix- Returns:
- A clone of the original array
-
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 classAMatrix
-
-
DMelt 3.0 © DataMelt by jWork.ORG