(broadcast-compatible a b)Broadcasts two matrices into identical shapes, coercing to the type of the first matrix. Intended to prepare for elementwise operations. Returns a vector containing the two broadcasted matrices. Throws an error if not possible.
Broadcasts two matrices into identical shapes, coercing to the type of the first matrix. Intended to prepare for elementwise operations. Returns a vector containing the two broadcasted matrices. Throws an error if not possible.
Protocol for add-product operation. Intended to implement a fast version for result = m + a * b
Protocol for add-product operation. Intended to implement a fast version for result = m + a * b
(add-product m a b)Protocol for mutable add-product! operation.
Protocol for mutable add-product! operation.
(add-product! m a b)Protocol for add-scaled operation. Intended to implement a fast version for result = m + a * factor
Protocol for add-scaled operation. Intended to implement a fast version for result = m + a * factor
(add-scaled m a factor)Protocol for mutable add-scaled! operation.
Protocol for mutable add-scaled! operation.
(add-scaled! m a factor)Protocol for add-product operation. Intended to implement a fast version for result = m + a * b * factor
Protocol for add-product operation. Intended to implement a fast version for result = m + a * b * factor
(add-scaled-product m a b factor)Protocol for mutable add-product! operation.
Protocol for mutable add-product! operation.
(add-scaled-product! m a b factor)Option protocol for quick determination of array matrics
Option protocol for quick determination of array matrics
(nonzero-count m)Protocol for assigning values element-wise to mutable arrays.
Protocol for assigning values element-wise to mutable arrays.
(assign! m source)Sets all the values in an array from a given source. Source may be a scalar or a smaller array that can be broadcast to the shape of m.
Sets all the values in an array from a given source. Source may be a scalar or a smaller array that can be broadcast to the shape of m.
(assign-array! m arr)(assign-array! m arr start length)Sets the elements in an array from an Java array source, in row-major order.
Sets the elements in an array from an Java array source, in row-major order.
Protocol to support broadcasting over one or more dimensions.
Protocol to support broadcasting over one or more dimensions.
(broadcast m target-shape)Broadcasts an array over a desired target shape, which should be larger than the current matrix. Dimensions should be matched up according to the last dimension. In order to broadcast sucessfully, the current dimension of the array must be either:
If broadcasting is not possible, an exception must be thrown.
Broadcasting may return either a view with replicated element or a new immutable matrix.
Broadcasts an array over a desired target shape, which should be larger than the current matrix. Dimensions should be matched up according to the last dimension. In order to broadcast sucessfully, the current dimension of the array must be either: - of size 1 - equal to the size of the dimension in the target shape - not included in the array (i.e. the target shape has more leading dimensions) If broadcasting is not possible, an exception must be thrown. Broadcasting may return either a view with replicated element or a new immutable matrix.
Protocol to broadcast into a given matrix shape and perform coercion in one step.
Equivalent to (coerce m (broadcast-like m a)) but likely to be more efficient.
Protocol to broadcast into a given matrix shape and perform coercion in one step. Equivalent to (coerce m (broadcast-like m a)) but likely to be more efficient.
(broadcast-coerce m a)Protocol to broadcast into a given matrix shape. May also perform coercion if needed by the implementation.
Protocol to broadcast into a given matrix shape. May also perform coercion if needed by the implementation.
(broadcast-like m a)Protocol to coerce a parameter to a format used by a specific implementation. It is up to the implementation to determine what parameter types they support. If the implementation is unable to perform coercion, it must return nil.
Implementations are encouraged to avoid taking a full copy of the data, for performance reasons. It is preferable to use structural sharing with the original data if possible.
If coercion is impossible (e.g. param has an invalid shape or element types) then the implementation may throw an exception, though it may also return nil to get default behaviour, which should implement any expected exceptions.
If an implementation implements coercion via copying, then it is recommended that conversion should be to the most efficient packed representation (i.e. as defined by 'pack')
Implementations must also be able to coerce valid scalar values (presumably via the identity function)
Protocol to coerce a parameter to a format used by a specific implementation. It is up to the implementation to determine what parameter types they support. If the implementation is unable to perform coercion, it must return nil. Implementations are encouraged to avoid taking a full copy of the data, for performance reasons. It is preferable to use structural sharing with the original data if possible. If coercion is impossible (e.g. param has an invalid shape or element types) then the implementation *may* throw an exception, though it may also return nil to get default behaviour, which should implement any expected exceptions. If an implementation implements coercion via copying, then it is recommended that conversion should be to the most efficient packed representation (i.e. as defined by 'pack') Implementations must also be able to coerce valid scalar values (presumably via the identity function)
(coerce-param m param)Attempts to coerce param into a matrix format supported by the implementation of matrix m. May return nil if unable to do so, in which case a default implementation can be used.
Attempts to coerce param into a matrix format supported by the implementation of matrix m. May return nil if unable to do so, in which case a default implementation can be used.
Protocol to compute a matrix by calling a function on each indexed location. The function f will be called as (f x y z ...) for all index values.
Protocol to compute a matrix by calling a function on each indexed location. The function f will be called as (f x y z ...) for all index values.
(compute-matrix m shape f)Protocol to allow conversion to Clojure-friendly vector format. Optional for implementers, however providing an efficient implementation is strongly encouraged to enable fast interop with Clojure vectors.
Protocol to allow conversion to Clojure-friendly vector format. Optional for implementers, however providing an efficient implementation is strongly encouraged to enable fast interop with Clojure vectors.
(convert-to-nested-vectors m)Protocol to return standard dimension information about an array. dimensionality and dimension-count are mandatory for implementations
Protocol to return standard dimension information about an array. dimensionality and dimension-count are mandatory for implementations
(dimension-count m dimension-number)Returns the size of a specific dimension. Must throw an exception if the array does not have the specified dimension.
Returns the size of a specific dimension. Must throw an exception if the array does not have the specified dimension.
(dimensionality m)Returns the number of dimensions of an array
Returns the number of dimensions of an array
(get-shape m)Returns the shape of the array, typically as a Java array or sequence of dimension sizes. Implementations are free to choose what type is used to represent the shape, but it must contain only integer values and be traversable as a sequence via clojure.core/seq
Returns the shape of the array, typically as a Java array or sequence of dimension sizes. Implementations are free to choose what type is used to represent the shape, but it must contain only integer values and be traversable as a sequence via clojure.core/seq
(is-scalar? m)Tests whether an object is a scalar value, i.e. a value that can exist at a specific position in an array.
Tests whether an object is a scalar value, i.e. a value that can exist at a specific position in an array.
(is-vector? m)Tests whether an object is a vector (1D array)
Tests whether an object is a vector (1D array)
Protocol for getting data as a double array
Protocol for getting data as a double array
(as-double-array m)Returns the internal double array used by m. If no such array is used, returns nil. Provides an opportunity to avoid copying the internal array.
Returns the internal double array used by m. If no such array is used, returns nil. Provides an opportunity to avoid copying the internal array.
(to-double-array m)Returns a double array containing the values of m in row-major order. May or may not be the internal double array used by m, depending on the implementation.
Returns a double array containing the values of m in row-major order. May or may not be the internal double array used by m, depending on the implementation.
Protocol to return the total count of elements in matrix. Result may be any integer type, typically a java.lang.Long
Protocol to return the total count of elements in matrix. Result may be any integer type, typically a java.lang.Long
(element-count m)(persistent-vector-coerce x)Protocol to support the 'pow' function. Should raise every element of a matrix to a given exponent. Default implementation uses Java's Math/pow function which is appropriate for double values: arrays supporting arbitrary precision numbers or complex types will need to provide their own implementation.
Protocol to support the 'pow' function. Should raise every element of a matrix to a given exponent. Default implementation uses Java's Math/pow function which is appropriate for double values: arrays supporting arbitrary precision numbers or complex types will need to provide their own implementation.
(element-pow m exponent)Protocol to allow functional-style operations on matrix elements.
Protocol to allow functional-style operations on matrix elements.
(element-map m f)(element-map m f a)(element-map m f a more)Maps f over all elements of m (and optionally other matrices), returning a new matrix
Maps f over all elements of m (and optionally other matrices), returning a new matrix
(element-map! m f)(element-map! m f a)(element-map! m f a more)Maps f over all elements of m (and optionally other matrices), mutating the elements of m in place. Must throw an exception if m is not mutable.
Maps f over all elements of m (and optionally other matrices), mutating the elements of m in place. Must throw an exception if m is not mutable.
(element-reduce m f)(element-reduce m f init)Reduces with the function f over all elements of m.
Reduces with the function f over all elements of m.
(element-seq m)Must return a sequence containing all elements of the matrix, in row-major order.
Must return a sequence containing all elements of the matrix, in row-major order.
Protocol for returning the generic numerical functions of a matrix implementation
Protocol for returning the generic numerical functions of a matrix implementation
(generic-add m)Generic 'add' function for numerical values. Must satisfy (equals x (add zero x)).
Generic 'add' function for numerical values. Must satisfy (equals x (add zero x)).
(generic-div m)Generic 'div' function for numerical values.
Generic 'div' function for numerical values.
(generic-mul m)Generic 'mul' function for numerical values. Must satisfy (equals x (mul one x)).
Generic 'mul' function for numerical values. Must satisfy (equals x (mul one x)).
(generic-negate m)Generic 'negate' function for numerical values.
Generic 'negate' function for numerical values.
Protocol for returning the generic/default values of a matrix implementation
Protocol for returning the generic/default values of a matrix implementation
(generic-one m)Generic 'one' value for numerical arrays. Must satisfy (equals m (mul m one)).
Generic 'one' value for numerical arrays. Must satisfy (equals m (mul m one)).
(generic-value m)Generic value for a new array. Likely to be zero or nil.
Generic value for a new array. Likely to be zero or nil.
(generic-zero m)Generic 'zero' value for numerical arrays. Must satisfy (equals m (add m zero)).
Generic 'zero' value for numerical arrays. Must satisfy (equals m (add m zero)).
Protocol for assigning values element-wise to an array, broadcasting as needed.
Protocol for assigning values element-wise to an array, broadcasting as needed.
(assign m source)Sets all the values in an array from a given source. Source may be a scalar or a smaller array that can be broadcast to the shape of m.
Sets all the values in an array from a given source. Source may be a scalar or a smaller array that can be broadcast to the shape of m.
Protocol for creating an immutable copy of a matrix. If implemented, must return a fully immutable copy of the given matrix.
The default implementation will attempt to choose a suitable immutable matrix implementation.
Protocol for creating an immutable copy of a matrix. If implemented, must return a fully immutable copy of the given matrix. The default implementation will attempt to choose a suitable immutable matrix implementation.
(immutable-matrix m)Protocol for general implementation functionality. Required to support implementation metadata and matrix construction.
Protocol for general implementation functionality. Required to support implementation metadata and matrix construction.
(construct-matrix m data)Returns a new matrix containing the given data. data should be in the form of either nested sequences or a valid existing matrix
Returns a new matrix containing the given data. data should be in the form of either nested sequences or a valid existing matrix
(implementation-key m)Returns a keyword representing this implementation. Each implementation should have one unique key.
Returns a keyword representing this implementation. Each implementation should have one unique key.
(meta-info m)Returns meta-information on the implementation. It is expected that at least an element :doc containing a string describing an implementation is provided.
Returns meta-information on the implementation. It is expected that at least an element :doc containing a string describing an implementation is provided.
(new-matrix m rows columns)Returns a new matrix (regular 2D matrix) with the given number of rows and columns, filled with numeric zero.
Returns a new matrix (regular 2D matrix) with the given number of rows and columns, filled with numeric zero.
(new-matrix-nd m shape)Returns a new general matrix of the given shape. Shape must be a sequence of dimension sizes.
Returns a new general matrix of the given shape. Shape must be a sequence of dimension sizes.
(new-vector m length)Returns a new vector (1D column matrix) of the given length, filled with numeric zero.
Returns a new vector (1D column matrix) of the given length, filled with numeric zero.
(supports-dimensionality? m dimensions)Returns true if the implementation supports matrices with the given number of dimensions.
Returns true if the implementation supports matrices with the given number of dimensions.
Protocol for indexed read access to arrays, matrices and vectors. Indexing values can be assumed to be integers. indexes may be any sequence or Java array of index values.
Protocol for indexed read access to arrays, matrices and vectors. Indexing values can be assumed to be integers. indexes may be any sequence or Java array of index values.
(get-1d m row)(get-2d m row column)(get-nd m indexes)Protocol for indexed 'setter' operations. These are like Clojure's 'assoc' function, i.e. they return an updated copy of the original array, which is itself unchanged. Must be supported for any immutable array type.
Protocol for indexed 'setter' operations. These are like Clojure's 'assoc' function, i.e. they return an updated copy of the original array, which is itself unchanged. Must be supported for any immutable array type.
(is-mutable? m)Returns true if the matrix is mutable and therefore supports direct mutable operations, e.g. add!
Returns true if the matrix is mutable and therefore supports direct mutable operations, e.g. add!
(set-1d m row v)(set-2d m row column v)(set-nd m indexes v)Protocol for indexed mutable setter access to matrices and vectors. Must be supported for any mutable matrix type.
Protocol for indexed mutable setter access to matrices and vectors. Must be supported for any mutable matrix type.
(set-1d! m row v)(set-2d! m row column v)(set-nd! m indexes v)Protocol to support mathematic functions applied element-wise to a numerical array
Protocol to support mathematic functions applied element-wise to a numerical array
(to-radians m)(log m)(acos m)(to-degrees m)(floor m)(tanh m)(ceil m)(atan m)(cos m)(log10 m)(tan m)(cbrt m)(sqrt m)(exp m)(cosh m)(asin m)(round m)(abs m)(sinh m)(sin m)(signum m)Protocol to support mutable mathematic functions applied element-wise to a numerical array
Protocol to support mutable mathematic functions applied element-wise to a numerical array
(sqrt! m)(asin! m)(cos! m)(ceil! m)(atan! m)(to-radians! m)(abs! m)(log! m)(cosh! m)(sin! m)(tan! m)(exp! m)(to-degrees! m)(cbrt! m)(round! m)(signum! m)(acos! m)(sinh! m)(tanh! m)(floor! m)(log10! m)Protocol to support addition and subtraction on arbitrary matrices. These are elementwise operations that should support broadcasting.
Protocol to support addition and subtraction on arbitrary matrices. These are elementwise operations that should support broadcasting.
(matrix-add m a)(matrix-sub m a)Protocol to support mutable addition and subtraction
Protocol to support mutable addition and subtraction
(matrix-add! m a)(matrix-sub! m a)Protocol for cloning a matrix value. The new clone must be mutable if the original matrix is mutable, i.e. mutating the clone must not affect the original. The copy should be shallow, if applicable.
Protocol for cloning a matrix value. The new clone must be mutable if the original matrix is mutable, i.e. mutating the clone must not affect the original. The copy should be shallow, if applicable.
(clone m)Returns a clone of an array. Must be a new independent (non-view) instance if the array is mutable.
Returns a clone of an array. Must be a new independent (non-view) instance if the array is mutable.
Protocol to support element-wise division operator. One-arg version returns the reciprocal of all elements.
Protocol to support element-wise division operator. One-arg version returns the reciprocal of all elements.
(element-divide m)(element-divide m a)Protocol to support mutable element-wise division operater. One-arg version returns the reciprocal of all elements.
Protocol to support mutable element-wise division operater. One-arg version returns the reciprocal of all elements.
(element-divide! m)(element-divide! m a)Protocol for numerical array equality operations.
Protocol for numerical array equality operations.
(matrix-equals a b)Return true if a equals b, i.e. if a and b are have the same shape and all elements are equal. Must use numerical value comparison on numbers (==) to account for matrices that may hold a mix of numercial types (e.g. java.lang.Long and java.lang.Double). Implementations that only support doubles should use Number.doubleValue() to get a numeric value to compare. May throw an exception if the matrices are non-numeric
Return true if a equals b, i.e. if a and b are have the same shape and all elements are equal. Must use numerical value comparison on numbers (==) to account for matrices that may hold a mix of numercial types (e.g. java.lang.Long and java.lang.Double). Implementations that only support doubles should use Number.doubleValue() to get a numeric value to compare. May throw an exception if the matrices are non-numeric
Protocol for numerical array equality operations with a specified tolerance.
Protocol for numerical array equality operations with a specified tolerance.
(matrix-equals-epsilon a b eps)As matrix-equals, but provides a numerical tolerance for equality testing.
As matrix-equals, but provides a numerical tolerance for equality testing.
Protocol to support matrix multiplication on an arbitrary matrix, vector or scalar.
Implementation may return nil if the implementation does not support one of the parameters, in which case a more general operation will be attempted.
Protocol to support matrix multiplication on an arbitrary matrix, vector or scalar. Implementation may return nil if the implementation does not support one of the parameters, in which case a more general operation will be attempted.
(element-multiply m a)(matrix-multiply m a)Protocol to support mutable matrix multiplication on an arbitrary matrix, vector or scalar
Protocol to support mutable matrix multiplication on an arbitrary matrix, vector or scalar
(element-multiply! m a)(matrix-multiply! m a)Protocol to support mutable array scaling by scalar values.
Protocol to support mutable array scaling by scalar values.
(pre-scale! m factor)(scale! m factor)Protocol to support common 2D numerical matrix operations
Protocol to support common 2D numerical matrix operations
(determinant m)Returns the determinant of a matrix.
Returns the determinant of a matrix.
(inverse m)Returns the invese of a matrix. Should throw an exception if m is not invertible.
Returns the invese of a matrix. Should throw an exception if m is not invertible.
(trace m)Returns the trace of a matrix (sum of elements on main diagonal. Must throw an error if the matrix is not square (i.e. all dimensions sizes are equal)
Returns the trace of a matrix (sum of elements on main diagonal. Must throw an error if the matrix is not square (i.e. all dimensions sizes are equal)
Protocol for matrix predicates like identity-matrix? or zero-matrix?
Protocol for matrix predicates like identity-matrix? or zero-matrix?
(identity-matrix? m)returns true if the matrix m is an identity-matrix
returns true if the matrix m is an identity-matrix
(loop-symmetric? m)FOR TESTING ONLY. returns true if matrix m is symmetric
FOR TESTING ONLY. returns true if matrix m is symmetric
(symmetric? m)returns true if matrix m is symmetric
returns true if matrix m is symmetric
(zero-matrix? m)returns true if all the elements of matrix m are zeros
returns true if all the elements of matrix m are zeros
Protocol for general inner and outer products of arrays. Products should use + and * as normally defined for numerical types
Protocol for general inner and outer products of arrays. Products should use + and * as normally defined for numerical types
(inner-product m a)(outer-product m a)Protocol to support computing the rank (number of linearly independent rows) in a matrix
Protocol to support computing the rank (number of linearly independent rows) in a matrix
(rank m)Returns the rank of a matrix
Returns the rank of a matrix
Protocol to support numerical array scaling by scalar values. Provided because array classes may have efficient specialised scaling operaions.
Works according the the default definition of multiplication for the matrix class (usually numerical, i.e. equivalent to clojure.core/+)
Protocol to support numerical array scaling by scalar values. Provided because array classes may have efficient specialised scaling operaions. Works according the the default definition of multiplication for the matrix class (usually numerical, i.e. equivalent to clojure.core/+)
(pre-scale m a)Pre-multiplies the array with the scalar. This is the same as scale for arrays where multiplication is commutative, but may be different for special kinds of scalars.
Pre-multiplies the array with the scalar. This is the same as scale for arrays where multiplication is commutative, but may be different for special kinds of scalars.
(scale m a)Multiplies a array by the scalar value a,
Multiplies a array by the scalar value a,
Protocol to support getting slices of an array. If implemented, must return either a view, a scalar or an immutable sub-matrix: it must not return copied data. i.e. making a full copy must be avoided.
Protocol to support getting slices of an array. If implemented, must return either a view, a scalar or an immutable sub-matrix: it must *not* return copied data. i.e. making a full copy must be avoided.
(get-column m i)(get-major-slice m i)(get-row m i)(get-slice m dimension i)Protocol for picking out subsections of a 2D matrix. Should return a mutable view if possible. The default implementation creates a new vector containing the diagonal values.
Protocol for picking out subsections of a 2D matrix. Should return a mutable view if possible. The default implementation creates a new vector containing the diagonal values.
(main-diagonal m)(fill! m value)Fills the array with the given scalar value.
Fills the array with the given scalar value.
Protocol for creating a mutable copy of a matrix. If implemented, must return either a fully mutable copy of the given matrix, or nil if not possible.
The default implementation will attempt to choose a suitable mutable matrix implementation.
Protocol for creating a mutable copy of a matrix. If implemented, must return either a fully mutable copy of the given matrix, or nil if not possible. The default implementation will attempt to choose a suitable mutable matrix implementation.
(mutable-matrix m)Protocol for mutable versions of common vector operations
Protocol for mutable versions of common vector operations
(normalise! a)(negate m)Returns a new numerical array with all elements negated.
Returns a new numerical array with all elements negated.
Protocol for identifying numerical arrays. Should return true if every element in the array is a valid numerical value.
Protocol for identifying numerical arrays. Should return true if every element in the array is a valid numerical value.
(numerical? m)Returns true if the array is numerical.
Returns true if the array is numerical.
Protocol for getting data as an object array
Protocol for getting data as an object array
(as-object-array m)Returns the internal object array used by m. If no such array is used, returns nil. Provides an opportunity to avoid copying the internal array.
Returns the internal object array used by m. If no such array is used, returns nil. Provides an opportunity to avoid copying the internal array.
(to-object-array m)Returns an object array containing the values of m in row-major order. May or may not be the internal object array used by m, depending on the implementation.
Returns an object array containing the values of m in row-major order. May or may not be the internal object array used by m, depending on the implementation.
Protocol to efficiently pack an array, according to the most efficient representation for a given implementation.
Definition of pack is up to the implementation to interpret, but the general rules are:
Protocol to efficiently pack an array, according to the most efficient representation for a given implementation. Definition of pack is up to the implementation to interpret, but the general rules are: 1. Must not change the value of the array for comparison purposes 2. Must not change the shape of the array 3. May preserve sparse representation 4. Should convert most efficient format for common operations (e.g. mget, inner-product)
(pack m)Protocol for construction of a permutation matrix.
Protocol for construction of a permutation matrix.
(permutation-matrix m permutation)Protocol to reshape matrices. Should support any new shape allowed by the implementation. Must preserve row-major ordering of matrix elements. If the original matrix is mutable, must return a new mutable copy of data. If the new shape has less elements than the original shape, it is OK to truncate the remaining elements. If the new shape requires more elements than the original shape, should throw an exception.
Protocol to reshape matrices. Should support any new shape allowed by the implementation. Must preserve row-major ordering of matrix elements. If the original matrix is mutable, must return a new mutable copy of data. If the new shape has less elements than the original shape, it is OK to truncate the remaining elements. If the new shape requires more elements than the original shape, should throw an exception.
(reshape m shape)Rotates an array along a specified dimension by the given number of places.
Rotating a dimension that does not exist has no effect on the array.
Rotates an array along a specified dimension by the given number of places. Rotating a dimension that does not exist has no effect on the array.
(rotate m dim places)Rotates an array using the specified shifts for each dimension.
shifts may be any sequence of iteger shift amounts.
Rotates an array using the specified shifts for each dimension. shifts may be any sequence of iteger shift amounts.
(rotate-all m shifts)Protocol to support construction of row and column matrices from 1D vectors.
A vector of length N should be converted to a 1xN or Nx1 matrix respectively.
Should throw an error if the data is not a 1D vector
Protocol to support construction of row and column matrices from 1D vectors. A vector of length N should be converted to a 1xN or Nx1 matrix respectively. Should throw an error if the data is not a 1D vector
(column-matrix m data)(row-matrix m data)Protocol for elementary row operations
Protocol for elementary row operations
(add-row m i j k)Returns a new matrix with row i added to row j times k
Returns a new matrix with row i added to row j times k
(multiply-row m i k)Returns a new matrix with row i multiplied by k
Returns a new matrix with row i multiplied by k
(swap-rows m i j)Returns a new matrix with rows i and j swapped
Returns a new matrix with rows i and j swapped
Protocol for row setting. Should set a dimension 0 (row) slice to thegiven row value.
Protocol for row setting. Should set a dimension 0 (row) slice to thegiven row value.
(set-row m i row)(set-row! m i row)Protocol to test if two arrays have the same shape. Implementations may have an optimised method for shape equality tests, and this is a frequently required operations so it may make sense to provide an optimised implementation.
Protocol to test if two arrays have the same shape. Implementations may have an optimised method for shape equality tests, and this is a frequently required operations so it may make sense to provide an optimised implementation.
(same-shape? a b)Protocol for concatenating / joining arrays.
Protocol for concatenating / joining arrays.
(join m a)Concatenates a to m, along the major slice dimension
Concatenates a to m, along the major slice dimension
Returns the row-major slices of the array as a sequence.
These must be views or immutable sub-arrays for higher order slices, or scalars for the slices of a 1D vector.
The default implementation uses get-major-slice-view to obtain the slices.
Returns the row-major slices of the array as a sequence. These must be views or immutable sub-arrays for higher order slices, or scalars for the slices of a 1D vector. The default implementation uses get-major-slice-view to obtain the slices.
(get-major-slice-seq m)Gets a sequence of all major array slices
Gets a sequence of all major array slices
Protocol for quick view access into a row-major slices of an array. If implemented, must return either a view or an immutable sub-matrix: it must not return copied data.
If the matrix is mutable, it must return a mutable view.
The default implementation creates a wrapper view.
Protocol for quick view access into a row-major slices of an array. If implemented, must return either a view or an immutable sub-matrix: it must *not* return copied data. If the matrix is mutable, it must return a mutable view. The default implementation creates a wrapper view.
(get-major-slice-view m i)Gets a view of a major array slice
Gets a view of a major array slice
Returns the row-major slice views of the array.
These must be arrays if the array is mutable, i.e. slices of a 1D vector must be 0-dimensional mutable arrays.
Returns the row-major slice views of the array. These must be arrays if the array is mutable, i.e. slices of a 1D vector must be 0-dimensional mutable arrays.
(get-major-slice-view-seq m)Gets a sequence of all major array slices
Gets a sequence of all major array slices
Protocol for determining if an array is sparse
Protocol for determining if an array is sparse
(is-sparse? m)Protocol for construction of special matrices.
Protocol for construction of special matrices.
(diagonal-matrix m diagonal-values)Create a diagonal matrix with the specified leading diagonal values
Create a diagonal matrix with the specified leading diagonal values
(identity-matrix m dims)Create a 2D identity matrix with the given number of dimensions
Create a 2D identity matrix with the given number of dimensions
Protocol to support element-wise squaring of a numerical array.
Protocol to support element-wise squaring of a numerical array.
(square m)Protocol to get a subarray of another array. dim-ranges should be a sequence of [start len] pairs, one for each dimension. If a pair is nil, it should be interpreted to take the whole dimension.
Returning a mutable view is preferred, if the implementation supports this.
Protocol to get a subarray of another array. dim-ranges should be a sequence of [start len] pairs, one for each dimension. If a pair is nil, it should be interpreted to take the whole dimension. Returning a mutable view is preferred, if the implementation supports this.
(submatrix d dim-ranges)Protocol for getting a sub-vector view of a vector. Must return a mutable view if the original vector is mutable. Should throw an exception if the specified subvector is out of bounds for the target vector.
Protocol for getting a sub-vector view of a vector. Must return a mutable view if the original vector is mutable. Should throw an exception if the specified subvector is out of bounds for the target vector.
(subvector m start length)Protocol to support the summing of all elements in an array. The array must hold numeric values only, or an exception will be thrown.
Protocol to support the summing of all elements in an array. The array must hold numeric values only, or an exception will be thrown.
(element-sum m)Protocol for array transpose operation
Protocol for array transpose operation
(transpose m)Returns the transpose of a matrix. Equivalent to reversing the "shape". Note that:
Returns the transpose of a matrix. Equivalent to reversing the "shape". Note that: - The transpose of a scalar is the same scalar - The transpose of a 1D vector is the same 1D vector - The transpose of a 2D matrix swaps rows and columns
Protocol for mutable 2D matrix transpose in place
Protocol for mutable 2D matrix transpose in place
(transpose! m)Transposes a mutable 2D matrix in place
Transposes a mutable 2D matrix in place
Protocol for querying the type of matrix elements. If not provided, the default implementation will return java.lang.Object, and the matrix object must accept any type of value. If a matrix is primitive-backed, it should return the appropriate primitive type e.g. Double/TYPE.
Protocol for querying the type of matrix elements. If not provided, the default implementation will return java.lang.Object, and the matrix object must accept any type of value. If a matrix is primitive-backed, it should return the appropriate primitive type e.g. Double/TYPE.
(element-type m)Optional protocol to validate the shape of a matrix. If the matrix has an incorrect shape, should throw an error. Otherwise it should return the correct shape.
Optional protocol to validate the shape of a matrix. If the matrix has an incorrect shape, should throw an error. Otherwise it should return the correct shape.
(validate-shape m)Protocol for comparing two arrays, with the semantics of clojure.core/=. Returns false if the arrays are not of equal shape, or if any elements are not equal.
Protocol for comparing two arrays, with the semantics of clojure.core/=. Returns false if the arrays are not of equal shape, or if any elements are not equal.
(value-equals m a)(cross-product a b)Cross product of two vectors
Cross product of two vectors
(cross-product! a b)Calculate cross product of two vectors, storing the result in the first vector
Calculate cross product of two vectors, storing the result in the first vector
(distance a b)Euclidean distance of two vectors.
Euclidean distance of two vectors.
Protocol to return an array as a flattened vector of all elements. Implementations are encouraged to avoid taking a full copy of all data (e.g. by using structural sharing or views).
Protocol to return an array as a flattened vector of all elements. Implementations are encouraged to avoid taking a full copy of all data (e.g. by using structural sharing or views).
(to-vector m)Returns an array as a single flattened vector
Returns an array as a single flattened vector
Protocol to support common numerical vector operations.
Protocol to support common numerical vector operations.
(length a)Euclidian length of a vector.
Euclidian length of a vector.
(length-squared a)Squared Euclidean length of a vector.
Squared Euclidean length of a vector.
(normalise a)Returns a new vector, normalised to length 1.0
Returns a new vector, normalised to length 1.0
(vector-dot a b)Numerical dot product of two vectors. Must return a scalar value if the two parameters are vectors of equal length.
If the vectors are of unequal length, should throw an exception (however returning nil is also acceptable).
Otherwise the implementation may optionally either return nil or compute a higher dimensional inner-product (if it is able to do so).
Numerical dot product of two vectors. Must return a scalar value if the two parameters are vectors of equal length. If the vectors are of unequal length, should throw an exception (however returning nil is also acceptable). Otherwise the implementation may optionally either return nil or compute a higher dimensional inner-product (if it is able to do so).
Protocol to support transformation of a vector to another vector. Is equivalent to matrix multiplication when 2D matrices are used as transformations. But other transformations are possible, e.g. affine transformations.
A transformation need not be a core.matrix matrix: other types are permissible
Protocol to support transformation of a vector to another vector. Is equivalent to matrix multiplication when 2D matrices are used as transformations. But other transformations are possible, e.g. affine transformations. A transformation need not be a core.matrix matrix: other types are permissible
(vector-transform t v)Transforms a vector
Transforms a vector
(vector-transform! t v)Transforms a vector in place - mutates the vector argument
Transforms a vector in place - mutates the vector argument
(as-vector m)Returns a view of an array as a single flattened vector. May return the vector itself if it is already a 1D vector.
Returns a view of an array as a single flattened vector. May return the vector itself if it is already a 1D vector.
Protocol for counting the number of zeros in an array
Protocol for counting the number of zeros in an array
(zero-count m)Protocol for accessing the scalar value in zero-dimensional arrays. Zero dimensional arrays differ from scalar values in the following two senses:
Protocol for accessing the scalar value in zero-dimensional arrays. Zero dimensional arrays differ from scalar values in the following two senses: - They may be mutable (in which case set-0d! is expected to work) - They are not considered themselves to be scalars. Hence you must use get-0d to access the contained scalar value
(get-0d m)(set-0d! m value)(new-scalar-array m)(new-scalar-array m value)Construct a new zero-dimensional array with the specified scalar value (zero if not specified)
Construct a new zero-dimensional array with the specified scalar value (zero if not specified)
Protocol for setting the scalar value in zero-dimensional arrays.
Protocol for setting the scalar value in zero-dimensional arrays.
(set-0d m value)Sets the scalar value in a 0-d array, returning a new 0-d array
Sets the scalar value in a 0-d array, returning a new 0-d array
(same-shapes? arrays)Returns true if a sequence of arrays all have the same shape.
Returns true if a sequence of arrays all have the same shape.
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 |