6.11 Indexing and Slicing
Returns the element of
arr at position
js. If any index in
js is
negative or not less than its corresponding axis length,
array-ref raises an error.
Sets the element of
arr at position
js to
value.
If any index in
js is negative or not less than its corresponding axis length,
array-set! raises an error.
High-level explanation: Returns multiple elements from arr in a new array.
Lower-level explanation: Returns an array with same shape as
idxs, whose elements are
array-ref’d from
arr using the indexes in
idxs.
Examples: |
> (define arr (array #[#[1 2] #[10 20]])) | | > (define idxs (array #['#(0 0) '#(1 1)])) | | > (array-indexes-ref arr idxs) | eval:212:0: Type Checker: missing type for top-level identifier; | either undefined or missing a type annotation | identifier: arr38 | in: idxs | context...: | /Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/typed-racket-lib/typed-racket/utils/tc-utils.rkt:123:0: report-all-errors | /Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/typed-racket-lib/typed-racket/typecheck/tc-toplevel.rkt:515:0: tc-toplevel-form | fail-to-succeed | /Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/typed-racket-lib/typed-racket/tc-setup.rkt:39:0: tc-setup | /Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/typed-racket-lib/typed-racket/typed-racket.rkt:24:4 | /Users/mflatt/build/macro/racket/collects/racket/private/more-scheme.rkt:148:2: call-with-break-parameterization | /Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/sandbox-lib/racket/sandbox.rkt:837:5: loop | eval:212:0: Type Checker: missing type for top-level identifier; | either undefined or missing a type annotation | identifier: idxs39 | in: idxs | context...: | /Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/typed-racket-lib/typed-racket/utils/tc-utils.rkt:123:0: report-all-errors | /Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/typed-racket-lib/typed-racket/typecheck/tc-toplevel.rkt:515:0: tc-toplevel-form | fail-to-succeed | /Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/typed-racket-lib/typed-racket/tc-setup.rkt:39:0: tc-setup | /Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/typed-racket-lib/typed-racket/typed-racket.rkt:24:4 | /Users/mflatt/build/macro/racket/collects/racket/private/more-scheme.rkt:148:2: call-with-break-parameterization | /Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/sandbox-lib/racket/sandbox.rkt:837:5: loop |
| Type Checker: Summary: 2 errors encountered |
|
|
eval:213:0: Type Checker: missing type for top-level identifier; | either undefined or missing a type annotation | identifier: idxs39 | in: js | context...: | /Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/typed-racket-lib/typed-racket/utils/tc-utils.rkt:123:0: report-all-errors | /Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/typed-racket-lib/typed-racket/typecheck/tc-toplevel.rkt:515:0: tc-toplevel-form | fail-to-succeed | /Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/typed-racket-lib/typed-racket/tc-setup.rkt:39:0: tc-setup | /Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/typed-racket-lib/typed-racket/typed-racket.rkt:24:4 | /Users/mflatt/build/macro/racket/collects/racket/private/more-scheme.rkt:148:2: call-with-break-parameterization | /Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/sandbox-lib/racket/sandbox.rkt:837:5: loop | eval:213:0: Type Checker: missing type for top-level identifier; | either undefined or missing a type annotation | identifier: arr38 | in: js | context...: | /Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/typed-racket-lib/typed-racket/utils/tc-utils.rkt:123:0: report-all-errors | /Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/typed-racket-lib/typed-racket/typecheck/tc-toplevel.rkt:515:0: tc-toplevel-form | fail-to-succeed | /Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/typed-racket-lib/typed-racket/tc-setup.rkt:39:0: tc-setup | /Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/typed-racket-lib/typed-racket/typed-racket.rkt:24:4 | /Users/mflatt/build/macro/racket/collects/racket/private/more-scheme.rkt:148:2: call-with-break-parameterization | /Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/sandbox-lib/racket/sandbox.rkt:837:5: loop | eval:213:0: Type Checker: missing type for top-level identifier; | either undefined or missing a type annotation | identifier: idxs39 | in: js | context...: | /Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/typed-racket-lib/typed-racket/utils/tc-utils.rkt:133:21: for-loop | /Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/typed-racket-lib/typed-racket/utils/tc-utils.rkt:123:0: report-all-errors | /Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/typed-racket-lib/typed-racket/typecheck/tc-toplevel.rkt:515:0: tc-toplevel-form | fail-to-succeed | /Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/typed-racket-lib/typed-racket/tc-setup.rkt:39:0: tc-setup | /Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/typed-racket-lib/typed-racket/typed-racket.rkt:24:4 | /Users/mflatt/build/macro/racket/collects/racket/private/more-scheme.rkt:148:2: call-with-break-parameterization | /Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/sandbox-lib/racket/sandbox.rkt:837:5: loop |
|
Type Checker: Summary: 3 errors encountered |
but faster.
Indexes
arr in the same way that
array-indexes-ref does, but mutates elements.
If
idxs and
vals do not have the same shape, they are
broadcast first.
Examples: |
> (define arr (mutable-array #[#[1 2] #[10 20]])) | | > (define idxs (array #['#(0 0) '#(1 1)])) | | > (array-indexes-set! arr idxs (array -1)) | eval:216:0: Type Checker: missing type for top-level identifier; | either undefined or missing a type annotation | identifier: arr40 | in: -1 | context...: | /Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/typed-racket-lib/typed-racket/utils/tc-utils.rkt:123:0: report-all-errors | /Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/typed-racket-lib/typed-racket/typecheck/tc-toplevel.rkt:515:0: tc-toplevel-form | fail-to-succeed | /Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/typed-racket-lib/typed-racket/tc-setup.rkt:39:0: tc-setup | /Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/typed-racket-lib/typed-racket/typed-racket.rkt:24:4 | /Users/mflatt/build/macro/racket/collects/racket/private/more-scheme.rkt:148:2: call-with-break-parameterization | /Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/sandbox-lib/racket/sandbox.rkt:837:5: loop | eval:216:0: Type Checker: missing type for top-level identifier; | either undefined or missing a type annotation | identifier: idxs41 | in: -1 | context...: | /Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/typed-racket-lib/typed-racket/utils/tc-utils.rkt:123:0: report-all-errors | /Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/typed-racket-lib/typed-racket/typecheck/tc-toplevel.rkt:515:0: tc-toplevel-form | fail-to-succeed | /Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/typed-racket-lib/typed-racket/tc-setup.rkt:39:0: tc-setup | /Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/typed-racket-lib/typed-racket/typed-racket.rkt:24:4 | /Users/mflatt/build/macro/racket/collects/racket/private/more-scheme.rkt:148:2: call-with-break-parameterization | /Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/sandbox-lib/racket/sandbox.rkt:837:5: loop |
| Type Checker: Summary: 2 errors encountered | > arr | eval:217:0: Type Checker: missing type for top-level | identifier; | either undefined or missing a type annotation | identifier: arr40 | in: arr |
|
When two indexes in idxs are the same, the element at that index is mutated more
than once in some unspecified order.
Returns a transformation of
arr according to the list of slice specifications
specs. See
Slicing for a discussion and examples.
Examples: |
> (define arr (array->mutable-array (axis-index-array #(5 5) 1))) | | > (array-slice-set! arr (list (:: 1 #f 2) (::)) (array 1)) | eval:219:0: Type Checker: missing type for top-level | identifier; | either undefined or missing a type annotation | identifier: arr42 | in: 1 | > arr | eval:220:0: Type Checker: missing type for top-level | identifier; | either undefined or missing a type annotation | identifier: arr42 | in: arr | | eval:221:0: Type Checker: missing type for top-level identifier; | either undefined or missing a type annotation | identifier: arr42 | in: -1 | context...: | /Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/typed-racket-lib/typed-racket/utils/tc-utils.rkt:123:0: report-all-errors | /Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/typed-racket-lib/typed-racket/typecheck/tc-toplevel.rkt:515:0: tc-toplevel-form | fail-to-succeed | /Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/typed-racket-lib/typed-racket/tc-setup.rkt:39:0: tc-setup | /Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/typed-racket-lib/typed-racket/typed-racket.rkt:24:4 | /Users/mflatt/build/macro/racket/collects/racket/private/more-scheme.rkt:148:2: call-with-break-parameterization | /Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/sandbox-lib/racket/sandbox.rkt:837:5: loop | eval:221:0: Type Checker: missing type for top-level identifier; | either undefined or missing a type annotation | identifier: arr42 | in: -1 | context...: | /Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/typed-racket-lib/typed-racket/utils/tc-utils.rkt:123:0: report-all-errors | /Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/typed-racket-lib/typed-racket/typecheck/tc-toplevel.rkt:515:0: tc-toplevel-form | fail-to-succeed | /Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/typed-racket-lib/typed-racket/tc-setup.rkt:39:0: tc-setup | /Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/typed-racket-lib/typed-racket/typed-racket.rkt:24:4 | /Users/mflatt/build/macro/racket/collects/racket/private/more-scheme.rkt:148:2: call-with-break-parameterization | /Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/sandbox-lib/racket/sandbox.rkt:837:5: loop |
| Type Checker: Summary: 2 errors encountered | > arr | eval:222:0: Type Checker: missing type for top-level | identifier; | either undefined or missing a type annotation | identifier: arr42 | in: arr |
|
When a slice specification refers to an element in arr more than once, the element is
mutated more than once in some unspecified order.
The type of a slice specification. Currently defined as
A (Sequenceof Integer) slice specification causes array-slice-ref to pick rows
from an axis.
An Integer slice specification causes array-slice-ref to remove an axis by
replacing it with one of its rows.
See Slicing for an extended example.
The type of
in-range-like slice specifications, its constructor, predicate, and accessors.
array-slice-ref interprets a Slice like an in-range sequence object.
When start or end is #f, it is interpreted as an axis-length-dependent
endpoint.
Given a slice
s and an axis length
dk, returns the arguments to
in-range
that would produce an equivalent slice specification.
This is used internally by array-slice-ref to interpret a Slice object as a
sequence of indexes.
The type of greedy, multiple-axis-preserving slice specifications, its singleton value, and predicate.
The type of slice specifications that indicate inserting a new axis, its constructor, predicate, and
accessor. The axis length dk must be nonnegative.