Builders

+eye

Identity matrix of shape nxn.

Accepts

A $meta.

Produces

A $ray.

Source

++  eye      ::  produces identity matrix of shape nxn.
  |=  =meta
  ^-  ray
  ~_  leaf+"lagoon-fail"
  ?>  =(2 (lent shape.meta))
  ?>  =((snag 0 shape.meta) (snag 1 shape.meta))
  =/  n  (snag 0 shape.meta)
  =<  +
  %^    spin
      (gulf 0 (dec n))
    ^-  ray  (zeros [~[n n] bloq.meta kind.meta ~])
  |=  [i=@ r=ray]
  :: [i (set-item r ~[i i] 1)]
  :-  i
  %^  set-item
      r
    ~[i i]
  ^-  @
  ?-    kind.meta
      %uint  `@`1
    ::
      %int2  !!
    ::
      %i754
    ?+  bloq.meta  ~|(bloq.meta !!)
      %7  .~~~1
      %6  .~1
      %5  .1
      %4  .~~1
    ==
  ==

+zeros

An array containing only zeros as values.

Accepts

A $meta of the target shape and parameters.

Produces

A $ray.

Source


+ones

An array containing only ones as values.

Accepts

A $meta of the target shape and parameters.

Produces

A $ray.

Source


+iota

Produce a 1-dimensional index array. Only produces %uint. Note that this runs from 0 to n1n-1. (The point of +iota is to be an index, so it needs to pattern-match the context rather than slavishly follow APL.)

Accepts

A $meta of the target shape and parameters.

Produces

A $ray.

Source

Discussion

The target shape is determined from the length of .shape in .meta.


+magic

Produce a magic square in nn dimensions.

Accepts

A $meta of the target shape and parameters.

Produces

A $ray.

Source


+range

Produce a 1-dimensional range along one dimension as [a,b)[a, b) with interval dd. Only produces %i754.

Accepts

A $meta of the target shape and parameters.

Produces

A $ray.

Source


+linspace

Produce a 1-dimensional range along one dimension as [a,b][a, b] with number of steps nn. Only produces %i754.

Accepts

A $meta of the target shape and parameters, a pair of left-hand and right-hand bounds, and a number of intervals.

Produces

A $ray.

Source

Discussion

The number of intervals n overrides any size specified in the input $meta.


+urge

Coerce 1D array along specified dimension with given overall dimensionality.

Accepts

A $ray, a target dimension index .i, and a resulting overall dimensionality .n.

Produces

A $ray.

Source


+scale

Produce an nn-dimensional array containing a single value.

Accepts

A $meta of the target shape and parameters, and the single value as an atom.

Produces

A $ray.

Source

Last updated