/** * Class representing an immutable real square matrix. * * @class Matrix * @memberof ran.la * @param {(number|Array|ran.la.Matrix)=} arg The constructor argument. If it is a number, it sets the * linear dimension of the matrix. If it is an array of arrays, the matrix is initialized with the array * elements. If it is another matrix, it is copied to this matrix. If not specified, a 3x3 identity matrix is * created. * @constructor * @ignore * @example * * let M1 = new ran.la.Matrix() * let M2 = new ran.la.Matrix(3) * let M3 = new ran.la.Matrix([[1, 0, 0], [0, 1, 0], [0, 0, 1]]) * let M4 = new ran.la.Matrix(M1) * // ┌ ┐ * // │ 1 0 0 │ * // => │ 0 1 0 │ * // │ 0 0 1 │ * // └ ┘ * */ declare class Matrix { _m: any; constructor(arg: any); /** * Returns the matrix as an array of arrays. * * @method m * @memberof ran.la.Matrix * @returns {Array[]} The matrix in an array of array representation. * @example * * let M = new ran.la.Matrix() * M.m() * // => [ [ 1, 0, 0 ], * // [ 0, 1, 0 ], * // [ 0, 0, 1 ] ] * */ m(): any[][]; /** * Returns or sets an element of the matrix. * * @method ij * @memberof ran.la.Matrix * @param {number} i Row index of the element. * @param {number} j Column index of the element. * @param {number=} value The new value of the element at the i-th row and j-th column. If not specified, * the value at (i, j) is returned. * @example * * let M = new ran.la.Matrix() * * M.ij(1, 1) * // => 1 * * M.ij(1, 2) * // => 0 * * M.ij(1, 2, 5) * // ┌ ┐ * // │ 1 0 0 │ * // => │ 0 1 0 │ * // │ 0 5 1 │ * // └ ┘ * */ ij(i: number, j: number, value?: number | undefined): any; /** * Performs an operation on the matrix element-wise. * * @method f * @memberof ran.la.Matrix * @param {Function} func Function to apply on each element. May take three parameters: the element's value and its * row and column indices. * @returns {ran.la.Matrix} The transformed matrix. * @example * * let M = new ran.la.Matrix([[1, 2], [3, 4]]) * M.f(d => d * d) * // ┌ ┐ * // => │ 1 4 │ * // │ 9 16 │ * // └ ┘ * */ f(func: Function): ran.la.Matrix; /** * Multiplies the matrix with a scalar. * * @method scale * @memberof ran.la.Matrix * @param {number} s The scalar to multiply matrix with. * @returns {ran.la.Matrix} The scaled matrix. * @example * * let M = new ran.la.Matrix([[1, 2], [3, 4]]) * M.scale(2) * // ┌ ┐ * // => │ 2 4 │ * // │ 6 8 │ * // └ ┘ * */ scale(s: number): ran.la.Matrix; /** * Adds another matrix to the current matrix. * * @method add * @memberof ran.la.Matrix * @param {ran.la.Matrix} mat The matrix to add. * @throws {Error} If the matrix dimensions do not match. * @returns {ran.la.Matrix} The sum of the two matrices. * @example * * let M = new ran.la.Matrix([[1, 2], [3, 4]]) * let N = new ran.la.Matrix([[5, 6], [7, 8]]) * M.add(N) * // ┌ ┐ * // => │ 6 8 │ * // │ 10 12 │ * // └ ┘ * */ add(mat: ran.la.Matrix): ran.la.Matrix; /** * Subtracts another matrix from the current matrix. * * @method sub * @memberof ran.la.Matrix * @param {ran.la.Matrix} mat The matrix to subtract. * @throws {Error} If the matrix dimensions do not match. * @returns {ran.la.Matrix} The difference of the two matrices. * @example * * let M = new ran.la.Matrix([[5, 6], [7, 8]]) * let N = new ran.la.Matrix([[1, 1], [1, 1]]) * M.add(N) * // ┌ ┐ * // => │ 4 5 │ * // │ 6 7 │ * // └ ┘ * */ sub(mat: ran.la.Matrix): ran.la.Matrix; /** * Multiplies the matrix with another matrix (from the right). * * @method mult * @memberof ran.la.Matrix * @param {Matrix} mat Matrix to multiply current matrix with. * @throws {Error} If the matrix dimensions do not match. * @returns {Matrix} The product matrix. * @example * * let M = new ran.la.Matrix([[1, 2], [3, 4]]) * let N = new ran.la.Matrix([[5, 6], [7, 8]]) * M.mult(N) * // ┌ ┐ * // => │ 19 22 │ * // │ 43 50 │ * // └ ┘ * */ mult(mat: Matrix): Matrix; /** * Returns the transpose of the matrix. * * @method t * @memberof ran.la.Matrix * @returns {ran.la.Matrix} The transposed matrix. * @example * * let M = new ran.la.Matrix([[1, 2], [3, 4]]) * M.t() * // ┌ ┐ * // => │ 1 3 │ * // │ 2 4 │ * // └ ┘ * */ t(): ran.la.Matrix; /** * Multiplies a vector with the matrix (applies this matrix on a vector). * * @method apply * @memberof ran.la.Matrix * @param {ran.la.Vector} vec Vector to apply matrix on. * @throws {Error} If the vector dimension does not match the matrix row count. * @returns {ran.la.Vector} The mapped vector. * @example * * let M = new ran.la.Matrix([[1, 2], [3, 4]]) * let v = new ran.la.Vector([5, 6]) * M.apply(v) * // => ( 17, 39 ) * */ apply(vec: ran.la.Vector): ran.la.Vector; /** * Performs the [LDL decomposition]{@link https://en.wikipedia.org/wiki/Cholesky_decomposition} of the * matrix. * * @method ldl * @memberof ran.la.Matrix * @returns {Object} Object containing two properties: {D} and {L} representing the corresponding matrices * in the LDL decomposition. * @example * * let M = new Matrix([[4, 12, -16], [12, 37, -43], [-16, -43, 98]]) * M.ldl() * // ┌ ┐ ┌ ┐ * // │ 1 0 0 │ │ 4 0 0 │ * // => L = │ 3 1 0 │, D = │ 0 1 0 │ * // │ -4 5 1 │ │ 0 0 9 │ * // └ ┘ └ ┘ * */ ldl(): any; /** * Returns an array representing the row sums of the matrix. * * @method rowSum * @memberof ran.la.Matrix * @return {number[]} Array containing the row sums. */ rowSum(): number[]; /** * Returns the Hadamard (element-wise) product of the matrix with another matrix * * @method hadamard * @memberof ran.la.Matrix * @param {ran.la.Matrix} mat Matrix to calculate element-wise product with. * @throws {Error} If the matrix dimensions do not match. * @return {ran.la.Matrix} The result matrix. */ hadamard(mat: ran.la.Matrix): ran.la.Matrix; /** * Returns the trace of the matrix. * * @method trace * @memberof ran.la.Matrix * @return {number} The trace of the matrix. */ trace(): number; } export default Matrix;