This is the array-operations Reference Manual, version 1.2.1, generated automatically by Declt version 4.0 beta 2 "William Riker" on Sun Dec 15 04:17:20 2024 GMT+0.
array-operations
array-operations/all
array-operations/generic
array-operations/reducing
array-operations/matrices
array-operations/creating
array-operations/utilities
array-operations/indexing
array-operations/displacing
array-operations/transforming
array-operations/stacking
array-operations/array-operations.asd
array-operations/all/file-type.lisp
array-operations/generic/file-type.lisp
array-operations/reducing/file-type.lisp
array-operations/matrices/file-type.lisp
array-operations/creating/file-type.lisp
array-operations/utilities/file-type.lisp
array-operations/indexing/file-type.lisp
array-operations/displacing/file-type.lisp
array-operations/transforming/file-type.lisp
array-operations/stacking/file-type.lisp
array-operations/matrices
array-operations/transforming
array-operations/reducing
array-operations/utilities
array-operations/creating
array-operations/all
array-operations/stacking
array-operations/indexing
array-operations/displacing
array-operations/generic
The main system appears first, followed by any subsystem dependency.
array-operations
array-operations/all
array-operations/generic
array-operations/reducing
array-operations/matrices
array-operations/creating
array-operations/utilities
array-operations/indexing
array-operations/displacing
array-operations/transforming
array-operations/stacking
array-operations
Array operations library for Common Lisp
Array operations for array-like data structures
Steve Nunez <steve@symbolics.tech>
Tamas K. Papp <tkpapp@gmail.com>
MS-PL
The array-operations system is a collection of functions and macros for manipulating Common Lisp arrays and performing numerical calculations with them. It is extendible to array-like data structures, such as data frames. It is a core system for solving linear systems of equations in common lisp.
Array-operations is a ’generic’ way of operating on array like data structures using a syntax that is natural for Common Lisp. Several aops functions have been implemented for data-frame. For those that haven’t, you can transform arrays to data frames using the df:matrix-df function, and a data-frame to an array using df:as-array. This make it convenient to work with the data sets using either system.
1.2.1
let-plus
(system).
array-operations/all
(system).
array-operations/all
Array operations for array-like data structures
Steve Nunez <steve@symbolics.tech>
Tamas K. Papp <tkpapp@gmail.com>
MS-PL
array-operations/generic
(system).
array-operations/reducing
(system).
array-operations/matrices
(system).
array-operations/creating
(system).
array-operations/indexing
(system).
array-operations/displacing
(system).
array-operations/transforming
(system).
array-operations/stacking
(system).
array-operations/generic
Array operations for array-like data structures
Steve Nunez <steve@symbolics.tech>
Tamas K. Papp <tkpapp@gmail.com>
MS-PL
let-plus
(system).
array-operations/reducing
Array operations for array-like data structures
Steve Nunez <steve@symbolics.tech>
Tamas K. Papp <tkpapp@gmail.com>
MS-PL
array-operations/matrices
Array operations for array-like data structures
Steve Nunez <steve@symbolics.tech>
Tamas K. Papp <tkpapp@gmail.com>
MS-PL
array-operations/generic
(system).
alexandria
(system).
array-operations/creating
Array operations for array-like data structures
Steve Nunez <steve@symbolics.tech>
Tamas K. Papp <tkpapp@gmail.com>
MS-PL
array-operations/generic
(system).
array-operations/utilities
(system).
array-operations/utilities
Array operations for array-like data structures
Steve Nunez <steve@symbolics.tech>
Tamas K. Papp <tkpapp@gmail.com>
MS-PL
array-operations/generic
(system).
alexandria
(system).
array-operations/indexing
Array operations for array-like data structures
Steve Nunez <steve@symbolics.tech>
Tamas K. Papp <tkpapp@gmail.com>
MS-PL
array-operations/generic
(system).
array-operations/utilities
(system).
array-operations/displacing
Array operations for array-like data structures
Steve Nunez <steve@symbolics.tech>
Tamas K. Papp <tkpapp@gmail.com>
MS-PL
array-operations/generic
(system).
array-operations/utilities
(system).
alexandria
(system).
array-operations/transforming
Array operations for array-like data structures
Steve Nunez <steve@symbolics.tech>
Tamas K. Papp <tkpapp@gmail.com>
MS-PL
array-operations/generic
(system).
array-operations/utilities
(system).
array-operations/displacing
(system).
alexandria
(system).
array-operations/stacking
Array operations for array-like data structures
Steve Nunez <steve@symbolics.tech>
Tamas K. Papp <tkpapp@gmail.com>
MS-PL
array-operations/generic
(system).
array-operations/utilities
(system).
array-operations/displacing
(system).
array-operations/transforming
(system).
alexandria
(system).
Files are sorted by type and then listed depth-first from the systems components trees.
array-operations/array-operations.asd
array-operations/all/file-type.lisp
array-operations/generic/file-type.lisp
array-operations/reducing/file-type.lisp
array-operations/matrices/file-type.lisp
array-operations/creating/file-type.lisp
array-operations/utilities/file-type.lisp
array-operations/indexing/file-type.lisp
array-operations/displacing/file-type.lisp
array-operations/transforming/file-type.lisp
array-operations/stacking/file-type.lisp
array-operations/array-operations.asd
array-operations
(system).
array-operations/all/file-type.lisp
array-operations/all
(system).
array-operations/generic/file-type.lisp
array-operations/generic
(system).
array-operations/reducing/file-type.lisp
array-operations/reducing
(system).
argmax
(function).
argmin
(function).
best
(function).
most
(function).
vectorize-reduce
(macro).
array-operations/matrices/file-type.lisp
array-operations/matrices
(system).
array-matrix
(type).
matrixp
(function).
square-matrix-p
(function).
array-operations/creating/file-type.lisp
array-operations/creating
(system).
fill!
(function).
generate
(function).
generate*
(function).
linspace
(function).
linspace!
(function).
linspace*
(function).
ones
(function).
ones!
(function).
ones*
(function).
rand
(function).
rand!
(function).
rand*
(function).
randn
(function).
randn!
(function).
randn*
(function).
similar-array
(function).
zeros
(function).
zeros!
(function).
zeros*
(function).
array-operations/utilities/file-type.lisp
array-operations/utilities
(system).
ensure-dimensions
(function).
multf
(macro).
nested-loop
(macro).
product
(function).
same-dimensions-p
(function).
walk-subscripts
(macro).
walk-subscripts-list
(macro).
array-operations/indexing/file-type.lisp
array-operations/indexing
(system).
each-index
(macro).
each-index!
(macro).
each-index*
(macro).
reduce-index
(macro).
sum-index
(macro).
find-array-dimensions
(function).
foreach
(macro).
array-operations/displacing/file-type.lisp
array-operations/displacing
(system).
combine
(function).
copy-into
(function).
displace
(function).
fill-in-dimensions
(function).
flatten
(function).
partition
(function).
(setf partition)
(function).
reshape
(function).
reshape-col
(function).
reshape-row
(function).
split
(function).
sub
(function).
(setf sub)
(function).
subvec
(function).
(setf subvec)
(function).
sub-location%
(function).
array-operations/transforming/file-type.lisp
array-operations/transforming
(system).
array-index-row-major
(function).
check-permutation
(function).
coercing
(function).
complement-permutation
(function).
complete-permutation
(function).
each
(function).
each*
(function).
identity-permutation-p
(function).
invert-permutation
(function).
map-array
(method).
margin
(function).
margin*
(function).
outer
(function).
outer*
(function).
permutation-incompatible-rank
(condition).
permutation-invalid-index
(condition).
permutation-repeated-index
(condition).
permute
(function).
recycle
(function).
turn
(function).
vectorize
(macro).
vectorize!
(macro).
vectorize*
(macro).
array-rank-element
(type).
permutation-flags
(function).
array-operations/stacking/file-type.lisp
array-operations/stacking
(system).
copy-row-major-block
(function).
stack
(function).
stack*
(function).
stack-cols
(function).
stack-cols*
(function).
stack-cols-copy
(generic function).
stack-rows
(function).
stack-rows*
(function).
stack-rows-copy
(generic function).
stack*0
(function).
Packages are listed by definition order.
array-operations/matrices
array-operations/transforming
array-operations/reducing
array-operations/utilities
array-operations/creating
array-operations/all
array-operations/stacking
array-operations/indexing
array-operations/displacing
array-operations/generic
array-operations/matrices
Functions for representing matrices as 2D arrays. A matrix is a two-dimensional array often used for linear algebra. See also the matrix functions in NUM-UTILS, which should be migrated to AOPS.
array-operations/generic
.
common-lisp
.
array-matrix
(type).
matrix?
(function).
matrixp
(function).
square-matrix-p
(function).
square-matrix?
(function).
array-operations/transforming
Functions for transforming arrays in various ways.
array-index-row-major
(function).
check-permutation
(function).
coercing
(function).
complement-permutation
(function).
complete-permutation
(function).
each
(function).
each*
(function).
identity-permutation-p
(function).
identity-permutation?
(function).
invert-permutation
(function).
map-array
(generic function).
margin
(function).
margin*
(function).
outer
(function).
outer*
(function).
permutation-incompatible-rank
(condition).
permutation-invalid-index
(condition).
permutation-repeated-index
(condition).
permute
(function).
recycle
(function).
turn
(function).
vectorize
(macro).
vectorize!
(macro).
vectorize*
(macro).
array-rank-element
(type).
permutation-flags
(function).
array-operations/reducing
Functions for reducing arrays, or performing reducing like operations over the elements of an array.
common-lisp
.
argmax
(function).
argmin
(function).
best
(function).
most
(function).
vectorize-reduce
(macro).
array-operations/utilities
array-operations/generic
.
common-lisp
.
ensure-dimensions
(function).
multf
(macro).
nested-loop
(macro).
product
(function).
same-dimensions-p
(function).
walk-subscripts
(macro).
walk-subscripts-list
(macro).
array-operations/creating
Functions for creating arrays or data frames filled with various values.
array-operations/generic
.
array-operations/utilities
.
common-lisp
.
fill!
(function).
generate
(function).
generate*
(function).
linspace
(function).
linspace!
(function).
linspace*
(function).
make-array-like
(function).
ones
(function).
ones!
(function).
ones*
(function).
rand
(function).
rand!
(function).
rand*
(function).
randn
(function).
randn!
(function).
randn*
(function).
similar-array
(function).
zeros
(function).
zeros!
(function).
zeros*
(function).
array-operations/all
This top level package re-exports the individual packages: generic, reducing, matrices, creating, indexing, displacing, transforming and stacking. It does not export utilities. The reason for this structure is the use of the ASDF package-inferred-system, where each file is its own package. None of Papp’s other libraries use this, and it seems to have been added after he abandoned the library.
array-operations
aops
array-operations/stacking
Functions for composing arrays into new arrays, by stacking.
One may think of stacking blocks as the guiding metaphor.
For example, stack two row vectors to yield a 2x2 matrix:
(stack-rows #(1 2) #(3 4)) -> #2A((1 2)
(3 4))
copy-row-major-block
(function).
stack
(function).
stack*
(function).
stack-cols
(function).
stack-cols*
(function).
stack-cols-copy
(generic function).
stack-rows
(function).
stack-rows*
(function).
stack-rows-copy
(generic function).
stack*0
(function).
array-operations/indexing
Macros for operating over indexes of arrays.
array-operations/generic
.
array-operations/utilities
.
common-lisp
.
each-index
(macro).
each-index!
(macro).
each-index*
(macro).
reduce-index
(macro).
sum-index
(macro).
find-array-dimensions
(function).
foreach
(macro).
array-operations/displacing
Functions that return arrays displaced in various ways from another array.
array-operations/generic
.
array-operations/utilities
.
common-lisp
.
combine
(function).
copy-into
(function).
displace
(function).
fill-in-dimensions
(function).
flatten
(function).
partition
(function).
(setf partition)
(function).
reshape
(function).
reshape-col
(function).
reshape-row
(function).
split
(function).
sub
(function).
(setf sub)
(function).
subvec
(function).
(setf subvec)
(function).
sub-location%
(function).
Definitions are sorted by export status, category, package, and then by lexicographic order.
Dimensions of array-like object.
Given one or more symbols INDEX, walks the BODY expression to determine the index ranges by looking for AREF and ROW-MAJOR-AREF calls.
Transpose of 2D array A
(each-index (i j)
(aref A j i))
Diagonal of a square 2D array
(each-index i (aref A i i))
Turn a 2D array into an array of arrays
(each-index i
(each-index j
(aref A i j)))
Matrix-vector product:
(each-index i
(sum-index j
(* (aref A i j) (aref x j))))
Sets elements of the given ARRAY to values of the BODY, evaluated at array indices INDEX
Note: This has the same semantics as each-index and each-index*,
but the INDEX ranges are taken from the ARRAY dimensions, not
a code walker.
Given one or more symbols INDEX, creates an array with ELEMENT-TYPE, then iterates over the index ranges with the innermost loop using the last index.
Each iteration evaluates BODY, and sets the array element.
To find the range of the indices, walks the BODY expression
to determine the index ranges by looking for
AREF and ROW-MAJOR-AREF calls.
Transpose of 2D array A
(each-index* t (i j)
(aref A j i))
Diagonal of a square 2D array
(each-index* t i (aref A i i))
Turn a 2D array into an array of arrays
(each-index* t i
(each-index* t j
(aref A i j)))
Outer product of two 1D arrays to create a 2D array
(each-index* t (i j)
(* (aref x i) (aref y j)))
Matrix-vector product:
(each-index* t i
(sum-index j
(* (aref A i j) (aref x j))))
Multiply by the arguments
Iterates over a multidimensional range of indices.
SYMS must be a list of symbols, with the first symbol
corresponding to the outermost loop.
DIMENSIONS will be evaluated, and must be a list of
dimension sizes, of the same length as SYMS.
Example:
(nested-loop (i j) ’(10 20) (format t ’~a ~a~%’ i j))
expands to:
; Check dimensions
(destructuring-bind (g1 g2) ’(10 20)
(loop for i from 0 below g1 do
(loop for j from 0 below g2 do
(format t ’~a ~a~%’ i j))))
with some additional type and dimension checks.
Reduction over one or more INDEX symbols in an array expression.
The range of these symbols is determined by walking the tree
for AREF and ROW-MAJOR-AREF calls.
Example:
(defparameter A #2A((1 2) (3 4)))
(reduce-index #’+ i (row-major-aref A i)) ; Sum all elements (sum-index)
=> 10
(reduce-index #’* (i j) (aref A i j)) ; Multiply all elements
=> 24
(reduce-index #’max i (row-major-aref A i)) ; Maxmum value
=> 4
Sums over one or more INDEX symbols in an array expression.
The range of these symbols is determined by walking the tree
for AREF and ROW-MAJOR-AREF calls.
Example:
(defparameter A #2A((1 2) (3 4)))
(sum-index i (row-major-aref A i)) ; Sum all elements
=> 10
(sum-index (i j) (aref A i j)) ; Sum all elements
=> 10
(sum-index i (aref A i i)) ; Trace of array
=> 5
Makes a new array of type ELEMENT-TYPE, containing the result of an array expression. All input and outputs have the same shape, and BODY is evaluated for each index
VARIABLES must be a list of symbols bound to arrays.
Each array must have the same dimensions. These are
checked at compile and run-time respectively.
(let ((a #2A((1 2) (3 4))))
(vectorize (a) (+ a 1)))
-> #2A((2 3) (4 5))
(let ((a #(1 2 3))
(b #(4 5 6)))
(vectorize (a b) (+ a (* b 2))))
-> #(9 12 15)
Fills an array RESULT with the result of an array expression. All input and outputs have the same shape, and BODY is evaluated for each index
VARIABLES must be a list of symbols bound to arrays. Each array must have the same dimensions. These are checked at compile and run-time respectively.
(let ((a #2A((1 2) (3 4)))
(b (make-array ’(2 2))))
(vectorize! b (a) (+ a 1)))
-> #2A((2 3) (4 5))
(let ((a #(1 2 3))
(b #(4 5 6)))
(vectorize! b (a b) (+ a (* b 2))))
-> #(9 12 15)
Makes a new array of type ELEMENT-TYPE, containing the result of an array expression. All input and outputs have the same shape, and BODY is evaluated for each index
VARIABLES must be a list of symbols bound to arrays.
Each array must have the same dimensions. These are
checked at compile and run-time respectively.
(let ((a #2A((1 2) (3 4))))
(vectorize* t (a) (+ a 1)))
-> #2A((2 3) (4 5))
(let ((a #(1 2 3))
(b #(4 5 6)))
(vectorize* t (a b) (+ a (* b 2))))
-> #(9 12 15)
Performs a reduction using FN over all elements in a vectorized expression
on array VARIABLES.
VARIABLES must be a list of symbols bound to arrays.
Each array must have the same dimensions. These are
checked at compile and run-time respectively.
Example: Maximum value in an array A
(vectorize-reduce #’max (a) a)
Example: Maximum absolute difference between two arrays A and B
(vectorize-reduce #’max (a b) (abs (- a b)))
Iterate over the subscripts of an array with given DIMENSIONS. SUBSCRIPTS contains the current subscripts as a vector of fixnums, POSITION has the row-major index. Consequences are undefined if either POSITION or SUBSCRIPTS is modified.
Like WALK-SUBSCRIPTS, but SUBSCRIPTS is a newly created list for each position that does not share structure and can be freely used/modified/kept etc.
Find the row-major-aref in ARRAY with the maximum value Returns both the index and the value of ARRAY at that index
Find the row-major-aref in ARRAY with the minimum value Returns both the index and the value of ARRAY at that index
https://groups.google.com/g/comp.lang.lisp/c/CM3MQkyOTHk/m/Pl4KPUqfobwJ Modified into a destructive, non-consing version. RESULT, if provided, must be a list of length equal to the rank of the array; it is modified to contain the result of the function. This way, the result list can be allocated only once and additionally be DX for zero consing. If RESULT is not provided, then it is consed and then returned.
FN must accept two inputs and return true/false. This function is applied
to elements of ARRAY, to find the ’best’. The row-major-aref index is returned.
Example: The index of the maximum is
* (best #’> #(1 2 3 4))
3 ; row-major index
4 ; value
This function was adapted from Paul Graham’s On Lisp
Check if PERMUTATION is a valid permutation (of the given RANK), and signal an error if necessary.
Return a function composed of a univariate function that coerces to ELEMENT-TYPE and function. When FUNCTION is not given, return a closure that coerces to ELEMENT-TYPE.
The opposite of SUBARRAYS.
If ELEMENT-TYPE is not given, it is inferred from the first element of array, which also determines the dimensions. If that element is not an array, the original ARRAY is returned as it is.
Return a list of increasing indices that complement PERMUTATION, i.e. form a permutation when appended. Atoms are accepted and treated as lists of a single element.
Return a completed version of permutation, appending it to its complement.
Copy SOURCE into TARGET, for array arguments of compatible dimensions (checked). Return TARGET, making the implementation of the semantics of SETF easy.
Copy elements with row major indexes between the given start and end from SOURCE to DESTINATION, respectively. Elements are coerced to ELEMENT-TYPE when necessary. Return no values.
This function should be used to implement copying of contiguous row-major blocks of elements, most optimizations should happen here.
Shorthand function for displacing an array.
Like EACH*, with ELEMENT-TYPE T.
Apply function to the array arguments elementwise, and return the result as an array with the given ELEMENT-TYPE. Arguments are checked for dimension compatibility.
Return a list of dimensions corresponding to OBJECT. Positive integers are
treated as dimensions of rank 1, lists are returned as they are, and arrays
are queried for their dimensions.
OBJECTS accepted by this function as valid dimensions are called ‘dimension specifications’ in this library.
Fills a given ARRAY with VALUE, coerced to the same element type as ARRAY
If one of the dimensions is missing (indicated with T), replace it with a dimension so that the total product equals SIZE. If that’s not possible, signal an error. If there are no missing dimensions, just check that the product equals size. Also accepts other dimension specifications (integer, array).
Return ARRAY flattened to a vector. Will share structure.
Like GENERATE*, with ELEMENT-TYPE T.
Return an array with given DIMENSIONS and ELEMENT-TYPE, with elements generated by calling FUNCTION.
Function is called with:
- no arguments, when ARGUMENTS is nil
- the position (= row major index), when ARGUMENTS is :POSITION
- a list of subscripts, when ARGUMENTS is :SUBSCRIPTS
- both when ARGUMENTS is :POSITION-AND-SUBSCRIPTS
The traversal order is unspecified and may be nonlinear.
Test if PERMUTATION is the identity permutation, i.e. a sequence of consecutive integers starting at 0. Note that permutation is otherwise not checked, i.e. it may not be a permutation.
Test if PERMUTATION is the identity permutation, i.e. a sequence of consecutive integers starting at 0. Note that permutation is otherwise not checked, i.e. it may not be a permutation.
Invert a permutation.
Make a vector of N elements containing evenly spaced numbers over an interval. The first element is equal to START and last element STOP, with constant difference between consecutive elements. Elements are of type T, unless ELEMENT-TYPE is given
(linspace 0 4 5) -> #(0 1 2 3 4)
(linspace 1 3 5) -> #(0 1/2 1 3/2 2)
(linspace 0 4d0 3) -> #(0.0d0 2.0d0 4.0d0)
Fill an array with evenly spaced numbers over an interval. The first element is equal to START and last element STOP, with constant difference between consecutive elements in ROW-MAJOR-INDEX.
Make a vector of N elements and type ELEMENT-TYPE, containing evenly spaced numbers over an interval. The first element is equal to START and last element STOP, with constant difference between consecutive elements.
Returns new array with the same properties as ARRAY.
Keyword arguments will override properties of ARRAY.
If INITIAL-ELEMENT is specified, it is coerced to ELEMENT-TYPE.
Like MARGIN*, with ELEMENT-TYPE T.
PERMUTE ARRAY with ‘(,@OUTER ,@INNER), split the inner subarrays, apply FUNCTION to each, return the results in an array of dimensions OUTER, with the given ELEMENT-TYPE.
Return NIL if MATRIX does not have rank 2.
Return NIL if MATRIX does not have rank 2.
Finds the element of ARRAY that returns the value closest to positive infinity when FN is applied to the array value.
Returns the row-major-aref index, and the winning value.
Example: The maximum of an array is
(most #’identity #(1 2 3))
-> 2 (row-major index)
3 (value)
Minimum of an array is
(most #’- #(1 2 3))
0
-1
This function was adapted from Paul Graham’s On Lisp
Makes an array of shape DIMENSIONS filled with ones. Elements are of type T, unless ELEMENT-TYPE is given.
Fills the given ARRAY with 1’s, coerced to the element type. Returns ARRAY.
Makes an array of shape DIMENSIONS and type ELEMENT-TYPE, filled with ones coerced to the specified type ELEMENT-TYPE.
Like OUTER, with ELEMENT-TYPE t.
Generalized outer product of ARRAYS with FUNCTION. The resulting array has the concatenated dimensions of ARRAYS, and the given ELEMENT-TYPE.
Return a subset of the array, on the first indexes between START and END.
Return ARRAY with the axes permuted by PERMUTATION, which is a sequence of indexes. Specifically, an array A is transformed to B, where
B[b_1,...,b_n] = A[a_1,...,a_n] with b_i=a_{P[i]}
P is the permutation.
Array element type is preserved.
Product of elements in the argument. NOT EXPORTED.
Makes an array of shape DIMENSIONS filled with random numbers uniformly distributed between 0 and 1. Elements are of type T, unless ELEMENT-TYPE is given.
Uses the built-in RANDOM function.
(rand 3) -> #(0.39319038 0.69693553 0.5021677)
(rand ’(2 2)) -> #2A((0.91003513 0.23208928) (0.5577954 0.94657767))
NOTE: If it’s important that these numbers are really random (e.g. cryptographic applications), then you should probably not use this function.
Fills a given ARRAY with random numbers, uniformly distributed between 0 and 1. Uses the built-in RANDOM function. Returns ARRAY.
Makes an array of shape DIMENSIONS and type ELEMENT-TYPE, filled with random numbers uniformly distributed between 0 and 1.
Uses the built-in RANDOM function.
(rand 3) -> #(0.39319038 0.69693553 0.5021677)
(rand ’(2 2)) -> #2A((0.91003513 0.23208928) (0.5577954 0.94657767))
NOTE: If it’s important that these numbers are really random (e.g. cryptographic applications), then you should probably not use this function.
Creates an array of shape DIMENSIONS and type T, and fills with normally distributed numbers with a mean of zero and standard deviation of 1
Uses the Box-Muller algorithm and built-in random number generator.
(rand 3) -> #(-0.82067037 -0.60068226 -0.21494178)
(randn ’(2 2)) -> #2A((1.6905352 -2.5379088) (0.8461403 -1.505984))
NOTE: If it’s important that these numbers are really random (e.g. cryptographic applications), then you should probably not use this function.
Fills ARRAY with normally distributed numbers with a mean of zero and standard deviation of 1
Uses the Box-Muller algorithm and built-in random number generator.
NOTE: If it’s important that these numbers are really random (e.g. cryptographic applications), then you should probably not use this function.
Creates an array of shape DIMENSIONS and type ELEMENT-TYPE, and fills with normally distributed numbers with a mean of zero and standard deviation of 1
Uses the Box-Muller algorithm and built-in random number generator.
(rand 3) -> #(-0.82067037 -0.60068226 -0.21494178)
(randn ’(2 2)) -> #2A((1.6905352 -2.5379088) (0.8461403 -1.505984))
NOTE: If it’s important that these numbers are really random
(e.g. cryptographic applications), then you should probably
not use this function.
Recycle elements of OBJECT, extending the dimensions by outer (repeating OBJECT) and inner (repeating each element of OBJECT). When both INNER and OUTER are nil, the OBJECT is returned as is. Non-array OBJECTs are interpreted as rank 0 arrays, following the usual semantics.
Reshape ARRAY using DIMENSIONS (which can also be dimension specifications).
If DIMENSIONS is a list, it may contain a single element T which will be calculated to match the total size of the resulting array.
Array reshaped as an Nx1 matrix.
Array reshaped as an 1xN matrix.
Test if arguments have the same dimensions. NOT EXPORTED.
Returns new array with the same properties as ARRAY.
Keyword arguments will override properties of ARRAY.
If INITIAL-ELEMENT is specified, it is coerced to ELEMENT-TYPE.
Return an array of subarrays, split off at RANK. All subarrays are displaced and share structure.
Test if MATRIX has two dimensions and that they are equal.
Test if MATRIX has two dimensions and that they are equal.
Like STACK*, with element-type T.
Stack array arguments along AXIS. ELEMENT-TYPE determines the element-type of the result.
Like STACK-COLS*, with ELEMENT-TYPE T.
Stack OBJECTS column-wise into an array of the given ELEMENT-TYPE, coercing if necessary. Always return a simple array of rank 2.
How objects are used depends on their dimensions, queried by DIMS:
- when the object has 0 dimensions, fill a column with the element.
- when the object has 1 dimension, use it as a column.
- when the object has 2 dimensions, use it as a matrix.
When applicable, compatibility of dimensions is checked, and the result is used to determine the number of rows. When all objects have 0 dimensions, the result has one row.
Like STACK-ROWS*, with ELEMENT-TYPE T.
Stack OBJECTS row-wise into an array of the given ELEMENT-TYPE, coercing if necessary. Always return a simple array of rank 2.
How objects are used depends on their dimensions, queried by DIMS:
- when the object has 0 dimensions, fill a row with the element.
- when the object has 1 dimension, use it as a row.
- when the object has 2 dimensions, use it as a matrix.
When applicable, compatibility of dimensions is checked, and the result is used to determine the number of columns. When all objects have 0 dimensions, the result has one column.
Given a partial list of subscripts, return the subarray that starts there, with all the other subscripts set to 0, dimensions inferred from the original.
If no subscripts are given, the original array is returned. Implemented by displacing, may share structure.
Displaced vector between START and END.
Turns an array by a specified number of clockwise 90° rotations. The axis of rotation is specified by RANK-1 (defaulting to 0) and RANK-2 (defaulting to 1).
Make an array of shape DIMENSIONS filled with zeros. Elements are of type T, unless ELEMENT-TYPE is given.
Fills the given ARRAY with zero values, coerced to the element type. Returns ARRAY.
Makes an array of shape DIMENSIONS and type ELEMENT-TYPE, filled with zeros coerced to the specified type ELEMENT-TYPE.
Return the contents of OBJECT as an array. Exact semantics depends on OBJECT, but generally objects which contain elements in a rectilinear coordinate system should have a natural mapping to arrays.
When the second value is T, the array itself does not share structure with OBJECT, but its elements may. Otherwise, it is indeterminate whether the two objects share structure, and consequences of modifying the result are not defined. Methods are encouraged but not required to return a second value.
Return specificed dimension of ARRAY.
Return a list of dimensions.
For non-array objects, SIZE, DIM, NROW and NCOL use this method by default, so it is enough to define it (unless efficiency is a concern).
When DIMS is not defined for an object, it falls back to as-array, which may be very inefficient for objects which need to be consed. It is always advisable to define DIMS.
Return TYPE such that
1. all elements of ARRAY are guaranteed to be a subtype of TYPE,
2. if applicable, elements of ARRAY can be set to values which are of a type that is a subtype of TYPE.
Apply FUNCTION to each element of ARRAY
Return a new array, or write into the optional 3rd argument.
Number of columns. Will signal an error if ARRAY is not a matrix.
Number of rows. Will signal an error if ARRAY is not a matrix.
Return the rank of ARRAY.
Return the total number of elements in array.
Method used to implement the copying of objects in STACK-COL*, by copying the elements of SOURCE to DESTINATION, starting with the column index START-COL in the latter. Elements are coerced to ELEMENT-TYPE.
This method is only called when (DIMS SOURCE) was non-nil. It is assumed that it only changes elements in DESTINATION which are supposed to be copies of SOURCE. DESTINATION is always a matrix with element-type upgraded from ELEMENT-TYPE, and its NROW should match the relevant dimension of SOURCE.
All objects have a fallback method, defined using AS-ARRAY. The only reason for defining a method is efficiency.
Method used to implement the copying of objects in STACK-ROW*, by copying the elements of SOURCE to DESTINATION, starting with the row index START-ROW in the latter. Elements are coerced to ELEMENT-TYPE.
This method is only called when (DIMS SOURCE) was non-nil. It is assumed that it only changes elements in DESTINATION which are supposed to be copies of SOURCE. DESTINATION is always a matrix with element-type upgraded from ELEMENT-TYPE, and its NCOL should match the relevant dimension of SOURCE.
All objects have a fallback method, defined using AS-ARRAY. The only reason for defining a method is efficiency.
error
.
error
.
:index
error
.
:index
Examples:
Matrix-matrix multiply
(foreach :index (i j) :sum k
:value (* (aref A i k) (aref B k j)))
Sum over vector
(foreach :sum i :value (aref A i))
Walks an expression tree EXPR, finds AREF and ROW-MAJOR-AREF, SVREF or ELT calls.
Returns a list of (symbol, expr) where EXPR is an expression which
evaluates to the array dimension size for SYMBOL.
Example:
(find-array-dimensions ’(+ (aref a i) (* 2 (aref b j k))))
-> ((I ARRAY-DIMENSION A 0) (K ARRAY-DIMENSION B 1) (J ARRAY-DIMENSION B 0))
Make a bit vector of flags with indexes from PERMUTATION, signaling errors for invalid and repeated indices. NOT EXPORTED.
Stack arrays along the 0 axis, returning an array with given ELEMENT-TYPE.
Return (values OFFSET REMAINING-DIMENSIONS) that can be used to displace a row-major subarray starting at SUBSCRIPTS in an array with the given DIMENSIONS. NOT EXPORTED.
Jump to: | &
(
A B C D E F G I L M N O P R S T V W Z |
---|
Jump to: | &
(
A B C D E F G I L M N O P R S T V W Z |
---|
Jump to: | I S |
---|
Index Entry | Section | ||
---|---|---|---|
| |||
I | |||
index : | Public conditions | ||
index : | Public conditions | ||
| |||
S | |||
Slot, index : | Public conditions | ||
Slot, index : | Public conditions | ||
|
Jump to: | I S |
---|
Jump to: | A C F P S T |
---|
Jump to: | A C F P S T |
---|