The array-operations Reference Manual

Table of Contents

Next: , Previous: , Up: (dir)   [Contents][Index]

The array-operations Reference Manual

This is the array-operations Reference Manual, generated automatically by Declt version 3.0 "Montgomery Scott" on Tue Apr 28 10:31:29 2020 GMT+0.


Next: , Previous: , Up: Top   [Contents][Index]

1 Introduction

Build Status

Introduction

This library is a collection of functions and macros for manipulating Common Lisp arrays and performing numerical calculations with them.

For example, arrays can be created:

;; uniform and normal random numbers
(rand '(2 2)) ; => #2A((0.62944734 0.2709539) (0.81158376 0.6700171))

;; linear ranges
(linspace 1 10 7) ; => #(1 5/2 4 11/2 7 17/2 10)

;; Using a function, optionally given index position
(generate #'identity '(2 3) :position) ; => #2A((0 1 2) (3 4 5))

Arrays can be manipulated:

(defparameter A #2A((1 2) (3 4)))
(defparameter B #2A((2 3) (4 5)))

;; split along any dimension
(split A 1)  ; => #(#(1 2) #(3 4))

;; stack along any dimension
(stack 1 A B) ; => #2A((1 2 2 3) (3 4 4 5))

;; element-wise function map
(each #'+ #(0 1 2) #(2 3 5)) ; => #(2 4 7)

;; element-wise expressions
(vectorize (A B) (* A (sqrt B))) ; => #2A((1.4142135 3.4641016) (6.0 8.944272))

;; index operations e.g. matrix-matrix multiply:
(each-index (i j)
  (sum-index k
    (* (aref A i k) (aref B k j)))) ; => #2A((10 13) (22 29))

Installation

This library is on QuickLisp:

  (ql:quickload :array-operations)

To get the latest version, clone into your Quicklisp local project directory:

  $ git clone https://github.com/bendudson/array-operations.git ~/quicklisp/local-projects/

Then load as above with (ql:quickload :array-operations).

To run the test suite (using clunit):

  (ql:quickload :array-operations-tests)
  (array-operations-tests:run)

Notes:

A quick tour of the library

Shorthand for frequently used Common Lisp array functions

The library defines the following short function names that are synomyms for Common Lisp operations:

array-operations | Common Lisp ------------------ | ------------------------------- size | array-total-size rank | array-rank dim | array-dimension dims | array-dimensions nrow | number of rows in matrix ncol | number of columns in matrix

The array-operations package has the nickname aops, so you can use, for example, (aops:size my-array) without use'ing the package.

Displaced arrays for fun and profit

displaced array n. an array which has no storage of its own, but which is instead indirected to the storage of another array, called its target, at a specified offset, in such a way that any attempt to access the displaced array implicitly references the target array. (CLHS Glossary)

Displaced arrays are one of the niftiest features of Common Lisp. When an array is displaced to another array, it shares structure with (part of) that array. The two arrays do not need to have the same dimensions, in fact, the dimensions do not be related at all as long as the displaced array fits inside the original one. The row-major index of the former in the latter is called the offset of the displacement.

Displaced arrays are usually constructed using make-array, but this library also provides displace for that purpose:

  (defparameter *a* #2A((1 2 3) (4 5 6)))
  (aops:displace *a* 2 1) ; => #(2 3)

flatten displaces to a row-major array:

  (aops:flatten *a*) ; => #(1 2 3 4 5 6)

The real fun starts with split, which splits off subarrays nested within a given axis:

  (aops:split *a* 1) ; => #(#(1 2 3) #(4 5 6))
  (defparameter *b* #3A(((0 1) (2 3))
                        ((4 5) (6 7))))
  (aops:split *b* 0) ; => #3A(((0 1) (2 3)) ((4 5) (6 7)))
  (aops:split *b* 1) ; => #(#2A((0 1) (2 3)) #2A((4 5) (6 7)))
  (aops:split *b* 2) ; => #2A((#(0 1) #(2 3)) (#(4 5) #(6 7)))
  (aops:split *b* 3) ; => #3A(((0 1) (2 3)) ((4 5) (6 7)))

Note how splitting at 0 and the rank of the array returns the array itself.

Now consider sub, which returns a specific array, composed of the elements that would start with given subscripts:

  (aops:sub *b* 0) ; => #2A((0 1) (2 3))
  (aops:sub *b* 0 1) ; => #(2 3)
  (aops:sub *b* 0 1 0) ; => 2

There is also a (setf sub) function.

partition returns a consecutive chunk of an array separated along its first subscript:

  (aops:partition #2A((0 1)
                    (2 3)
                    (4 5)
                    (6 7)
                    (8 9))
                1 3) ; => #2A((2 3) (4 5))

and also has a (setf partition) pair.

combine is the opposite of split:

  (aops:combine #(#(0 1) #(2 3))) ; => #2A((0 1) (2 3))

subvec returns a displaced subvector:

  (aops:subvec #(0 1 2 3 4) 2 4) ; => #(2 3)

There is also a (setf subvec) function, which is like (setf subseq) except for demanding matching lengths.

Finally, reshape can be used to displace arrays into a different shape:

  (aops:reshape *a* '(3 2)) ; => #2A((1 2) (3 4) (5 6))

You can use t for one of the dimensions, to be filled in automatically:

  (aops:reshape *b* '(1 t)) ; => #2A((0 1 2 3 4 5 6 7))

reshape-col and reshape-row reshape your array into a column or row matrix, respectively.

Dimension specifications

Functions in the library accept the following in place of dimensions:

The last one allows you to specify dimensions with other arrays. For example, to reshape an array a1 to look like a2, you can use

  (aops:reshape a1 a2)

instead of the longer form

  (aops:reshape a1 (aops:dims a2))

Array creation and transformations

When the resulting element type cannot be inferred, functions that create and transform arrays are provided in pairs: one of these will allow you to specify the array-element-type of the result, while the other assumes it is t. The former ends with a *, and the element-type is always its first argument. I give examples for the versions without *, use the other when you are optimizing your code and you are sure you can constrain to a given element-type.

Element traversal order of these functions is unspecified. The reason for this is that the library may use parallel code in the future, so it is unsafe to rely on a particular element traversal order.

The following functions all make a new array, taking the dimensions as input. The version ending in * also takes the array type as first argument. There are also versions ending in ! which do not make a new array, but take an array as first argument, which is modified and returned.

Function | Description ---------- | ------------------------------------------------------------------ zeros | Filled with zeros ones | Filled with ones rand | Filled with uniformly distrubuted random numbers between 0 and 1 randn | Normally distributed with mean 0 and standard deviation 1 linspace | Evenly spaced numbers in given range

For example:

  (aops:rand '(2 2))  ; => #2A((0.6686077 0.59425664) (0.7987722 0.6930506))

  (aops:rand* 'single-float '(2 2)) ; => #2A((0.39332366 0.5557821) (0.48831415 0.10924244))

  (let ((a (make-array '(2 2) :element-type 'double-float)))
    ;; Modify array A, filling with random numbers
    (aops:rand! a))  ; => #2A((0.6324615478515625d0 0.4636608362197876d0)
                              (0.4145939350128174d0 0.5124958753585815d0))

generate (and generate*) allow you to generate arrays using functions.

  (aops:generate (lambda () (random 10)) 3) ; => #(6 9 5)
  (aops:generate #'identity '(2 3) :position) ; => #2A((0 1 2) (3 4 5))
  (aops:generate #'identity '(2 2) :subscripts)
  ;; => #2A(((0 0) (0 1)) ((1 0) (1 1)))
  (aops:generate #'cons '(2 2) :position-and-subscripts)
  ;; => #2A(((0 0 0) (1 0 1)) ((2 1 0) (3 1 1)))

Depending on the last argument, the function will be called with the (row-major) position, the subscripts, both, or no argument.

permute can permutate subscripts (you can also invert, complement, and complete permutations, look at the docstring and the unit tests). Transposing is a special case of permute:

  (defparameter *a* #2A((1 2 3) (4 5 6)))
  (aops:permute '(0 1) *a*) ; => #2A((1 2 3) (4 5 6))
  (aops:permute '(1 0) *a*) ; => #2A((1 4) (2 5) (3 6))

each applies a function to its (array) arguments elementwise:

  (aops:each #'+ #(0 1 2) #(2 3 5)) ; => #(2 4 7)

vectorize is a macro which performs elementwise operations

  (defparameter a #(1 2 3 4))
  (aops:vectorize (a) (* 2 a)) ; => #(2 4 6 8)

  (defparameter b #(2 3 4 5))
  (aops:vectorize (a b) (* a (sin b))) ; => #(0.9092974 0.28224 -2.2704074 -3.8356972)

There is also a version vectorize* which takes a type argument for the resulting array, and a version vectorize! which sets elements in a given array.

The semantics of margin are more difficult to explain, so perhaps an example will be more useful. Suppose that you want to calculate column sums in a matrix. You could permute (transpose) the matrix, split its subarrays at rank one (so you get a vector for each row), and apply the function that calculates the sum. margin automates that for you:

  (aops:margin (lambda (column)
               (reduce #'+ column))
             #2A((0 1)
                 (2 3)
                 (5 7)) 0) ; => #(7 11)

But the function is much more general than this: the arguments inner and outer allow arbitrary permutations before splitting.

Finally, recycle allows you to recycle arrays along inner and outer dimensions:

  (aops:recycle #(2 3) :inner 2 :outer 4)
  ; => #3A(((2 2) (3 3)) ((2 2) (3 3)) ((2 2) (3 3)) ((2 2) (3 3)))

Indexing operations

nested-loop is a simple macro which iterates over a set of indices with a given range

  (defparameter A #2A((1 2) (3 4)))

  (aops:nested-loop (i j) (array-dimensions A)
    (setf (aref A i j) (* 2 (aref A i j))))
  A ; => #2A((2 4) (6 8))

  (aops:nested-loop (i j) '(2 3)
    (format t "(~a ~a) " i j)) ; => (0 0) (0 1) (0 2) (1 0) (1 1) (1 2) 

sum-index is a macro which uses a code walker to determine the dimension sizes, summing over the given index or indices

  (defparameter A #2A((1 2) (3 4)))

  ;; Trace
  (aops:sum-index i (aref A i i)) ; => 5

  ;; Sum array
  (aops:sum-index (i j) (aref A i j)) ; => 10

  ;; Sum array
  (aops:sum-index i (row-major-aref A i)) ; => 10

The main use for sum-index is in combination with each-index.

each-index is a macro which creates an array and iterates over the elements. Like sum-index it is given one or more index symbols, and uses a code walker to find array dimensions.

  (defparameter A #2A((1 2) (3 4)))
  (defparameter B #2A((5 6) (7 8)))

  ;; Transpose
  (aops:each-index (i j) (aref A j i)) ; => #2A((1 3) (2 4))

  ;; Sum columns
  (aops:each-index i
    (aops:sum-index j
      (aref A j i))) ; => #(4 6)

  ;; Matrix-matrix multiply
  (aops:each-index (i j)
     (aops:sum-index k
        (* (aref A i k) (aref B k j)))) ; => #2A((19 22) (43 50))

reduce-index is a more general version of sum-index, which applies a reduction operation over one or more indices.

  (defparameter A #2A((1 2) (3 4)))
  
  ;; Sum all values in an array
  (aops:reduce-index #'+ i (row-major-aref A i)) ; => 10
  
  ;; Maximum value in each row
  (aops:each-index i
    (aops:reduce-index #'max j
      (aref A i j)))  ; => #(2 4)

Reductions

Some reductions over array elements can be done using the CL reduce function, together with aops:flatten, which returns a displaced vector:

  (defparameter a #2A((1 2) (3 4)))
  (reduce #'max (aops:flatten a)) ; => 4

argmax and argmin find the row-major-aref index where an array is maximum or minimum. They both return two values: the first value is the index; the second is the array value at that index.

  (defparameter a #(1 2 5 4 2))
  (aops:argmax a) ; => 2 5
  (aops:argmin a) ; => 0 1

More complicated reductions can be done with vectorize-reduce, for example the maximum absolute difference between arrays:

  (defparameter a #2A((1 2) (3 4)))
  (defparameter b #2A((2 2) (1 3)))

  (aops:vectorize-reduce #'max (a b) (abs (- a b))) ; => 2

See also reduce-index above.

Scalars as 0-dimensional arrays

Library functions treat non-array objects as if they were equivalent to 0-dimensional arrays: for example, (aops:split array (rank array)) returns an array that effectively equivalent (eq) to array. Another example is recycle:

  (aops:recycle 4 :inner '(2 2)) ; => #2A((4 4) (4 4))

Stacking

You can also stack compatible arrays along any axis:

  (defparameter *a1* #(0 1 2))
  (defparameter *a2* #(3 5 7))
  (aops:stack 0 *a1* *a2*) ; => #(0 1 2 3 5 7)
  (aops:stack 1
            (aops:reshape-col *a1*)
            (aops:reshape-col *a2*)) ; => #2A((0 3) (1 5) (2 7))


Next: , Previous: , Up: Top   [Contents][Index]

2 Systems

The main system appears first, followed by any subsystem dependency.


Next: , Previous: , Up: Systems   [Contents][Index]

2.1 array-operations

Maintainer

Ben Dudson <http://github.com/bendudson>

Author

Tamas K. Papp <tkpapp@gmail.com>

Home Page

https://github.com/bendudson/array-operations

License

MIT

Description

Simple array operations library for Common Lisp.

Dependencies
Source

array-operations.asd (file)


Next: , Previous: , Up: Systems   [Contents][Index]

2.2 array-operations/all

Maintainer

Ben Dudson <http://github.com/bendudson>

Author

Tamas K. Papp <tkpapp@gmail.com>

Home Page

https://github.com/bendudson/array-operations

License

MIT

Dependencies
Source

array-operations.asd (file)

Component

lisp.lisp (file)


Next: , Previous: , Up: Systems   [Contents][Index]

2.3 array-operations/reducing

Maintainer

Ben Dudson <http://github.com/bendudson>

Author

Tamas K. Papp <tkpapp@gmail.com>

Home Page

https://github.com/bendudson/array-operations

License

MIT

Source

array-operations.asd (file)

Component

lisp.lisp (file)


Next: , Previous: , Up: Systems   [Contents][Index]

2.4 array-operations/matrices

Maintainer

Ben Dudson <http://github.com/bendudson>

Author

Tamas K. Papp <tkpapp@gmail.com>

Home Page

https://github.com/bendudson/array-operations

License

MIT

Dependencies
Source

array-operations.asd (file)

Component

lisp.lisp (file)


Next: , Previous: , Up: Systems   [Contents][Index]

2.5 array-operations/creating

Maintainer

Ben Dudson <http://github.com/bendudson>

Author

Tamas K. Papp <tkpapp@gmail.com>

Home Page

https://github.com/bendudson/array-operations

License

MIT

Dependencies
Source

array-operations.asd (file)

Component

lisp.lisp (file)


Next: , Previous: , Up: Systems   [Contents][Index]

2.6 array-operations/indexing

Maintainer

Ben Dudson <http://github.com/bendudson>

Author

Tamas K. Papp <tkpapp@gmail.com>

Home Page

https://github.com/bendudson/array-operations

License

MIT

Dependencies
Source

array-operations.asd (file)

Component

lisp.lisp (file)


Next: , Previous: , Up: Systems   [Contents][Index]

2.7 array-operations/stacking

Maintainer

Ben Dudson <http://github.com/bendudson>

Author

Tamas K. Papp <tkpapp@gmail.com>

Home Page

https://github.com/bendudson/array-operations

License

MIT

Dependencies
Source

array-operations.asd (file)

Component

lisp.lisp (file)


Next: , Previous: , Up: Systems   [Contents][Index]

2.8 array-operations/transforming

Maintainer

Ben Dudson <http://github.com/bendudson>

Author

Tamas K. Papp <tkpapp@gmail.com>

Home Page

https://github.com/bendudson/array-operations

License

MIT

Dependencies
Source

array-operations.asd (file)

Component

lisp.lisp (file)


Next: , Previous: , Up: Systems   [Contents][Index]

2.9 array-operations/displacing

Maintainer

Ben Dudson <http://github.com/bendudson>

Author

Tamas K. Papp <tkpapp@gmail.com>

Home Page

https://github.com/bendudson/array-operations

License

MIT

Dependencies
Source

array-operations.asd (file)

Component

lisp.lisp (file)


Next: , Previous: , Up: Systems   [Contents][Index]

2.10 array-operations/utilities

Maintainer

Ben Dudson <http://github.com/bendudson>

Author

Tamas K. Papp <tkpapp@gmail.com>

Home Page

https://github.com/bendudson/array-operations

License

MIT

Dependencies
Source

array-operations.asd (file)

Component

lisp.lisp (file)


Previous: , Up: Systems   [Contents][Index]

2.11 array-operations/generic

Maintainer

Ben Dudson <http://github.com/bendudson>

Author

Tamas K. Papp <tkpapp@gmail.com>

Home Page

https://github.com/bendudson/array-operations

License

MIT

Dependency

let-plus

Source

array-operations.asd (file)

Component

lisp.lisp (file)


Next: , Previous: , Up: Top   [Contents][Index]

3 Files

Files are sorted by type and then listed depth-first from the systems components trees.


Previous: , Up: Files   [Contents][Index]

3.1 Lisp


Next: , Previous: , Up: Lisp files   [Contents][Index]

3.1.1 array-operations.asd

Location

/home/quickref/quicklisp/dists/quicklisp/software/array-operations-20190710-git/array-operations.asd

Systems

Next: , Previous: , Up: Lisp files   [Contents][Index]

3.1.2 array-operations/all/lisp.lisp

Parent

array-operations/all (system)

Location

all.lisp

Packages

array-operations/all


Next: , Previous: , Up: Lisp files   [Contents][Index]

3.1.3 array-operations/reducing/lisp.lisp

Parent

array-operations/reducing (system)

Location

reducing.lisp

Packages

array-operations/reducing

Exported Definitions

Next: , Previous: , Up: Lisp files   [Contents][Index]

3.1.4 array-operations/matrices/lisp.lisp

Parent

array-operations/matrices (system)

Location

matrices.lisp

Packages

array-operations/matrices

Exported Definitions

Next: , Previous: , Up: Lisp files   [Contents][Index]

3.1.5 array-operations/creating/lisp.lisp

Parent

array-operations/creating (system)

Location

creating.lisp

Packages

array-operations/creating

Exported Definitions

Next: , Previous: , Up: Lisp files   [Contents][Index]

3.1.6 array-operations/indexing/lisp.lisp

Parent

array-operations/indexing (system)

Location

indexing.lisp

Packages

array-operations/indexing

Exported Definitions
Internal Definitions

Next: , Previous: , Up: Lisp files   [Contents][Index]

3.1.7 array-operations/stacking/lisp.lisp

Parent

array-operations/stacking (system)

Location

stacking.lisp

Packages

array-operations/stacking

Exported Definitions
Internal Definitions

stack*0 (function)


Next: , Previous: , Up: Lisp files   [Contents][Index]

3.1.8 array-operations/transforming/lisp.lisp

Parent

array-operations/transforming (system)

Location

transforming.lisp

Packages

array-operations/transforming

Exported Definitions
Internal Definitions

Next: , Previous: , Up: Lisp files   [Contents][Index]

3.1.9 array-operations/displacing/lisp.lisp

Parent

array-operations/displacing (system)

Location

displacing.lisp

Packages

array-operations/displacing

Exported Definitions
Internal Definitions

sub-location% (function)


Next: , Previous: , Up: Lisp files   [Contents][Index]

3.1.10 array-operations/utilities/lisp.lisp

Parent

array-operations/utilities (system)

Location

utilities.lisp

Packages

array-operations/utilities

Exported Definitions

Previous: , Up: Lisp files   [Contents][Index]

3.1.11 array-operations/generic/lisp.lisp

Parent

array-operations/generic (system)

Location

generic.lisp

Packages

array-operations/generic

Exported Definitions

Next: , Previous: , Up: Top   [Contents][Index]

4 Packages

Packages are listed by definition order.


Next: , Previous: , Up: Packages   [Contents][Index]

4.1 array-operations/all

Source

lisp.lisp (file)

Nicknames
Use List

Next: , Previous: , Up: Packages   [Contents][Index]

4.2 array-operations/reducing

Source

lisp.lisp (file)

Use List

common-lisp

Used By List

array-operations/all

Exported Definitions

Next: , Previous: , Up: Packages   [Contents][Index]

4.3 array-operations/matrices

Source

lisp.lisp (file)

Use List
Used By List

array-operations/all

Exported Definitions

Next: , Previous: , Up: Packages   [Contents][Index]

4.4 array-operations/creating

Source

lisp.lisp (file)

Use List
Used By List

array-operations/all

Exported Definitions

Next: , Previous: , Up: Packages   [Contents][Index]

4.5 array-operations/indexing

Source

lisp.lisp (file)

Use List
Used By List

array-operations/all

Exported Definitions
Internal Definitions

Next: , Previous: , Up: Packages   [Contents][Index]

4.6 array-operations/stacking

Source

lisp.lisp (file)

Use List
Used By List

array-operations/all

Exported Definitions
Internal Definitions

stack*0 (function)


Next: , Previous: , Up: Packages   [Contents][Index]

4.7 array-operations/transforming

Source

lisp.lisp (file)

Use List
Used By List

array-operations/all

Exported Definitions
Internal Definitions

Next: , Previous: , Up: Packages   [Contents][Index]

4.8 array-operations/displacing

Source

lisp.lisp (file)

Use List
Used By List
Exported Definitions
Internal Definitions

sub-location% (function)


Next: , Previous: , Up: Packages   [Contents][Index]

4.9 array-operations/utilities

Source

lisp.lisp (file)

Use List
Used By List
Exported Definitions

Previous: , Up: Packages   [Contents][Index]

4.10 array-operations/generic

Source

lisp.lisp (file)

Use List
Used By List
Exported Definitions

Next: , Previous: , Up: Top   [Contents][Index]

5 Definitions

Definitions are sorted by export status, category, package, and then by lexicographic order.


Next: , Previous: , Up: Definitions   [Contents][Index]

5.1 Exported definitions


Next: , Previous: , Up: Exported definitions   [Contents][Index]

5.1.1 Macros

Macro: &dims &rest DIMENSIONS

Dimensions of array-like object.

Package

array-operations/generic

Source

lisp.lisp (file)

Macro: each-index INDEX &body BODY

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))))

Package

array-operations/indexing

Source

lisp.lisp (file)

Macro: each-index! ARRAY INDEX &body BODY

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.

Package

array-operations/indexing

Source

lisp.lisp (file)

Macro: each-index* ELEMENT-TYPE INDEX &body BODY

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))))

Package

array-operations/indexing

Source

lisp.lisp (file)

Macro: multf PLACE &rest VALUES

Multiply by the arguments

Package

array-operations/utilities

Source

lisp.lisp (file)

Macro: nested-loop SYMS DIMENSIONS &body BODY

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.

Package

array-operations/utilities

Source

lisp.lisp (file)

Macro: reduce-index FUNCTION INDEX &body BODY

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

Package

array-operations/indexing

Source

lisp.lisp (file)

Macro: sum-index INDEX &body BODY

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

Package

array-operations/indexing

Source

lisp.lisp (file)

Macro: vectorize VARIABLES &body BODY

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)

Package

array-operations/transforming

Source

lisp.lisp (file)

Macro: vectorize! RESULT VARIABLES &body BODY

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)

Package

array-operations/transforming

Source

lisp.lisp (file)

Macro: vectorize* ELEMENT-TYPE VARIABLES &body BODY

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)

Package

array-operations/transforming

Source

lisp.lisp (file)

Macro: vectorize-reduce FN VARIABLES &body BODY

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)))

Package

array-operations/reducing

Source

lisp.lisp (file)

Macro: walk-subscripts (DIMENSIONS SUBSCRIPTS &optional POSITION) &body BODY

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.

Package

array-operations/utilities

Source

lisp.lisp (file)

Macro: walk-subscripts-list (DIMENSIONS SUBSCRIPTS &optional POSITION) &body BODY

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.

Package

array-operations/utilities

Source

lisp.lisp (file)


Next: , Previous: , Up: Exported definitions   [Contents][Index]

5.1.2 Functions

Function: argmax ARRAY

Find the row-major-aref in ARRAY with the maximum value Returns both the index and the value of ARRAY at that index

Package

array-operations/reducing

Source

lisp.lisp (file)

Function: argmin ARRAY

Find the row-major-aref in ARRAY with the minimum value Returns both the index and the value of ARRAY at that index

Package

array-operations/reducing

Source

lisp.lisp (file)

Function: best FN ARRAY

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 P.Graham’s On Lisp

Package

array-operations/reducing

Source

lisp.lisp (file)

Function: coercing ELEMENT-TYPE &optional FUNCTION

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.

Package

array-operations/transforming

Source

lisp.lisp (file)

Function: combine ARRAY &optional 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.

Package

array-operations/displacing

Source

lisp.lisp (file)

Function: complement-permutation PERMUTATION RANK

Return a list of increasing indices that complement PERMUTATION, ie form a permutation when appended. Atoms are accepted and treated as lists of a single element.

Package

array-operations/transforming

Source

lisp.lisp (file)

Function: complete-permutation PERMUTATION RANK

Return a completed version of permutation, appending it to its complement.

Package

array-operations/transforming

Source

lisp.lisp (file)

Function: copy-into TARGET SOURCE

Copy SOURCE into TARGET, for array arguments of compatible dimensions (checked). Return TARGET, making the implementation of the semantics of SETF easy.

Package

array-operations/displacing

Source

lisp.lisp (file)

Function: copy-row-major-block SOURCE-ARRAY DESTINATION-ARRAY ELEMENT-TYPE &key SOURCE-START SOURCE-END DESTINATION-START

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.

Package

array-operations/stacking

Source

lisp.lisp (file)

Function: displace ARRAY DIMENSIONS &optional OFFSET

Shorthand function for displacing an array.

Package

array-operations/displacing

Source

lisp.lisp (file)

Function: each FUNCTION ARRAY &rest OTHER-ARRAYS

Like EACH*, with ELEMENT-TYPE T.

Package

array-operations/transforming

Source

lisp.lisp (file)

Function: each* ELEMENT-TYPE FUNCTION ARRAY &rest OTHER-ARRAYS

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.

Package

array-operations/transforming

Source

lisp.lisp (file)

Function: ensure-dimensions OBJECT

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.

Package

array-operations/utilities

Source

lisp.lisp (file)

Function: fill! ARRAY VALUE

Fills a given ARRAY with VALUE, coerced to the same element type as ARRAY

Package

array-operations/creating

Source

lisp.lisp (file)

Function: fill-in-dimensions DIMENSIONS SIZE

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

Package

array-operations/displacing

Source

lisp.lisp (file)

Function: flatten ARRAY

Return ARRAY flattened to a vector. Will share structure.

Package

array-operations/displacing

Source

lisp.lisp (file)

Function: generate FUNCTION DIMENSIONS &optional ARGUMENTS

Like GENERATE*, with ELEMENT-TYPE T.

Package

array-operations/creating

Source

lisp.lisp (file)

Function: generate* ELEMENT-TYPE FUNCTION DIMENSIONS &optional ARGUMENTS

Return an array with given DIMENSIONS and ELEMENT-TYPE, with elements generated by calling FUNCTION 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.

Package

array-operations/creating

Source

lisp.lisp (file)

Function: identity-permutation-p PERMUTATION &optional RANK

Test if PERMUTATION is the identity permutation, ie a sequence of consecutive integers starting at 0. Note that permutation is otherwise not checked, ie it may not be a permutation.

Package

array-operations/transforming

Source

lisp.lisp (file)

Function: identity-permutation? PERMUTATION &optional RANK

Test if PERMUTATION is the identity permutation, ie a sequence of consecutive integers starting at 0. Note that permutation is otherwise not checked, ie it may not be a permutation.

Package

array-operations/transforming

Source

lisp.lisp (file)

Function: invert-permutation PERMUTATION

Invert a permutation.

Package

array-operations/transforming

Source

lisp.lisp (file)

Function: linspace START STOP N

Make a vector of N elements and type T, containing evenly spaced numbers over an interval. The first element is equal to START and last element STOP,
with constant difference between consecutive elements.

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

Package

array-operations/creating

Source

lisp.lisp (file)

Function: linspace! ARRAY START STOP

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.

Package

array-operations/creating

Source

lisp.lisp (file)

Function: linspace* ELEMENT-TYPE START STOP N

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.

Package

array-operations/creating

Source

lisp.lisp (file)

Function: make-array-like ARRAY &key DIMENSIONS ADJUSTABLE ELEMENT-TYPE INITIAL-ELEMENT FILL-POINTER

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.

Package

array-operations/creating

Source

lisp.lisp (file)

Function: margin FUNCTION ARRAY INNER &optional OUTER

Like MARGIN*, with ELEMENT-TYPE T.

Package

array-operations/transforming

Source

lisp.lisp (file)

Function: margin* ELEMENT-TYPE FUNCTION ARRAY INNER &optional OUTER

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.

Package

array-operations/transforming

Source

lisp.lisp (file)

Function: matrix? MATRIX

Test if MATRIX has rank 2.

Package

array-operations/matrices

Source

lisp.lisp (file)

Function: matrixp MATRIX

Test if MATRIX has rank 2.

Package

array-operations/matrices

Source

lisp.lisp (file)

Function: most FN ARRAY

Finds the element of ARRAY which maximises FN 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 P.Graham’s On Lisp

Package

array-operations/reducing

Source

lisp.lisp (file)

Function: ones DIMENSIONS

Makes an array of shape DIMENSIONS and type T, filled with ones

Package

array-operations/creating

Source

lisp.lisp (file)

Function: ones! ARRAY

Fills the given ARRAY with 1’s, coerced to the element type. Returns ARRAY.

Package

array-operations/creating

Source

lisp.lisp (file)

Function: ones* ELEMENT-TYPE DIMENSIONS

Makes an array of shape DIMENSIONS and type ELEMENT-TYPE, filled with ones coerced to the specified type ELEMENT-TYPE.

Package

array-operations/creating

Source

lisp.lisp (file)

Function: outer FUNCTION &rest ARRAYS

Like OUTER, with ELEMENT-TYPE t.

Package

array-operations/transforming

Source

lisp.lisp (file)

Function: outer* ELEMENT-TYPE FUNCTION &rest ARRAYS

Generalized outer product of ARRAYS with FUNCTION. The resulting array has the concatenated dimensions of ARRAYS, and the given ELEMENT-TYPE.

Package

array-operations/transforming

Source

lisp.lisp (file)

Function: partition ARRAY START &optional END

Return a subset of the array, on the first indexes between START and END.

Package

array-operations/displacing

Source

lisp.lisp (file)

Writer

(setf partition) (function)

Function: (setf partition) VALUE ARRAY START &optional END
Package

array-operations/displacing

Source

lisp.lisp (file)

Reader

partition (function)

Function: permute PERMUTATION ARRAY

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.

Package

array-operations/transforming

Source

lisp.lisp (file)

Function: product DIMENSIONS

Product of elements in the argument. NOT EXPORTED.

Package

array-operations/utilities

Source

lisp.lisp (file)

Function: rand DIMENSIONS

Makes an array of shape DIMENSIONS and type T, 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.

Package

array-operations/creating

Source

lisp.lisp (file)

Function: rand! ARRAY

Fills a given ARRAY with random numbers, uniformly distributed between 0 and 1. Uses the built-in RANDOM function. Returns ARRAY.

Package

array-operations/creating

Source

lisp.lisp (file)

Function: rand* ELEMENT-TYPE DIMENSIONS

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.

Package

array-operations/creating

Source

lisp.lisp (file)

Function: randn DIMENSIONS

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.

Package

array-operations/creating

Source

lisp.lisp (file)

Function: randn! ARRAY

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.

Package

array-operations/creating

Source

lisp.lisp (file)

Function: randn* ELEMENT-TYPE DIMENSIONS

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.

Package

array-operations/creating

Source

lisp.lisp (file)

Function: recycle OBJECT &key INNER OUTER ELEMENT-TYPE

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 intepreted as rank 0 arrays, following the usual semantics.

Package

array-operations/transforming

Source

lisp.lisp (file)

Function: reshape ARRAY DIMENSIONS &optional OFFSET

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.

Package

array-operations/displacing

Source

lisp.lisp (file)

Function: reshape-col ARRAY

Array reshaped as an Nx1 matrix.

Package

array-operations/displacing

Source

lisp.lisp (file)

Function: reshape-row ARRAY

Array reshaped as an 1xN matrix.

Package

array-operations/displacing

Source

lisp.lisp (file)

Function: same-dimensions-p ARRAY &rest ARRAYS

Test if arguments have the same dimensions. NOT EXPORTED.

Package

array-operations/utilities

Source

lisp.lisp (file)

Function: similar-array ARRAY &key DIMENSIONS ADJUSTABLE ELEMENT-TYPE INITIAL-ELEMENT FILL-POINTER

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.

Package

array-operations/creating

Source

lisp.lisp (file)

Function: split ARRAY RANK

Return an array of subarrays, split off at RANK. All subarrays are displaced and share structure.

Package

array-operations/displacing

Source

lisp.lisp (file)

Function: square-matrix-p MATRIX

Test if MATRIX has two dimensions and that they are equal.

Package

array-operations/matrices

Source

lisp.lisp (file)

Function: square-matrix? MATRIX

Test if MATRIX has two dimensions and that they are equal.

Package

array-operations/matrices

Source

lisp.lisp (file)

Function: stack AXIS ARRAY &rest ARRAYS

Like STACK*, with element-type T.

Package

array-operations/stacking

Source

lisp.lisp (file)

Function: stack* ELEMENT-TYPE AXIS ARRAY &rest ARRAYS

Stack array arguments along AXIS. ELEMENT-TYPE determines the element-type of the result.

Package

array-operations/stacking

Source

lisp.lisp (file)

Function: stack-cols &rest OBJECTS

Like STACK-COLS*, with ELEMENT-TYPE T.

Package

array-operations/stacking

Source

lisp.lisp (file)

Function: stack-cols* ELEMENT-TYPE &rest OBJECTS

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.

Package

array-operations/stacking

Source

lisp.lisp (file)

Function: stack-rows &rest OBJECTS

Like STACK-ROWS*, with ELEMENT-TYPE T.

Package

array-operations/stacking

Source

lisp.lisp (file)

Function: stack-rows* ELEMENT-TYPE &rest OBJECTS

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.

Package

array-operations/stacking

Source

lisp.lisp (file)

Function: sub ARRAY &rest SUBSCRIPTS

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.

Package

array-operations/displacing

Source

lisp.lisp (file)

Writer

(setf sub) (function)

Function: (setf sub) VALUE ARRAY &rest SUBSCRIPTS
Package

array-operations/displacing

Source

lisp.lisp (file)

Reader

sub (function)

Function: subvec VECTOR START &optional END

Displaced vector between START and END.

Package

array-operations/displacing

Source

lisp.lisp (file)

Writer

(setf subvec) (function)

Function: (setf subvec) VALUE VECTOR START &optional END
Package

array-operations/displacing

Source

lisp.lisp (file)

Reader

subvec (function)

Function: zeros DIMENSIONS

Makes an array of shape DIMENSIONS and type T, filled with zeros

Package

array-operations/creating

Source

lisp.lisp (file)

Function: zeros! ARRAY

Fills the given ARRAY with zero values, coerced to the element type. Returns ARRAY.

Package

array-operations/creating

Source

lisp.lisp (file)

Function: zeros* ELEMENT-TYPE DIMENSIONS

Makes an array of shape DIMENSIONS and type ELEMENT-TYPE, filled with zeros coerced to the specified type ELEMENT-TYPE.

Package

array-operations/creating

Source

lisp.lisp (file)


Next: , Previous: , Up: Exported definitions   [Contents][Index]

5.1.3 Generic functions

Generic Function: as-array OBJECT

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.

Package

array-operations/generic

Source

lisp.lisp (file)

Methods
Method: as-array (ARRAY array)
Method: as-array OBJECT
Generic Function: dim ARRAY AXIS

Return specificed dimension of ARRAY.

Package

array-operations/generic

Source

lisp.lisp (file)

Methods
Method: dim (ARRAY array) AXIS
Method: dim ARRAY AXIS
Generic Function: dims 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.

Package

array-operations/generic

Source

lisp.lisp (file)

Methods
Method: dims (ARRAY array)
Method: dims ARRAY
Generic Function: element-type ARRAY

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.

Package

array-operations/generic

Source

lisp.lisp (file)

Methods
Method: element-type (ARRAY array)
Method: element-type ARRAY
Generic Function: ncol ARRAY

Number of columns. Will signal an error if ARRAY is not a matrix.

Package

array-operations/generic

Source

lisp.lisp (file)

Methods
Method: ncol (ARRAY array)
Method: ncol ARRAY
Generic Function: nrow ARRAY

Number of rows. Will signal an error if ARRAY is not a matrix.

Package

array-operations/generic

Source

lisp.lisp (file)

Methods
Method: nrow (ARRAY array)
Method: nrow ARRAY
Generic Function: rank ARRAY

Return the rank of ARRAY.

Package

array-operations/generic

Source

lisp.lisp (file)

Methods
Method: rank (ARRAY array)
Method: rank ARRAY
Generic Function: size ARRAY

Return the total number of elements in array.

Package

array-operations/generic

Source

lisp.lisp (file)

Methods
Method: size (ARRAY array)
Method: size ARRAY
Generic Function: stack-cols-copy SOURCE DESTINATION ELEMENT-TYPE START-COL

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 definining a method is efficiency.

Package

array-operations/stacking

Source

lisp.lisp (file)

Methods
Method: stack-cols-copy SOURCE DESTINATION ELEMENT-TYPE START-COL
Method: stack-cols-copy (SOURCE array) DESTINATION ELEMENT-TYPE START-COL
Generic Function: stack-rows-copy SOURCE DESTINATION ELEMENT-TYPE START-ROW

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 onlychanges 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 definining a method is efficiency.

Package

array-operations/stacking

Source

lisp.lisp (file)

Methods
Method: stack-rows-copy SOURCE DESTINATION ELEMENT-TYPE START-ROW
Method: stack-rows-copy (SOURCE array) DESTINATION ELEMENT-TYPE START-ROW

Next: , Previous: , Up: Exported definitions   [Contents][Index]

5.1.4 Conditions

Condition: permutation-incompatible-rank ()
Package

array-operations/transforming

Source

lisp.lisp (file)

Direct superclasses

error (condition)

Condition: permutation-invalid-index ()
Package

array-operations/transforming

Source

lisp.lisp (file)

Direct superclasses

error (condition)

Direct slots
Slot: index
Initargs

:index

Condition: permutation-repeated-index ()
Package

array-operations/transforming

Source

lisp.lisp (file)

Direct superclasses

error (condition)

Direct slots
Slot: index
Initargs

:index


Previous: , Up: Exported definitions   [Contents][Index]

5.1.5 Types

Type: array-matrix ()

A rank-2 array.

Package

array-operations/matrices

Source

lisp.lisp (file)


Previous: , Up: Definitions   [Contents][Index]

5.2 Internal definitions


Next: , Previous: , Up: Internal definitions   [Contents][Index]

5.2.1 Macros

Macro: foreach &key INDEX SUM (VALUE BODY)

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))

Package

array-operations/indexing

Source

lisp.lisp (file)


Previous: , Up: Internal definitions   [Contents][Index]

5.2.2 Functions

Function: check-permutation PERMUTATION &optional RANK

Check if PERMUTATION is a valid permutation (of the given RANK), and signal an error if necessary.

Package

array-operations/transforming

Source

lisp.lisp (file)

Function: find-array-dimensions EXPR

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))

Package

array-operations/indexing

Source

lisp.lisp (file)

Function: permutation-flags PERMUTATION &optional RANK

Make a bit vector of flags with indexes from PERMUTATION, signalling errors for invalid and repeated indices. NOT EXPORTED.

Package

array-operations/transforming

Source

lisp.lisp (file)

Function: stack*0 ELEMENT-TYPE ARRAYS

Stack arrays along the 0 axis, returning an array with given ELEMENT-TYPE.

Package

array-operations/stacking

Source

lisp.lisp (file)

Function: sub-location% DIMENSIONS SUBSCRIPTS

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.

Package

array-operations/displacing

Source

lisp.lisp (file)


Previous: , Up: Top   [Contents][Index]

Appendix A Indexes


Next: , Previous: , Up: Indexes   [Contents][Index]

A.1 Concepts

Jump to:   A   F   L  
Index Entry  Section

A
array-operations.asd: The array-operations․asd file
array-operations/all/lisp.lisp: The array-operations/all/lisp․lisp file
array-operations/creating/lisp.lisp: The array-operations/creating/lisp․lisp file
array-operations/displacing/lisp.lisp: The array-operations/displacing/lisp․lisp file
array-operations/generic/lisp.lisp: The array-operations/generic/lisp․lisp file
array-operations/indexing/lisp.lisp: The array-operations/indexing/lisp․lisp file
array-operations/matrices/lisp.lisp: The array-operations/matrices/lisp․lisp file
array-operations/reducing/lisp.lisp: The array-operations/reducing/lisp․lisp file
array-operations/stacking/lisp.lisp: The array-operations/stacking/lisp․lisp file
array-operations/transforming/lisp.lisp: The array-operations/transforming/lisp․lisp file
array-operations/utilities/lisp.lisp: The array-operations/utilities/lisp․lisp file

F
File, Lisp, array-operations.asd: The array-operations․asd file
File, Lisp, array-operations/all/lisp.lisp: The array-operations/all/lisp․lisp file
File, Lisp, array-operations/creating/lisp.lisp: The array-operations/creating/lisp․lisp file
File, Lisp, array-operations/displacing/lisp.lisp: The array-operations/displacing/lisp․lisp file
File, Lisp, array-operations/generic/lisp.lisp: The array-operations/generic/lisp․lisp file
File, Lisp, array-operations/indexing/lisp.lisp: The array-operations/indexing/lisp․lisp file
File, Lisp, array-operations/matrices/lisp.lisp: The array-operations/matrices/lisp․lisp file
File, Lisp, array-operations/reducing/lisp.lisp: The array-operations/reducing/lisp․lisp file
File, Lisp, array-operations/stacking/lisp.lisp: The array-operations/stacking/lisp․lisp file
File, Lisp, array-operations/transforming/lisp.lisp: The array-operations/transforming/lisp․lisp file
File, Lisp, array-operations/utilities/lisp.lisp: The array-operations/utilities/lisp․lisp file

L
Lisp File, array-operations.asd: The array-operations․asd file
Lisp File, array-operations/all/lisp.lisp: The array-operations/all/lisp․lisp file
Lisp File, array-operations/creating/lisp.lisp: The array-operations/creating/lisp․lisp file
Lisp File, array-operations/displacing/lisp.lisp: The array-operations/displacing/lisp․lisp file
Lisp File, array-operations/generic/lisp.lisp: The array-operations/generic/lisp․lisp file
Lisp File, array-operations/indexing/lisp.lisp: The array-operations/indexing/lisp․lisp file
Lisp File, array-operations/matrices/lisp.lisp: The array-operations/matrices/lisp․lisp file
Lisp File, array-operations/reducing/lisp.lisp: The array-operations/reducing/lisp․lisp file
Lisp File, array-operations/stacking/lisp.lisp: The array-operations/stacking/lisp․lisp file
Lisp File, array-operations/transforming/lisp.lisp: The array-operations/transforming/lisp․lisp file
Lisp File, array-operations/utilities/lisp.lisp: The array-operations/utilities/lisp․lisp file

Jump to:   A   F   L  

Next: , Previous: , Up: Indexes   [Contents][Index]

A.2 Functions

Jump to:   &   (  
A   B   C   D   E   F   G   I   L   M   N   O   P   R   S   V   W   Z  
Index Entry  Section

&
&dims: Exported macros

(
(setf partition): Exported functions
(setf sub): Exported functions
(setf subvec): Exported functions

A
argmax: Exported functions
argmin: Exported functions
as-array: Exported generic functions
as-array: Exported generic functions
as-array: Exported generic functions

B
best: Exported functions

C
check-permutation: Internal functions
coercing: Exported functions
combine: Exported functions
complement-permutation: Exported functions
complete-permutation: Exported functions
copy-into: Exported functions
copy-row-major-block: Exported functions

D
dim: Exported generic functions
dim: Exported generic functions
dim: Exported generic functions
dims: Exported generic functions
dims: Exported generic functions
dims: Exported generic functions
displace: Exported functions

E
each: Exported functions
each*: Exported functions
each-index: Exported macros
each-index!: Exported macros
each-index*: Exported macros
element-type: Exported generic functions
element-type: Exported generic functions
element-type: Exported generic functions
ensure-dimensions: Exported functions

F
fill!: Exported functions
fill-in-dimensions: Exported functions
find-array-dimensions: Internal functions
flatten: Exported functions
foreach: Internal macros
Function, (setf partition): Exported functions
Function, (setf sub): Exported functions
Function, (setf subvec): Exported functions
Function, argmax: Exported functions
Function, argmin: Exported functions
Function, best: Exported functions
Function, check-permutation: Internal functions
Function, coercing: Exported functions
Function, combine: Exported functions
Function, complement-permutation: Exported functions
Function, complete-permutation: Exported functions
Function, copy-into: Exported functions
Function, copy-row-major-block: Exported functions
Function, displace: Exported functions
Function, each: Exported functions
Function, each*: Exported functions
Function, ensure-dimensions: Exported functions
Function, fill!: Exported functions
Function, fill-in-dimensions: Exported functions
Function, find-array-dimensions: Internal functions
Function, flatten: Exported functions
Function, generate: Exported functions
Function, generate*: Exported functions
Function, identity-permutation-p: Exported functions
Function, identity-permutation?: Exported functions
Function, invert-permutation: Exported functions
Function, linspace: Exported functions
Function, linspace!: Exported functions
Function, linspace*: Exported functions
Function, make-array-like: Exported functions
Function, margin: Exported functions
Function, margin*: Exported functions
Function, matrix?: Exported functions
Function, matrixp: Exported functions
Function, most: Exported functions
Function, ones: Exported functions
Function, ones!: Exported functions
Function, ones*: Exported functions
Function, outer: Exported functions
Function, outer*: Exported functions
Function, partition: Exported functions
Function, permutation-flags: Internal functions
Function, permute: Exported functions
Function, product: Exported functions
Function, rand: Exported functions
Function, rand!: Exported functions
Function, rand*: Exported functions
Function, randn: Exported functions
Function, randn!: Exported functions
Function, randn*: Exported functions
Function, recycle: Exported functions
Function, reshape: Exported functions
Function, reshape-col: Exported functions
Function, reshape-row: Exported functions
Function, same-dimensions-p: Exported functions
Function, similar-array: Exported functions
Function, split: Exported functions
Function, square-matrix-p: Exported functions
Function, square-matrix?: Exported functions
Function, stack: Exported functions
Function, stack*: Exported functions
Function, stack*0: Internal functions
Function, stack-cols: Exported functions
Function, stack-cols*: Exported functions
Function, stack-rows: Exported functions
Function, stack-rows*: Exported functions
Function, sub: Exported functions
Function, sub-location%: Internal functions
Function, subvec: Exported functions
Function, zeros: Exported functions
Function, zeros!: Exported functions
Function, zeros*: Exported functions

G
generate: Exported functions
generate*: Exported functions
Generic Function, as-array: Exported generic functions
Generic Function, dim: Exported generic functions
Generic Function, dims: Exported generic functions
Generic Function, element-type: Exported generic functions
Generic Function, ncol: Exported generic functions
Generic Function, nrow: Exported generic functions
Generic Function, rank: Exported generic functions
Generic Function, size: Exported generic functions
Generic Function, stack-cols-copy: Exported generic functions
Generic Function, stack-rows-copy: Exported generic functions

I
identity-permutation-p: Exported functions
identity-permutation?: Exported functions
invert-permutation: Exported functions

L
linspace: Exported functions
linspace!: Exported functions
linspace*: Exported functions

M
Macro, &dims: Exported macros
Macro, each-index: Exported macros
Macro, each-index!: Exported macros
Macro, each-index*: Exported macros
Macro, foreach: Internal macros
Macro, multf: Exported macros
Macro, nested-loop: Exported macros
Macro, reduce-index: Exported macros
Macro, sum-index: Exported macros
Macro, vectorize: Exported macros
Macro, vectorize!: Exported macros
Macro, vectorize*: Exported macros
Macro, vectorize-reduce: Exported macros
Macro, walk-subscripts: Exported macros
Macro, walk-subscripts-list: Exported macros
make-array-like: Exported functions
margin: Exported functions
margin*: Exported functions
matrix?: Exported functions
matrixp: Exported functions
Method, as-array: Exported generic functions
Method, as-array: Exported generic functions
Method, dim: Exported generic functions
Method, dim: Exported generic functions
Method, dims: Exported generic functions
Method, dims: Exported generic functions
Method, element-type: Exported generic functions
Method, element-type: Exported generic functions
Method, ncol: Exported generic functions
Method, ncol: Exported generic functions
Method, nrow: Exported generic functions
Method, nrow: Exported generic functions
Method, rank: Exported generic functions
Method, rank: Exported generic functions
Method, size: Exported generic functions
Method, size: Exported generic functions
Method, stack-cols-copy: Exported generic functions
Method, stack-cols-copy: Exported generic functions
Method, stack-rows-copy: Exported generic functions
Method, stack-rows-copy: Exported generic functions
most: Exported functions
multf: Exported macros

N
ncol: Exported generic functions
ncol: Exported generic functions
ncol: Exported generic functions
nested-loop: Exported macros
nrow: Exported generic functions
nrow: Exported generic functions
nrow: Exported generic functions

O
ones: Exported functions
ones!: Exported functions
ones*: Exported functions
outer: Exported functions
outer*: Exported functions

P
partition: Exported functions
permutation-flags: Internal functions
permute: Exported functions
product: Exported functions

R
rand: Exported functions
rand!: Exported functions
rand*: Exported functions
randn: Exported functions
randn!: Exported functions
randn*: Exported functions
rank: Exported generic functions
rank: Exported generic functions
rank: Exported generic functions
recycle: Exported functions
reduce-index: Exported macros
reshape: Exported functions
reshape-col: Exported functions
reshape-row: Exported functions

S
same-dimensions-p: Exported functions
similar-array: Exported functions
size: Exported generic functions
size: Exported generic functions
size: Exported generic functions
split: Exported functions
square-matrix-p: Exported functions
square-matrix?: Exported functions
stack: Exported functions
stack*: Exported functions
stack*0: Internal functions
stack-cols: Exported functions
stack-cols*: Exported functions
stack-cols-copy: Exported generic functions
stack-cols-copy: Exported generic functions
stack-cols-copy: Exported generic functions
stack-rows: Exported functions
stack-rows*: Exported functions
stack-rows-copy: Exported generic functions
stack-rows-copy: Exported generic functions
stack-rows-copy: Exported generic functions
sub: Exported functions
sub-location%: Internal functions
subvec: Exported functions
sum-index: Exported macros

V
vectorize: Exported macros
vectorize!: Exported macros
vectorize*: Exported macros
vectorize-reduce: Exported macros

W
walk-subscripts: Exported macros
walk-subscripts-list: Exported macros

Z
zeros: Exported functions
zeros!: Exported functions
zeros*: Exported functions

Jump to:   &   (  
A   B   C   D   E   F   G   I   L   M   N   O   P   R   S   V   W   Z  

Next: , Previous: , Up: Indexes   [Contents][Index]

A.3 Variables

Jump to:   I   S  
Index Entry  Section

I
index: Exported conditions
index: Exported conditions

S
Slot, index: Exported conditions
Slot, index: Exported conditions

Jump to:   I   S  

Previous: , Up: Indexes   [Contents][Index]

A.4 Data types

Jump to:   A   C   P   S   T  
Index Entry  Section

A
array-matrix: Exported types
array-operations: The array-operations system
array-operations/all: The array-operations/all system
array-operations/all: The array-operations/all package
array-operations/creating: The array-operations/creating system
array-operations/creating: The array-operations/creating package
array-operations/displacing: The array-operations/displacing system
array-operations/displacing: The array-operations/displacing package
array-operations/generic: The array-operations/generic system
array-operations/generic: The array-operations/generic package
array-operations/indexing: The array-operations/indexing system
array-operations/indexing: The array-operations/indexing package
array-operations/matrices: The array-operations/matrices system
array-operations/matrices: The array-operations/matrices package
array-operations/reducing: The array-operations/reducing system
array-operations/reducing: The array-operations/reducing package
array-operations/stacking: The array-operations/stacking system
array-operations/stacking: The array-operations/stacking package
array-operations/transforming: The array-operations/transforming system
array-operations/transforming: The array-operations/transforming package
array-operations/utilities: The array-operations/utilities system
array-operations/utilities: The array-operations/utilities package

C
Condition, permutation-incompatible-rank: Exported conditions
Condition, permutation-invalid-index: Exported conditions
Condition, permutation-repeated-index: Exported conditions

P
Package, array-operations/all: The array-operations/all package
Package, array-operations/creating: The array-operations/creating package
Package, array-operations/displacing: The array-operations/displacing package
Package, array-operations/generic: The array-operations/generic package
Package, array-operations/indexing: The array-operations/indexing package
Package, array-operations/matrices: The array-operations/matrices package
Package, array-operations/reducing: The array-operations/reducing package
Package, array-operations/stacking: The array-operations/stacking package
Package, array-operations/transforming: The array-operations/transforming package
Package, array-operations/utilities: The array-operations/utilities package
permutation-incompatible-rank: Exported conditions
permutation-invalid-index: Exported conditions
permutation-repeated-index: Exported conditions

S
System, array-operations: The array-operations system
System, array-operations/all: The array-operations/all system
System, array-operations/creating: The array-operations/creating system
System, array-operations/displacing: The array-operations/displacing system
System, array-operations/generic: The array-operations/generic system
System, array-operations/indexing: The array-operations/indexing system
System, array-operations/matrices: The array-operations/matrices system
System, array-operations/reducing: The array-operations/reducing system
System, array-operations/stacking: The array-operations/stacking system
System, array-operations/transforming: The array-operations/transforming system
System, array-operations/utilities: The array-operations/utilities system

T
Type, array-matrix: Exported types

Jump to:   A   C   P   S   T