procedure
( array-axis-fold arrkf)→(Array A)
k:Integerk:Integerinit:B
The three-argument variant uses the first value of each row in axis k as init. It therefore requires axis k to have positive length.
> arr- : #(struct:Array
(Indexes Index (Boxof Boolean) (-> Void) (-> Indexes Index))
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:56:13 prop:equal+hash>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:55:13 prop:custom-write>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:54:13 prop:custom-print-quotable>)
(array #[#[0 1 2 3] #[4 5 6 7] #[8 9 10 11]])
- : #(struct:Array
(Indexes
Index
(Boxof Boolean)
(-> Void)
(-> Indexes Nonnegative-Integer))
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:56:13 prop:equal+hash>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:55:13 prop:custom-write>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:54:13 prop:custom-print-quotable>)
(array #[12 15 18 21])
- : #(struct:Array
(Indexes Index (Boxof Boolean) (-> Void) (-> Indexes (Listof Index)))
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:56:13 prop:equal+hash>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:55:13 prop:custom-write>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:54:13 prop:custom-print-quotable>)
(array #['(3 2 1 0) '(7 6 5 4) '(11 10 9 8)])
If you need control over the order of evaluation in axis k’s rows, see array-axis-reduce .
syntax
( array-axis-sum arrk)
syntax
( array-axis-prod arrk)
syntax
( array-axis-min arrk)
> arr- : #(struct:Array
(Indexes Index (Boxof Boolean) (-> Void) (-> Indexes Index))
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:56:13 prop:equal+hash>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:55:13 prop:custom-write>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:54:13 prop:custom-print-quotable>)
(array #[#[0 1 2 3] #[4 5 6 7] #[8 9 10 11]])
- : #(struct:Array
(Indexes
Index
(Boxof Boolean)
(-> Void)
(-> Indexes Nonnegative-Integer))
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:56:13 prop:equal+hash>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:55:13 prop:custom-write>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:54:13 prop:custom-print-quotable>)
(array #[6 22 38])
- : #(struct:Array
(Indexes
Index
(Boxof Boolean)
(-> Void)
(-> Indexes Nonnegative-Integer))
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:56:13 prop:equal+hash>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:55:13 prop:custom-write>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:54:13 prop:custom-print-quotable>)
(array #[6 22 38])
- : #(struct:Array
(Indexes Index (Boxof Boolean) (-> Void) (-> Indexes Nonnegative-Flonum))
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:56:13 prop:equal+hash>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:55:13 prop:custom-write>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:54:13 prop:custom-print-quotable>)
(array #[12.0 15.0 18.0 21.0])
> arr- : #(struct:Array
(Indexes Index (Boxof Boolean) (-> Void) (-> Indexes Index))
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:56:13 prop:equal+hash>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:55:13 prop:custom-write>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:54:13 prop:custom-print-quotable>)
(array #[#[0 1 2] #[3 4 5] #[6 7 8]])
- : #(struct:Array
(Indexes Index (Boxof Boolean) (-> Void) (-> Indexes Index))
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:56:13 prop:equal+hash>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:55:13 prop:custom-write>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:54:13 prop:custom-print-quotable>)
(array #[1 2 1])
#t])))))
- : #(struct:Array
(Indexes Index (Boxof Boolean) (-> Void) (-> Indexes Boolean))
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:56:13 prop:equal+hash>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:55:13 prop:custom-write>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:54:13 prop:custom-print-quotable>)
(array #f)
> second?- : Boolean
#f
> arr- : #(struct:Array
(Indexes Index (Boxof Boolean) (-> Void) (-> Indexes Index))
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:56:13 prop:equal+hash>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:55:13 prop:custom-write>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:54:13 prop:custom-print-quotable>)
(array #[#[0 1 2 3] #[4 5 6 7] #[8 9 10 11]])
- : #(struct:Array
(Indexes Index (Boxof Boolean) (-> Void) (-> Indexes Integer))
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:56:13 prop:equal+hash>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:55:13 prop:custom-write>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:54:13 prop:custom-print-quotable>)
(array 66)
- : Integer [more precisely: Nonnegative-Integer]
66
#())- : (U (Listof (Rec g8474238 (U (Listof g8474238) Integer))) Index)
'((0 1 2 3) (4 5 6 7) (8 9 10 11))
procedure
( array-all-fold arrf)→A
init:A
#())
> arr- : #(struct:Array
(Indexes Index (Boxof Boolean) (-> Void) (-> Indexes Index))
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:56:13 prop:equal+hash>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:55:13 prop:custom-write>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:54:13 prop:custom-print-quotable>)
(array #[#[0 1 2 3] #[4 5 6 7] #[8 9 10 11]])
- : Integer [more precisely: Nonnegative-Integer]
66
- : Flonum [more precisely: Nonnegative-Flonum]
0.0
syntax
( array-all-sum arr)
syntax
( array-all-min arr)
> arr- : #(struct:Array
(Indexes Index (Boxof Boolean) (-> Void) (-> Indexes Index))
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:56:13 prop:equal+hash>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:55:13 prop:custom-write>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:54:13 prop:custom-print-quotable>)
(array #[#[0 1 2 3] #[4 5 6 7] #[8 9 10 11]])
- : Integer [more precisely: Nonnegative-Integer]
66
- : Integer [more precisely: Nonnegative-Integer]
66
- : Real [more precisely: Nonnegative-Real]
66.0
procedure
( array-all-and arr)→(U ABoolean )
procedure
( array-all-or arr)→(U A#f)
- : Boolean
#t
- : Boolean
#f
- : Boolean
#t
syntax
( array-count pred?arrs...)
- : Integer [more precisely: Index]
3
- : Integer [more precisely: Index]
4
syntax
( array-andmap pred?arrs...)
- : Boolean
#t
- : Boolean
#t
- : Boolean
#f
The arguments to h are the length of axis k and a procedure that retrieves elements from that axis’s rows by their indexes in axis k. It should return the elements of the resulting array.
> arr- : #(struct:Array
(Indexes Index (Boxof Boolean) (-> Void) (-> Indexes Index))
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:56:13 prop:equal+hash>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:55:13 prop:custom-write>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:54:13 prop:custom-print-quotable>)
(array #[#[0 1 2] #[3 4 5] #[6 7 8]])
arr1- : #(struct:Array
(Indexes Index (Boxof Boolean) (-> Void) (-> Indexes Real))
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:56:13 prop:equal+hash>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:55:13 prop:custom-write>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:54:13 prop:custom-print-quotable>)
(array #[5 50 149])
- : #(struct:Array
(Indexes
Index
(Boxof Boolean)
(-> Void)
(-> Indexes Nonnegative-Integer))
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:56:13 prop:equal+hash>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:55:13 prop:custom-write>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:54:13 prop:custom-print-quotable>)
(array #[5 50 149])
- : #(struct:Array
(Indexes Index (Boxof Boolean) (-> Void) (-> Indexes (Listof Index)))
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:56:13 prop:equal+hash>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:55:13 prop:custom-write>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:54:13 prop:custom-print-quotable>)
(array #['(0 1 2) '(3 4 5) '(6 7 8)])
- : #(struct:Array
(Indexes Index (Boxof Boolean) (-> Void) (-> Indexes (Listof Index)))
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:56:13 prop:equal+hash>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:55:13 prop:custom-write>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:54:13 prop:custom-print-quotable>)
(array #['(0 1 2) '(3 4 5) '(6 7 8)])
Every fold, including array-axis-fold , is ultimately defined using array-axis-reduce or its unsafe counterpart.
Conceptually, g is applied dk times to each element in each row of axis k, once for each nonnegative index jk< dk.
- : #(struct:Array
(Indexes Index (Boxof Boolean) (-> Void) (-> Indexes Any))
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:56:13 prop:equal+hash>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:55:13 prop:custom-write>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:54:13 prop:custom-print-quotable>)
(array #[#['a 'b 'c] #['d 'e 'f] #['g 'h 'i]])
- : #(struct:Array
(Indexes Index (Boxof Boolean) (-> Void) (-> Indexes Positive-Integer))
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:56:13 prop:equal+hash>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:55:13 prop:custom-write>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:54:13 prop:custom-print-quotable>)
(array #[#[1 1 1 1 1] #[1 2 4 8 16] #[1 3 9 27 81] #[1 4 16 64 256]])
This function is a dual of array-axis-reduce in that it can be used to invert applications of array-axis-reduce . To do so, g should be a destructuring function that is dual to the constructor passed to array-axis-reduce . Example dual pairs are vector-ref and build-vector , and list-ref and build-list .
(Do not pass list-ref to array-axis-expand if you care about performance, though. See list-array->array for a more efficient solution.)
procedure
( array->list-array arr[k])→(Array (Listof A))
> arr- : #(struct:Array
(Indexes Index (Boxof Boolean) (-> Void) (-> Indexes Index))
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:56:13 prop:equal+hash>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:55:13 prop:custom-write>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:54:13 prop:custom-print-quotable>)
(array #[#[0 1 2] #[3 4 5] #[6 7 8]])
- : #(struct:Array
(Indexes Index (Boxof Boolean) (-> Void) (-> Indexes (Listof Index)))
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:56:13 prop:equal+hash>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:55:13 prop:custom-write>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:54:13 prop:custom-print-quotable>)
(array #['(0 1 2) '(3 4 5) '(6 7 8)])
- : (Listof (Listof Index))
'((0 1 2) (3 4 5) (6 7 8))
procedure
( list-array->array arr[k])→(Array A)
> arr- : #(struct:Array
(Indexes Index (Boxof Boolean) (-> Void) (-> Indexes (Listof Index)))
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:56:13 prop:equal+hash>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:55:13 prop:custom-write>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:54:13 prop:custom-print-quotable>)
(array #['(0 1 2) '(3 4 5) '(6 7 8)])
- : #(struct:Array
(Indexes Index (Boxof Boolean) (-> Void) (-> Indexes Index))
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:56:13 prop:equal+hash>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:55:13 prop:custom-write>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:54:13 prop:custom-print-quotable>)
(array #[#[0 1 2] #[3 4 5] #[6 7 8]])
For fixed k, this function and array->list-array are mutual inverses with respect to their array arguments.