enclose - create an enclosed scalar or list of enclosed scalars from a value
val.enclose()
val.enclose(axis)
The enclose operator encloses a value to make a scalar. It
is similar to APL
⊂
val or
⊂[
axis]
val. Encloses part or all of val in an
Enclosure
or an array of enclosures. If no
axis is given, encloses val in a single-element
Enclosure
. If an axis is given, creates a
generic Array
of rank one less than the source
array, with the given axis omitted. Each element of the
resulting Array
is an enclosure of a sub-array of
the original val, with elements along the axis grouped
together. For example:
An Enclosure
or list of
Enclosure
s
RangeCheck
if the given axis does not
match the shape of val
ShapeCheck
if a non-scalar axis has a rank greater than 1
ShapeCheck
if a vector axis repeats any
axis number
// Make the boxes easier to see by using Unicode box drawing chars io::FormatFlags = io::FMT_FORCE_WIDE arr=[2,3].iterate() arr 0 1 2 3 4 5 encl = arr.enclose() encl ┌─────┐ │0 1 2│ │3 4 5│ └─────┘ // An enclosure is a scalar for the purposes of array conformance encl * [[1,10],[100,1000]] ┌───────┐ ┌──────────┐ │┌─────┐│ │┌────────┐│ ││0 1 2││ ││ 0 10 20││ ││3 4 5││ ││30 40 50││ │└─────┘│ │└────────┘│ └───────┘ └──────────┘ ┌─────────────┐ ┌────────────────┐ │┌───────────┐│ │┌──────────────┐│ ││ 0 100 200││ ││ 0 1000 2000││ ││300 400 500││ ││3000 4000 5000││ │└───────────┘│ │└──────────────┘│ └─────────────┘ └────────────────┘ arr.enclose(0) ┌─────┐ ┌─────┐ ┌─────┐ │┌───┐│ │┌───┐│ │┌───┐│ ││0 3││ ││1 4││ ││2 5││ │└───┘│ │└───┘│ │└───┘│ └─────┘ └─────┘ └─────┘ arr.enclose(1) ┌───────┐ ┌───────┐ │┌─────┐│ │┌─────┐│ ││0 1 2││ ││3 4 5││ │└─────┘│ │└─────┘│ └───────┘ └───────┘