Liking cljdoc? Tell your friends :D
Clojure only.

clojure.core.matrix


*matrix-implementation*clj


absclj

(abs m)

abs!clj

(abs! m)

acosclj

(acos m)

acos!clj

(acos! m)

addclj

(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.
raw docstring

add!clj

(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.
raw docstring

add-productclj

(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.
raw docstring

add-product!clj

(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.
raw docstring

add-rowclj

(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
raw docstring

add-scaledclj

(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
raw docstring

add-scaled!clj

(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.
raw docstring

add-scaled-productclj

(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
raw docstring

add-scaled-product!clj

(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.
raw docstring

arrayclj

(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:

  • 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.

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.
raw docstring

array?clj

(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
raw docstring

as-vectorclj

(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.
raw docstring

asinclj

(asin m)

asin!clj

(asin! m)

assignclj

(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.
raw docstring

assign!clj

(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.
raw docstring

assign-array!clj

(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
raw docstring

atanclj

(atan m)

atan!clj

(atan! m)

broadcastclj

(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.
raw docstring

broadcast-coerceclj

(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)).
raw docstring

broadcast-likeclj

(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'.
raw docstring

cbrtclj

(cbrt m)

cbrt!clj

(cbrt! m)

ceilclj

(ceil m)

ceil!clj

(ceil! m)

cholesky-decompositionclj

(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)] ....)
raw docstring

cloneclj

(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:

  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.

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.
raw docstring

coerceclj

(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.
raw docstring

column-countclj

(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)
raw docstring

column-matrixclj

(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.
raw docstring

column-matrix?clj

(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)
raw docstring

columnsclj

(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.
raw docstring

compute-matrixclj

(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
raw docstring

conforming?clj

(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.
raw docstring

cosclj

(cos m)

cos!clj

(cos! m)

coshclj

(cosh m)

cosh!clj

(cosh! m)

crossclj

(cross a b)

Computes the cross-product of two numerical 3D vectors

Computes the cross-product of two numerical 3D vectors
raw docstring

cross!clj

(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.
raw docstring

current-implementationclj

(current-implementation)

Gets the currently active matrix implementation (as a keyword)

Gets the currently active matrix implementation (as a keyword)
raw docstring

current-implementation-objectclj

(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.
raw docstring

densityclj

(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
raw docstring

detclj

(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.
raw docstring

diagonalclj

(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.
raw docstring

diagonal-matrixclj

(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.
raw docstring

dimension-countclj

(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.
raw docstring

dimensionalityclj

(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.
raw docstring

distanceclj

(distance a b)

Calculates the euclidean distance between two numerical vectors.

Calculates the euclidean distance between two numerical vectors.
raw docstring

divclj

(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.
raw docstring

div!clj

(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.
raw docstring

dotclj

(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.
raw docstring

e*clj

(e*)
(e* a)
(e* a b)
(e* a b & more)

Element-wise multiply operator. Equivalent to emul.

Element-wise multiply operator. Equivalent to emul.
raw docstring

e=clj

(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.
raw docstring

e==clj

(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.
raw docstring

ecountclj

(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.
raw docstring

eigen-decompositionclj

(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)] ....)
raw docstring

element-typeclj

(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.
raw docstring

emapclj

(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.
raw docstring

emap!clj

(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.
raw docstring

emaxclj

(emax m)

Gets the maximum element value from a numerical array

Gets the maximum element value from a numerical array
raw docstring

eminclj

(emin m)

Gets the minimum element value from a numerical array

Gets the minimum element value from a numerical array
raw docstring

emulclj

(emul)
(emul a)
(emul a b)
(emul a b & more)

Performs element-wise multiplication.

Performs element-wise multiplication.
raw docstring

emul!clj

(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.
raw docstring

ensure-mutableclj

(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.
raw docstring

equalsclj

(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)
raw docstring

ereduceclj

(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.
raw docstring

eseqclj

(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
raw docstring

esumclj

(esum m)

Calculates the sum of all the elements in a numerical array.

Calculates the sum of all the elements in a numerical array.
raw docstring

expclj

(exp m)

exp!clj

(exp! m)

fillclj

(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.
raw docstring

fill!clj

(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.
raw docstring

floorclj

(floor m)

floor!clj

(floor! m)

get-columnclj

(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.
raw docstring

get-rowclj

(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.
raw docstring

identity-matrixclj

(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.
raw docstring

identity-matrix?clj

(identity-matrix? m)

Returns true if the parameter is an identity-matrix

Returns true if the parameter is an identity-matrix
raw docstring

immutableclj

(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.
raw docstring

index-seqclj

(index-seq m)

index-seq-for-shapeclj

(index-seq-for-shape sh)

inner-productclj

(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.
raw docstring

inverseclj

(inverse m)

Calculates the inverse of a 2D numerical matrix.

Calculates the inverse of a 2D numerical matrix.
raw docstring

joinclj

(join & arrays)

Joins arrays together, along dimension 0. Other dimensions must be compatible

Joins arrays together, along dimension 0. Other dimensions must be compatible
raw docstring

join-alongclj

(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.
raw docstring

lengthclj

(length m)

Calculates the euclidean length (magnitude) of a numerical vector

Calculates the euclidean length (magnitude) of a numerical vector
raw docstring

length-squaredclj

(length-squared m)

Calculates the squared length (squared magnitude) of a numerical vector

Calculates the squared length (squared magnitude) of a numerical vector
raw docstring

logclj

(log m)

log!clj

(log! m)

log10clj

(log10 m)

log10!clj

(log10! m)

loop-symmetric?clj

(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
raw docstring

lu-decompositionclj

(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)] ....) 
raw docstring

main-diagonalclj

(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.
raw docstring

matrixclj

(matrix data)
(matrix implementation data)

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

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*
raw docstring

matrix?clj

(matrix? m)

Returns true if parameter is a valid matrix (dimensionality == 2)

Returns true if parameter is a valid matrix (dimensionality == 2)
raw docstring

mgetclj

(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.
raw docstring

mmulclj

(mmul)
(mmul a)
(mmul a b)
(mmul a b & more)

Performs matrix multiplication (equivalent to inner-product).

Performs matrix multiplication (equivalent to inner-product).
raw docstring

msetclj

(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.
raw docstring

mset!clj

(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)
raw docstring

mulclj

(mul)
(mul a)
(mul a b)
(mul a b & more)

Performs element-wise multiplication with numerical arrays.

Performs element-wise multiplication with numerical arrays.
raw docstring

mul!clj

(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.
raw docstring

multiply-rowclj

(multiply-row m i factor)

Multiply row i by a constant factor

Multiply row i by a constant factor
raw docstring

mutableclj

(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.
raw docstring

mutable-matrixcljdeprecated

(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
raw docstring

mutable?clj

(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.
raw docstring

negateclj

(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
raw docstring

negate!clj

(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
raw docstring

new-arrayclj

(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.
raw docstring

new-matrixclj

(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.
raw docstring

new-scalar-arrayclj

(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.
raw docstring

new-vectorclj

(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.
raw docstring

normaliseclj

(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.
raw docstring

normalise!clj

(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.
raw docstring

numerical?clj

(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).
raw docstring

outer-productclj

(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.
raw docstring

packclj

(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.
raw docstring

permutation-matrixclj

(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.
raw docstring

pmclj

(pm m)
(pm m & opts)

Pretty-prints a matrix

Pretty-prints a matrix
raw docstring

powclj

(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.
raw docstring

pow!clj

(pow! m a)

Mutable exponent function, see 'pow'

Mutable exponent function, see 'pow'
raw docstring

qr-decompositionclj

(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)] ....)
raw docstring

rankclj

(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
raw docstring

reshapeclj

(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.
raw docstring

rotateclj

(rotate m shifts)
(rotate m dimension shift-amount)

Rotates an array along specified dimensions.

Rotates an array along specified dimensions.
raw docstring

roundclj

(round m)

round!clj

(round! m)

row-countclj

(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)
raw docstring

row-matrixclj

(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.
raw docstring

row-matrix?clj

(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)
raw docstring

rowsclj

(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.
raw docstring

same-shape?clj

(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
raw docstring

scalarclj

(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.
raw docstring

scalar-arrayclj

(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.
raw docstring

scalar?clj

(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.
raw docstring

scaleclj

(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.
raw docstring

scale!clj

(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.
raw docstring

set-current-implementationclj

(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]])
raw docstring

set-rowclj

(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.
raw docstring

set-row!clj

(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.
raw docstring

shapeclj

(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)
raw docstring

signumclj

(signum m)

signum!clj

(signum! m)

sinclj

(sin m)

sin!clj

(sin! m)

sinhclj

(sinh m)

sinh!clj

(sinh! m)

sliceclj

(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.
raw docstring

slice-countclj

(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.
raw docstring

slice-viewsclj

(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.
raw docstring

slicesclj

(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.
raw docstring

sparse-matrixclj

(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
raw docstring

sparse?clj

(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.
raw docstring

sqrtclj

(sqrt m)

sqrt!clj

(sqrt! m)

squareclj

(square m)

Squares every element of a numerical array.

Squares every element of a numerical array.
raw docstring

square?clj

(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)
raw docstring

subclj

(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.
raw docstring

sub!clj

(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.
raw docstring

submatrixclj

(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) 
raw docstring

subvectorclj

(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.
raw docstring

supports-dimensionality?clj

(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
raw docstring

supports-shape?clj

(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.
raw docstring

sv-decompositionclj

(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)] ....)
raw docstring

swap-rowsclj

(swap-rows m i j)

Swap row i with row j in a matrix

Swap row i with row j in a matrix
raw docstring

symmetric?clj

(symmetric? m)

Returns true if the parameter is a symmetric matrix

Returns true if the parameter is a symmetric matrix
raw docstring

tanclj

(tan m)

tan!clj

(tan! m)

tanhclj

(tanh m)

tanh!clj

(tanh! m)

to-degreesclj

(to-degrees m)

to-degrees!clj

(to-degrees! m)

to-double-arrayclj

(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
raw docstring

to-nested-vectorsclj

(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.
raw docstring

to-object-arrayclj

(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
raw docstring

to-radiansclj

(to-radians m)

to-radians!clj

(to-radians! m)

to-vectorclj

(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.
raw docstring

traceclj

(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)
raw docstring

transformclj

(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.
raw docstring

transform!clj

(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].
raw docstring

transposeclj

(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.
raw docstring

transpose!clj

(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.
raw docstring

vec?clj

(vec? m)

Returns true if the parameter is a vector (1-dimensional array)

Returns true if the parameter is a vector (1-dimensional array)
raw docstring

with-implementationcljmacro

(with-implementation impl & body)

zero-arrayclj

(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.
raw docstring

zero-countclj

(zero-count m)

Counts the number of zeros in an array.

Counts the number of zeros in an array.
raw docstring

zero-dimensional?clj

(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.
raw docstring

zero-matrixclj

(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.
raw docstring

zero-matrix?clj

(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.
raw docstring

zero-vectorclj

(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.
raw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close