(abs m)(abs! m)(acos m)(acos! m)(add a)(add a b)(add a b & more)Performs element-wise addition on one or more numerical arrays.
Performs element-wise addition on one or more numerical arrays.
(add! a)(add! a b)(add! a b & more)Performs element-wise mutable addition on one or more numerical arrays. Returns the first array after it has been mutated.
Performs element-wise mutable addition on one or more numerical arrays. Returns the first array after it has been mutated.
(add-product m a b)Adds the element-wise product of two numerical ararys to the first array. Arrays must be the same shape.
Adds the element-wise product of two numerical ararys to the first array. Arrays must be the same shape.
(add-product! m a b)Adds the product of two numerical arrays to the first array. Returns the mutated array.
Adds the product of two numerical arrays to the first array. Returns the mutated array.
(add-row m i j)(add-row m i j factor)Add a row j (optionally multiplied by a scalar factor) to a row i and replace row i with the result
Add a row j (optionally multiplied by a scalar factor) to a row i and replace row i with the result
(add-scaled m a factor)Adds a numerical array scaled by a given factor to the first array
Adds a numerical array scaled by a given factor to the first array
(add-scaled! m a factor)Adds a numerical array scaled by a given factor to the first array. Returns the mutated array.
Adds a numerical array scaled by a given factor to the first array. Returns the mutated array.
(add-scaled-product m a b factor)Adds the product of two numerical arrays scaled by a given factor to the first array
Adds the product of two numerical arrays scaled by a given factor to the first array
(add-scaled-product! m a b factor)Adds the product of two numerical arrays scaled by a given factor to the first array. Returns the mutated array.
Adds the product of two numerical arrays scaled by a given factor to the first array. Returns the mutated array.
(array data)(array implementation data)Constructs a new n-dimensional array from the given data.
The data may be in one of the following forms:
If implementation is not specified, uses the current matrix library as specified in matrix-implementation
If the implementation does not support the shape of data provided, will attempt to create an array using a different implemntation on a best-efforts basis.
Constructs a new n-dimensional array from the given data. The data may be in one of the following forms: - A valid existing array - Nested sequences of scalar values, e.g. Clojure vectors (must have regular shape) - A sequence of slices, each of which must be valid matrix data If implementation is not specified, uses the current matrix library as specified in *matrix-implementation* If the implementation does not support the shape of data provided, will attempt to create an array using a different implemntation on a best-efforts basis.
(array? m)Returns true if the parameter is an N-dimensional array, for any N>=0
Returns true if the parameter is an N-dimensional array, for any N>=0
(as-vector m)Creates a view of an array as a single flattened vector. Returns nil if this is not supported by the implementation.
Creates a view of an array as a single flattened vector. Returns nil if this is not supported by the implementation.
(asin m)(asin! m)(assign m a)Assigns array a elementwise, broadcasting to fill the whole shape of m. Returns a new matrix, of the same shape as the original m.
Assigns array a elementwise, broadcasting to fill the whole shape of m. Returns a new matrix, of the same shape as the original m.
(assign! m a)Assigns a new value to an array. Sets the values of the target elementwise, broadcasting where necessary. Returns the mutated array. The new value may be either a scalar or a array of compatible (maybe smaller) shape.
Assigns a new value to an array. Sets the values of the target elementwise, broadcasting where necessary. Returns the mutated array. The new value may be either a scalar or a array of compatible (maybe smaller) shape.
(assign-array! m a)Assigns values to a core.matrix array from a Java array. Returns the mutated core.matrix array
Assigns values to a core.matrix array from a Java array. Returns the mutated core.matrix array
(atan m)(atan! m)(broadcast m shape)Broadcasts a matrix to a specified shape. Returns a new matrix with the shape specified. The broadcasted matrix may be a view over the original matrix: attempting to modify the broadcasted matrix therefore has undefined results. Will throw an excption if broadcast to the target shape is not possible.
Broadcasts a matrix to a specified shape. Returns a new matrix with the shape specified. The broadcasted matrix may be a view over the original matrix: attempting to modify the broadcasted matrix therefore has undefined results. Will throw an excption if broadcast to the target shape is not possible.
(broadcast-coerce m a)Broadcasts and coerces the second matrix to the shape and type of the first. Equivalent to (coerce m (broadcast-like m a)).
Broadcasts and coerces the second matrix to the shape and type of the first. Equivalent to (coerce m (broadcast-like m a)).
(broadcast-like m a)Broadcasts the second matrix to the shape of the first. See 'broadcast'.
Broadcasts the second matrix to the shape of the first. See 'broadcast'.
(cbrt m)(cbrt! m)(ceil m)(ceil! m)(cholesky-decomposition m)Computes the Cholesky decomposition of a matrix. Returns a vector containing two matrices [L L*]
Intended usage: (let [[L L*] (cholesky-decomosition M)] ....)
Computes the Cholesky decomposition of a matrix. Returns a vector containing two matrices [L L*] Intended usage: (let [[L L*] (cholesky-decomosition M)] ....)
(clone m)Constructs a (shallow) clone of the array. This function is intended to allow safe defensive usage of matrices / vectors. If the intent is to create a mutable clone of some array data, it is recommended to use mutable instead.
Guarantees that:
The clone may or may not be of the same implementation: implementations are encouraged to do so but this is not mandatory.
A core.matrix implementation which only provides immutable arrays may safely return the same array.
Constructs a (shallow) clone of the array. This function is intended to allow safe defensive usage of matrices / vectors. If the intent is to create a mutable clone of some array data, it is recommended to use mutable instead. Guarantees that: 1. Mutating the returned array will not modify any other array (defensive copy) 2. The returned array will be fully mutable, if the implementation supports mutable matrices. The clone may or may not be of the same implementation: implementations are encouraged to do so but this is not mandatory. A core.matrix implementation which only provides immutable arrays may safely return the same array.
(coerce matrix-or-implementation param)Coerces param into a format preferred by a specific matrix implementation. If param is already in a format deemed usable by the implementation, returns it unchanged.
Coerces param into a format preferred by a specific matrix implementation. If param is already in a format deemed usable by the implementation, returns it unchanged.
(column-count m)Returns the number of columns in a matrix (array must be 2D or more)
Returns the number of columns in a matrix (array must be 2D or more)
(column-matrix data)(column-matrix implementation data)Constucts a column matrix with the given data. The returned matrix is a 2D Nx1 column matrix.
The data must be either a valid existing vector or a sequence of scalar values.
Constucts a column matrix with the given data. The returned matrix is a 2D Nx1 column matrix. The data must be either a valid existing vector or a sequence of scalar values.
(column-matrix? m)Returns true if a matrix is a column-matrix (i.e. is 2D and has has exactly one column)
Returns true if a matrix is a column-matrix (i.e. is 2D and has has exactly one column)
(columns m)Gets the columns of an array, as a sequence of vectors.
If the array has more than 2 dimensions, will return the columns from all slices in order.
Gets the columns of an array, as a sequence of vectors. If the array has more than 2 dimensions, will return the columns from all slices in order.
(compute-matrix shape f)(compute-matrix implementation shape f)Creates a matrix with the specified shape, and each element specified by (f i j k...) Where i, j, k... are the index positions of each element in the matrix
Creates a matrix with the specified shape, and each element specified by (f i j k...) Where i, j, k... are the index positions of each element in the matrix
(conforming? a)(conforming? a b)Returns true if two arrays have a conforming shape. Two arrays are conforming if there exists a common shape that both can broadcast to. This is a requirement for element-wise operations to work correctly on two different-shaped arrays.
Returns true if two arrays have a conforming shape. Two arrays are conforming if there exists a common shape that both can broadcast to. This is a requirement for element-wise operations to work correctly on two different-shaped arrays.
(cos m)(cos! m)(cosh m)(cosh! m)(cross a b)Computes the cross-product of two numerical 3D vectors
Computes the cross-product of two numerical 3D vectors
(cross! a b)Computes the cross-product of two numerical 3D vectors, storing the result in the first vector. Returns the (mutated) first vector.
Computes the cross-product of two numerical 3D vectors, storing the result in the first vector. Returns the (mutated) first vector.
(current-implementation)Gets the currently active matrix implementation (as a keyword)
Gets the currently active matrix implementation (as a keyword)
(current-implementation-object)Gets the a canonical object for the currently active matrix implementation. This object can be used to pass as an implementation parameter, or to query implementation internals.
Gets the a canonical object for the currently active matrix implementation. This object can be used to pass as an implementation parameter, or to query implementation internals.
(density m)Returns the density of the matrix, defined as the proportion on non-zero elements
Returns the density of the matrix, defined as the proportion on non-zero elements
(det a)Calculates the determinant of a 2D numerical matrix.
Throws an exception if the matrix is not square.
Calculates the determinant of a 2D numerical matrix. Throws an exception if the matrix is not square.
(diagonal m)(diagonal m k)Returns the specified diagonal of a 2D matrix as a vector. If k>0, returns a diagonal above the main diagonal. If k<0, returns a diagonal below the main diagonal. Works on both square and rectangular matrices.
Returns the specified diagonal of a 2D matrix as a vector. If k>0, returns a diagonal above the main diagonal. If k<0, returns a diagonal below the main diagonal. Works on both square and rectangular matrices.
(diagonal-matrix diagonal-values)(diagonal-matrix implementation diagonal-values)Constructs a 2D diagonal matrix with the given numerical values on the main diagonal. All off-diagonal elements will be zero. diagonal-values may be a vector or any Clojure sequence of values.
Diagonal matrices constructed this way may use specialised storage formats, hence may not be fully mutable. Use (mutable (diagonal-matrix ...)) if you need to guarantee a mutable matrix.
Constructs a 2D diagonal matrix with the given numerical values on the main diagonal. All off-diagonal elements will be zero. diagonal-values may be a vector or any Clojure sequence of values. Diagonal matrices constructed this way may use specialised storage formats, hence may not be fully mutable. Use (mutable (diagonal-matrix ...)) if you need to guarantee a mutable matrix.
(dimension-count m dim)Returns the size of the specified dimension in a matrix. Will throw an error if the matrix does not have the specified dimension.
Returns the size of the specified dimension in a matrix. Will throw an error if the matrix does not have the specified dimension.
(dimensionality m)Returns the dimensionality of an array. The dimensionality is equal to the number of dimensions in the array's shape.
Returns the dimensionality of an array. The dimensionality is equal to the number of dimensions in the array's shape.
(distance a b)Calculates the euclidean distance between two numerical vectors.
Calculates the euclidean distance between two numerical vectors.
(div a)(div a b)(div a b & more)Performs element-wise matrix division for numerical arrays.
Performs element-wise matrix division for numerical arrays.
(div! a)(div! a b)(div! a b & more)Performs in-place element-wise matrix division for numerical arrays.
Performs in-place element-wise matrix division for numerical arrays.
(dot a b)Computes the dot product (1Dx1D inner product) of two numerical vectors.
If either argument is not a vector, computes a higher dimensional inner product.
Computes the dot product (1Dx1D inner product) of two numerical vectors. If either argument is not a vector, computes a higher dimensional inner product.
(e*)(e* a)(e* a b)(e* a b & more)Element-wise multiply operator. Equivalent to emul.
Element-wise multiply operator. Equivalent to emul.
(e= m1)(e= m1 m2)(e= m1 m2 & more)Returns true if all array elements are equal (using the semantics of clojure.core/=). WARNING: a java.lang.Long does not equal a java.lang.Double. Use 'equals' or 'e==' instead if you want numerical equality.
Returns true if all array elements are equal (using the semantics of clojure.core/=). WARNING: a java.lang.Long does not equal a java.lang.Double. Use 'equals' or 'e==' instead if you want numerical equality.
(e== m1)(e== m1 m2)(e== m1 m2 & more)Returns true if all array elements are numerically equal. Throws an error if any elements of the arrays being compared are not numerical values.
Returns true if all array elements are numerically equal. Throws an error if any elements of the arrays being compared are not numerical values.
(ecount m)Returns the total count of elements in an array.
Equal to the product of the lenegths of each dimension in the array's shape.
Returns 1 for a zero-dimensional array or scalar.
Returns the total count of elements in an array. Equal to the product of the lenegths of each dimension in the array's shape. Returns 1 for a zero-dimensional array or scalar.
(eigen-decomposition m)Computes the Eigendecomposition of a diagonalisable matrix. Returns a vector containing three matrices [Q A Qinv]
A is a diagonal matrix whose diagonal elements are the eigenvalues.
Intended usage: (let [[Q A Qinv] (eigen-decomosition M)] ....)
Computes the Eigendecomposition of a diagonalisable matrix. Returns a vector containing three matrices [Q A Qinv] A is a diagonal matrix whose diagonal elements are the eigenvalues. Intended usage: (let [[Q A Qinv] (eigen-decomosition M)] ....)
(element-type m)Returns the class of elements that can be in the array. For example, a numerical array may return the class java.lang.Double.
Returns the class of elements that can be in the array. For example, a numerical array may return the class java.lang.Double.
(emap f m)(emap f m a)(emap f m a & more)Element-wise map over all elements of one or more arrays.
f must return a result compatible with the element-type of the array m
Returns a new array of the same element-type and shape as the array m.
Element-wise map over all elements of one or more arrays. f must return a result compatible with the element-type of the array m Returns a new array of the same element-type and shape as the array m.
(emap! f m)(emap! f m a)(emap! f m a & more)Element-wise map of a function f over all elements of one or more arrays.
f must return a result compatible with the element-type of the array m
Performs in-place modification of the first array argument.
Element-wise map of a function f over all elements of one or more arrays. f must return a result compatible with the element-type of the array m Performs in-place modification of the first array argument.
(emax m)Gets the maximum element value from a numerical array
Gets the maximum element value from a numerical array
(emin m)Gets the minimum element value from a numerical array
Gets the minimum element value from a numerical array
(emul)(emul a)(emul a b)(emul a b & more)Performs element-wise multiplication.
Performs element-wise multiplication.
(emul! a)(emul! a b)(emul! a b & more)Performs in-place element-wise multiplication of numerical arrays.
Performs in-place element-wise multiplication of numerical arrays.
(ensure-mutable m)Checks if an array is mutable, and if not converts to a new mutable array. Guarantees that the result will be mutable, but may not be the same type as the original array.
Checks if an array is mutable, and if not converts to a new mutable array. Guarantees that the result will be mutable, but may not be the same type as the original array.
(equals a b)(equals a b epsilon)Returns true if two arrays are numerically equal.
Will return false for arrays of different shapes.
May either return false or throw an error if the arrays are not numerical.
If epsilon is provided, performs an equality test with the given maximum tolerance (default is 0.0, i.e. exact numerical equivalence)
Returns true if two arrays are numerically equal. Will return false for arrays of different shapes. May either return false or throw an error if the arrays are not numerical. If epsilon is provided, performs an equality test with the given maximum tolerance (default is 0.0, i.e. exact numerical equivalence)
(ereduce f m)(ereduce f init m)Element-wise reduce on all elements of an array.
Element-wise reduce on all elements of an array.
(eseq m)Returns all elements of an array as a sequence in row-major order
Returns all elements of an array as a sequence in row-major order
(esum m)Calculates the sum of all the elements in a numerical array.
Calculates the sum of all the elements in a numerical array.
(exp m)(exp! m)(fill m value)Fills a matrix with a single scalar value. The scalar value must be compatible with the element-type of the array. Returns a new array.
Fills a matrix with a single scalar value. The scalar value must be compatible with the element-type of the array. Returns a new array.
(fill! m value)Fills a matrix with a single scalar value. The scalar value must be compatible with the element-type of the array.
Equivalent to assign!, but may be more efficient for scalar values.
Fills a matrix with a single scalar value. The scalar value must be compatible with the element-type of the array. Equivalent to assign!, but may be more efficient for scalar values.
(floor m)(floor! m)(get-column m y)Gets a column of a matrix, as a vector. Will return a mutable view if supported by the implementation.
Gets a column of a matrix, as a vector. Will return a mutable view if supported by the implementation.
(get-row m x)Gets a row of a matrix, as a vector. Will return a mutable view if supported by the implementation.
Gets a row of a matrix, as a vector. Will return a mutable view if supported by the implementation.
(identity-matrix dims)(identity-matrix implementation dims)Constructs a 2D identity matrix with the given number of rows.
Identity matrices constructed with this function may not be fully mutable because they may be implemented with a specialised identity matrix type. Use (mutable (identity-matrix ...)) if you need to guarantee a mutable matrix.
Constructs a 2D identity matrix with the given number of rows. Identity matrices constructed with this function may not be fully mutable because they may be implemented with a specialised identity matrix type. Use (mutable (identity-matrix ...)) if you need to guarantee a mutable matrix.
(identity-matrix? m)Returns true if the parameter is an identity-matrix
Returns true if the parameter is an identity-matrix
(immutable data)(immutable data type)Constructs an immutable copy of the given array data.
If the implementation does not support immutable matrices, will return an immutable array from another core.matrix implementation that supports either the same element type or a broader type.
Constructs an immutable copy of the given array data. If the implementation does not support immutable matrices, will return an immutable array from another core.matrix implementation that supports either the same element type or a broader type.
(index-seq m)(index-seq-for-shape sh)(inner-product)(inner-product a)(inner-product a b)(inner-product a b & more)Computes the inner product of numerical arrays.
The inner product of two arrays with indexed dimensions {..i j} and {j k..} has dimensions {..i k..}. The inner-product of two vectors will be scalar.
Computes the inner product of numerical arrays.
The inner product of two arrays with indexed dimensions {..i j} and {j k..} has dimensions {..i k..}. The inner-product of two vectors will be scalar.(inverse m)Calculates the inverse of a 2D numerical matrix.
Calculates the inverse of a 2D numerical matrix.
(join & arrays)Joins arrays together, along dimension 0. Other dimensions must be compatible
Joins arrays together, along dimension 0. Other dimensions must be compatible
(join-along dimension & arrays)Joins arrays together, along a specified dimension. Other dimensions must be compatible.
Joins arrays together, along a specified dimension. Other dimensions must be compatible.
(length m)Calculates the euclidean length (magnitude) of a numerical vector
Calculates the euclidean length (magnitude) of a numerical vector
(length-squared m)Calculates the squared length (squared magnitude) of a numerical vector
Calculates the squared length (squared magnitude) of a numerical vector
(log m)(log! m)(log10 m)(log10! m)(loop-symmetric? m)FOR TESTING ONLY. Returns true if the parameter is a symmetric matrix
FOR TESTING ONLY. Returns true if the parameter is a symmetric matrix
(lu-decomposition m)Computes the LU decompotion of a matrix. Returns a vector containing two matrices [L U]
Intended usage: (let [[L U] (lu-decomosition M)] ....)
Computes the LU decompotion of a matrix. Returns a vector containing two matrices [L U] Intended usage: (let [[L U] (lu-decomosition M)] ....)
(main-diagonal m)Returns the main diagonal of a matrix or general array, as a vector. The main diagonal of a general array is defined as those elements where the all the indexes are equal, i.e. the index is of the form [i i ... i] Works on both square and rectangular matrices.
Returns the main diagonal of a matrix or general array, as a vector. The main diagonal of a general array is defined as those elements where the all the indexes are equal, i.e. the index is of the form [i i ... i] Works on both square and rectangular matrices.
(matrix data)(matrix implementation data)Constructs a matrix from the given numerical data.
The data may be in one of the following forms:
If implementation is not specified, uses the current matrix library as specified in matrix-implementation
Constructs a matrix from the given numerical data. The data may be in one of the following forms: - A valid existing matrix - Nested sequences of scalar values, e.g. Clojure vectors - A sequence of slices, each of which must be valid matrix data If implementation is not specified, uses the current matrix library as specified in *matrix-implementation*
(matrix? m)Returns true if parameter is a valid matrix (dimensionality == 2)
Returns true if parameter is a valid matrix (dimensionality == 2)
(mget m)(mget m x)(mget m x y)(mget m x y & more)Gets a scalar value from an array at the specified position. Supports any number of dimensions.
Gets a scalar value from an array at the specified position. Supports any number of dimensions.
(mmul)(mmul a)(mmul a b)(mmul a b & more)Performs matrix multiplication (equivalent to inner-product).
Performs matrix multiplication (equivalent to inner-product).
(mset m v)(mset m x v)(mset m x y v)(mset m x y z & more)Sets a scalar value in an array at the specified position, returning a new matrix and leaving the original unchanged.
Sets a scalar value in an array at the specified position, returning a new matrix and leaving the original unchanged.
(mset! m v)(mset! m x v)(mset! m x y v)(mset! m x y z & more)Sets a scalar value in an array at the specified position. Supports any number of dimensions.
Will throw an exception if the matrix is not mutable at the specified position. Note that it is possible for some arrays to be mutable in places and immutable in others (e.g. sparse arrays)
Returns the modified matrix (it is guaranteed to return the same instance)
Sets a scalar value in an array at the specified position. Supports any number of dimensions. Will throw an exception if the matrix is not mutable at the specified position. Note that it is possible for some arrays to be mutable in places and immutable in others (e.g. sparse arrays) Returns the modified matrix (it is guaranteed to return the same instance)
(mul)(mul a)(mul a b)(mul a b & more)Performs element-wise multiplication with numerical arrays.
Performs element-wise multiplication with numerical arrays.
(mul! a)(mul! a b)(mul! a b & more)Performs in-place element-wise multiplication of numerical arrays.
Performs in-place element-wise multiplication of numerical arrays.
(multiply-row m i factor)Multiply row i by a constant factor
Multiply row i by a constant factor
(mutable data)(mutable data type)Constructs a mutable copy of the given array data.
If the implementation does not support mutable matrices, will return a mutable array from another core.matrix implementation that supports either the same element type or a broader type.
Constructs a mutable copy of the given array data. If the implementation does not support mutable matrices, will return a mutable array from another core.matrix implementation that supports either the same element type or a broader type.
(mutable-matrix data)(mutable-matrix data type)Constructs a mutable copy of the given matrix.
DEPRECATED: please use mutable instead
Constructs a mutable copy of the given matrix. DEPRECATED: please use mutable instead
(mutable? m)Returns true if the matrix is mutable, i.e. supports setting of values.
Returns true if the matrix is mutable, i.e. supports setting of values.
(negate m)Calculates the negation of a numerical array. Should normally be equivalent to scaling by -1.0
Calculates the negation of a numerical array. Should normally be equivalent to scaling by -1.0
(negate! m)Calculates the negation of a numerical array in place. Equivalent to scaling by -1.0
Calculates the negation of a numerical array in place. Equivalent to scaling by -1.0
(new-array shape)(new-array implementation shape)Creates a new array with the given shape. New array will contain default values as defined by the implementation (usually null or zero). If the implementation supports mutable matrices, then the new matrix will be fully mutable.
Creates a new array with the given shape. New array will contain default values as defined by the implementation (usually null or zero). If the implementation supports mutable matrices, then the new matrix will be fully mutable.
(new-matrix rows columns)(new-matrix implementation rows columns)Constructs a new 2D array (matrix) with the given dimensions. The new matrix will contain default values as defined by the implementation (usually null or zero). If the implementation supports mutable matrices, then the new matrix will be fully mutable.
Constructs a new 2D array (matrix) with the given dimensions. The new matrix will contain default values as defined by the implementation (usually null or zero). If the implementation supports mutable matrices, then the new matrix will be fully mutable.
(new-scalar-array)(new-scalar-array implementation)Returns a new mutable scalar array containing the scalar value zero.
Returns a new mutable scalar array containing the scalar value zero.
(new-vector length)(new-vector implementation length)Constructs a new vector with the given length. New matrix will contain default values as defined by the implementation (usually null or zero). If the implementation supports mutable vectors, then the new vector will be fully mutable.
Constructs a new vector with the given length. New matrix will contain default values as defined by the implementation (usually null or zero). If the implementation supports mutable vectors, then the new vector will be fully mutable.
(normalise v)Normalises a numerical vector (scales to unit length). Returns a new normalised vector.
Normalises a numerical vector (scales to unit length). Returns a new normalised vector.
(normalise! v)Normalises a numerical vector in-place (scales to unit length). Returns the modified vector.
Normalises a numerical vector in-place (scales to unit length). Returns the modified vector.
(numerical? m)Returns true if the matrix is a valid numerical matrix (i.e. supports numerical core.matrix operations).
Returns true if the matrix is a valid numerical matrix (i.e. supports numerical core.matrix operations).
(outer-product)(outer-product a)(outer-product a b)(outer-product a b & more)Computes the outer product of numerical arrays.
Computes the outer product of numerical arrays.
(pack a)Packs array data in the most efficient format as defined by the implementation. May return the same array if no additional packing is required.
Packs array data in the most efficient format as defined by the implementation. May return the same array if no additional packing is required.
(permutation-matrix permutation)(permutation-matrix implementation permutation)Constructs a permutation matrix for a given permutation vector. The permutation vector should contain a distinct set of intergers 0...n-1, representing the re-ordering performed by the permutation matrix.
Constructs a permutation matrix for a given permutation vector. The permutation vector should contain a distinct set of intergers 0...n-1, representing the re-ordering performed by the permutation matrix.
(pow m)(pow m exponent)(pow m exponent & more)Raises every element of a numerical matrix by the given exponent.
Note that behaviour for large exponents may depend on the underlying implementation: for example double-based matrices may overflow to Double/POSITIVE_INFINITY.
Raises every element of a numerical matrix by the given exponent. Note that behaviour for large exponents may depend on the underlying implementation: for example double-based matrices may overflow to Double/POSITIVE_INFINITY.
(pow! m a)Mutable exponent function, see 'pow'
Mutable exponent function, see 'pow'
(qr-decomposition m)Computes the QR decomposition of a matrix. Returns a vector containing two matrices [Q R]
Intended usage: (let [[Q R] (qr-decomosition M)] ....)
Computes the QR decomposition of a matrix. Returns a vector containing two matrices [Q R] Intended usage: (let [[Q R] (qr-decomosition M)] ....)
(rank m)Computes the rank of a matrix, i.e. the number of linearly independent rows
Computes the rank of a matrix, i.e. the number of linearly independent rows
(reshape m shape)Changes the shape of a matrix to the specified new shape. shape can be any sequence of dimension sizes. Preserves the row-major order of matrix elements.
Changes the shape of a matrix to the specified new shape. shape can be any sequence of dimension sizes. Preserves the row-major order of matrix elements.
(rotate m shifts)(rotate m dimension shift-amount)Rotates an array along specified dimensions.
Rotates an array along specified dimensions.
(round m)(round! m)(row-count m)Returns the number of rows in a matrix or vector (array must be 1D or more)
Returns the number of rows in a matrix or vector (array must be 1D or more)
(row-matrix data)(row-matrix implementation data)Constucts a row matrix with the given data. The returned matrix is a 2D 1xN row matrix.
The data must be either a valid existing vector or a sequence of scalar values.
Constucts a row matrix with the given data. The returned matrix is a 2D 1xN row matrix. The data must be either a valid existing vector or a sequence of scalar values.
(row-matrix? m)Returns true if a matrix is a row-matrix (i.e. is 2D and has exactly one row)
Returns true if a matrix is a row-matrix (i.e. is 2D and has exactly one row)
(rows m)Gets the rows of an array, as a sequence of vectors.
If the array has more than 2 dimensions, will return the rows from all slices in order.
Gets the rows of an array, as a sequence of vectors. If the array has more than 2 dimensions, will return the rows from all slices in order.
(same-shape?)(same-shape? m)(same-shape? m n)(same-shape? m n & more)Returns true if the arrays have the same shape, false otherwise
Returns true if the arrays have the same shape, false otherwise
(scalar m)Coerces m to a scalar value. Result is guaranteed not to be an array. Will throw an exception if m is not zero-dimensional.
Coerces m to a scalar value. Result is guaranteed not to be an array. Will throw an exception if m is not zero-dimensional.
(scalar-array value)(scalar-array implementation value)Creates a new zero-dimensional array containing the specified scalar value.
Creates a new zero-dimensional array containing the specified scalar value.
(scalar? v)Returns true if the parameter is a scalar value (i.e. acceptable as matrix element value). A 0-d array containing a scalar is not itself a scalar value.
Returns true if the parameter is a scalar value (i.e. acceptable as matrix element value). A 0-d array containing a scalar is *not* itself a scalar value.
(scale m factor)(scale m factor & more-factors)Scales a numerical array by one or more scalar factors. Returns a new scaled matrix.
Scales a numerical array by one or more scalar factors. Returns a new scaled matrix.
(scale! m factor)(scale! m factor & more-factors)Scales a numerical array by one or more scalar factors (in place). Returns the matrix after it has been mutated.
Scales a numerical array by one or more scalar factors (in place). Returns the matrix after it has been mutated.
(set-current-implementation m)Sets the currently active core.matrix implementation.
This is used primarily for functions that construct new matrices, i.e. it determines the implementation used for expressions like: (matrix [[1 2] [3 4]])
Sets the currently active core.matrix implementation. This is used primarily for functions that construct new matrices, i.e. it determines the implementation used for expressions like: (matrix [[1 2] [3 4]])
(set-row m i row)Sets a row in a matrix using a specified vector.
Sets a row in a matrix using a specified vector.
(set-row! m i row)Sets a row in a matrix using a specified vector.
Sets a row in a matrix using a specified vector.
(shape m)Returns the shape of an array, i.e. the dimension sizes for all dimensions.
The result will be a vector containing only integer index values, with a count equal to the dimensionality of the array.
Returns nil the if object is not an array (i.e. is a scalar value)
Returns the shape of an array, i.e. the dimension sizes for all dimensions. The result will be a vector containing only integer index values, with a count equal to the dimensionality of the array. Returns nil the if object is not an array (i.e. is a scalar value)
(signum m)(signum! m)(sin m)(sin! m)(sinh m)(sinh! m)(slice m index)(slice m dimension index)Gets a slice of an array along a specific dimension. The returned array will have one less dimension.
Slicing a 1D vector will return a scalar.
Slicing on the first dimension (dimension 0) is likely to perform better for many array implementations, and is therefore the default if no dimension is specified.
Gets a slice of an array along a specific dimension. The returned array will have one less dimension. Slicing a 1D vector will return a scalar. Slicing on the first dimension (dimension 0) is likely to perform better for many array implementations, and is therefore the default if no dimension is specified.
(slice-count m)Returns the number of slices in an array (array must be 1D or more). The array is sliced in row-major order, i.e. this is the dimension count of the first dimension.
Returns the number of slices in an array (array must be 1D or more). The array is sliced in row-major order, i.e. this is the dimension count of the first dimension.
(slice-views m)(slice-views m dimension)Gets a sequence of views of the slices of an array. If dimension is supplied, slices along a given dimension, otherwise slices along the first dimension. If the matrix implementation supports mutable views, these views can be used to mutate portions of the original array.
The key difference betwen 'slices' and 'slice-views' is that 'slice-views' will always return views, including for the 0-dimensional case. Hence it will return a sequence of 0-dimensional scalar arrays if the array is 1-dimensional.
Gets a sequence of views of the slices of an array. If dimension is supplied, slices along a given dimension, otherwise slices along the first dimension. If the matrix implementation supports mutable views, these views can be used to mutate portions of the original array. The key difference betwen 'slices' and 'slice-views' is that 'slice-views' will always return views, including for the 0-dimensional case. Hence it will return a sequence of 0-dimensional scalar arrays if the array is 1-dimensional.
(slices m)(slices m dimension)Gets a sequence of slices of an array. If dimension is supplied, slices along a given dimension, otherwise slices along the first dimension.
Returns a sequence of scalar values if the array is 1-dimensional.
Gets a sequence of slices of an array. If dimension is supplied, slices along a given dimension, otherwise slices along the first dimension. Returns a sequence of scalar values if the array is 1-dimensional.
(sparse-matrix data)(sparse-matrix implementation data)Creates a sparse matrix with the given data. Sparse matrices are required to store a M*N matrix with E non-zero elements in approx O(M+N+E) space or less.
Throws an exception if creation of a sparse matrix is not possible
Creates a sparse matrix with the given data. Sparse matrices are required to store a M*N matrix with E non-zero elements in approx O(M+N+E) space or less. Throws an exception if creation of a sparse matrix is not possible
(sparse? m)Returns true if an array is sparse, i.e. the implementation supports storage of the entire array in less memory than would normally be implied by the number of elements.
Sparse matrices may have memory requirements that scale with the number of non-zero elements rather than the total number of elements, for example.
Returns true if an array is sparse, i.e. the implementation supports storage of the entire array in less memory than would normally be implied by the number of elements. Sparse matrices may have memory requirements that scale with the number of non-zero elements rather than the total number of elements, for example.
(sqrt m)(sqrt! m)(square m)Squares every element of a numerical array.
Squares every element of a numerical array.
(square? m)Returns true if matrix is square (i.e. a 2D array with same number of rows and columns)
Returns true if matrix is square (i.e. a 2D array with same number of rows and columns)
(sub a)(sub a b)(sub a b & more)Performs element-wise subtraction on one or more numerical arrays. Returns the first array after it has been mutated.
Performs element-wise subtraction on one or more numerical arrays. Returns the first array after it has been mutated.
(sub! a)(sub! a b)(sub! a b & more)Performs element-wise mutable subtraction on one or more numerical arrays. Returns the first array, after it has been mutated.
Performs element-wise mutable subtraction on one or more numerical arrays. Returns the first array, after it has been mutated.
(submatrix m index-ranges)(submatrix m dimension index-range)(submatrix m row-start row-length col-start col-length)Gets a view of a submatrix, for a set of index ranges. Index ranges should be [start, length] pairs. Index range pairs can be nil (gets the whole range)
Gets a view of a submatrix, for a set of index ranges. Index ranges should be [start, length] pairs. Index range pairs can be nil (gets the whole range)
(subvector m start length)Gets a view of part of a vector. The view maintains a reference to the original, so can be used to modify the original vector if it is mutable.
Gets a view of part of a vector. The view maintains a reference to the original, so can be used to modify the original vector if it is mutable.
(supports-dimensionality? m dimension-count)Returns true if the implementation for a given matrix supports a specific dimensionality, i.e. can natively create and manipulate matrices with the given number of dimensions
Returns true if the implementation for a given matrix supports a specific dimensionality, i.e. can natively create and manipulate matrices with the given number of dimensions
(supports-shape? m shape)Returns true if the implementation supports creation of matrices with a specific shape.
Returns true if the implementation supports creation of matrices with a specific shape.
(sv-decomposition m)Computes the Singular Value decomposition of a matrix. Returns a vector containing three matrices [U S V*]
Intended usage: (let [[U S V*] (sv-decomosition M)] ....)
Computes the Singular Value decomposition of a matrix. Returns a vector containing three matrices [U S V*] Intended usage: (let [[U S V*] (sv-decomosition M)] ....)
(swap-rows m i j)Swap row i with row j in a matrix
Swap row i with row j in a matrix
(symmetric? m)Returns true if the parameter is a symmetric matrix
Returns true if the parameter is a symmetric matrix
(tan m)(tan! m)(tanh m)(tanh! m)(to-degrees m)(to-degrees! m)(to-double-array m)(to-double-array m want-copy?)Returns a Java double[] array containing the values of a numerical array m in row-major order. Will throw an error if any of the array elements cannot be converted to doubles.
If want-copy? is true, will guarantee a new double array (defensive copy). If want-copy? is false, will return the internal array used by m, or nil if not supported by the implementation. If want-copy? is not specified, will return either a copy or the internal array
Returns a Java double[] array containing the values of a numerical array m in row-major order. Will throw an error if any of the array elements cannot be converted to doubles. If want-copy? is true, will guarantee a new double array (defensive copy). If want-copy? is false, will return the internal array used by m, or nil if not supported by the implementation. If want-copy? is not specified, will return either a copy or the internal array
(to-nested-vectors m)Converts an array to an idiomatic, immutable nested Clojure vector format. The bottom level of the nested vectors will contain the element values.
The depth of nesting will be equal to the dimensionality of the array.
Converts an array to an idiomatic, immutable nested Clojure vector format. The bottom level of the nested vectors will contain the element values. The depth of nesting will be equal to the dimensionality of the array.
(to-object-array m)(to-object-array m want-copy?)Returns a Java Object[] array containing the values of an array m in row-major order.
If want-copy? is true, will guarantee a new Object array (defensive copy). If want-copy? is false, will return the internal array used by m, or nil if not supported by the implementation. If want-copy? is not specified, will return either a copy or the internal array
Returns a Java Object[] array containing the values of an array m in row-major order. If want-copy? is true, will guarantee a new Object array (defensive copy). If want-copy? is false, will return the internal array used by m, or nil if not supported by the implementation. If want-copy? is not specified, will return either a copy or the internal array
(to-radians m)(to-radians! m)(to-vector m)Creates a new array representing the elements of array m as a single flattened vector. The new vector will be a mutable copy if the implementation supports mutable vectors.
Creates a new array representing the elements of array m as a single flattened vector. The new vector will be a mutable copy if the implementation supports mutable vectors.
(trace a)Calculates the trace of a 2D numerical matrix (sum of elements on main diagonal)
Calculates the trace of a 2D numerical matrix (sum of elements on main diagonal)
(transform t v)Transforms a given vector with a transformation, returning a new vector.
The transformation may be a 2D matrix, but other types of transformation are also supported e.g. affine transformations.
Transforms a given vector with a transformation, returning a new vector. The transformation may be a 2D matrix, but other types of transformation are also supported e.g. affine transformations.
(transform! t v)Transforms a given vector in place. Returns the transformed vector.
The transformation must map an n-dimensional vector to another n-dimensional vector, i.e. if it is a 2D matrix then it must have shape [n x n].
Transforms a given vector in place. Returns the transformed vector. The transformation must map an n-dimensional vector to another n-dimensional vector, i.e. if it is a 2D matrix then it must have shape [n x n].
(transpose m)(transpose m ordering)Transposes a matrix, returning a new matrix. For 2D matices, rows and columns are swapped. More generally, the dimension indices are reversed for any shape of array. Note that 1D vectors and scalars will be returned unchanged.
If ordering is provided, will re-order dimensions according to the provided order.
Transposes a matrix, returning a new matrix. For 2D matices, rows and columns are swapped. More generally, the dimension indices are reversed for any shape of array. Note that 1D vectors and scalars will be returned unchanged. If ordering is provided, will re-order dimensions according to the provided order.
(transpose! m)Transposes a square 2D matrix in-place. Will throw an exception if not possible.
Transposes a square 2D matrix in-place. Will throw an exception if not possible.
(vec? m)Returns true if the parameter is a vector (1-dimensional array)
Returns true if the parameter is a vector (1-dimensional array)
(with-implementation impl & body)(zero-array shape)(zero-array implementation shape)Creates a new zero-filled numerical array with the given shape. If the implementation supports mutable matrices, then the new matrix will be fully mutable.
Creates a new zero-filled numerical array with the given shape. If the implementation supports mutable matrices, then the new matrix will be fully mutable.
(zero-count m)Counts the number of zeros in an array.
Counts the number of zeros in an array.
(zero-dimensional? m)Returns true if the parameter has zero dimensions. i.e. it is a 0-d array or a scalar value.
Returns true if the parameter has zero dimensions. i.e. it is a 0-d array or a scalar value.
(zero-matrix rows columns)(zero-matrix implementation rows columns)Constructs a new zero-filled numerical matrix with the given dimensions. If the implementation supports mutable matrices, then the new matrix will be fully mutable.
Constructs a new zero-filled numerical matrix with the given dimensions. If the implementation supports mutable matrices, then the new matrix will be fully mutable.
(zero-matrix? m)Returns true if all the elements of the parameter are zeros.
Returns true if all the elements of the parameter are zeros.
(zero-vector length)(zero-vector implementation length)Constructs a new zero-filled numerical vector with the given length. If the implementation supports mutable vectors, then the new vector will be fully mutable.
Constructs a new zero-filled numerical vector with the given length. If the implementation supports mutable vectors, then the new vector will be fully mutable.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |