Fork me on GitHub

src/arraymancer/tensor/selectors

Search:
Group by:
  Source Edit

Procs

proc index_fill[T; Idx: byte or char or SomeInteger](t: var Tensor[T];
    axis: int; indices: openArray[Idx]; value: T)
Replace elements of t indicated by their indices along axis with value This is equivalent to Numpy put.   Source Edit
proc index_fill[T; Idx: byte or char or SomeInteger](t: var Tensor[T];
    axis: int; indices: Tensor[Idx]; value: T)
Replace elements of t indicated by their indices along axis with value This is equivalent to Numpy put.   Source Edit
proc index_select[T; Idx: byte or char or SomeInteger](t: Tensor[T]; axis: int;
    indices: openArray[Idx]): Tensor[T] {.noinit.}
Take elements from a tensor along an axis using the indices Tensor. This is equivalent to NumPy take. The result does not share the input storage, there are copies. The tensors containing the indices can be an integer, byte or char tensor.   Source Edit
proc index_select[T; Idx: byte or char or SomeInteger](t: Tensor[T]; axis: int;
    indices: Tensor[Idx]): Tensor[T] {.noinit.}
Take elements from a tensor along an axis using the indices Tensor. This is equivalent to NumPy take. The result does not share the input storage, there are copies. The tensors containing the indices can be an integer, byte or char tensor.   Source Edit
proc masked_axis_fill[T](t: var Tensor[T]; mask: openArray[bool]; axis: int;
                         value: T or Tensor[T])

Take a 1D boolean mask tensor with size equal to the t.shape[axis] The axis indexes that are set to true in the mask will be filled with value

Limitation: If value is a Tensor, only filling via broadcastable tensors is supported at the moment for example if filling axis of a tensor t of shape 4, 3 the corresponding shapes are valid 4, 3.masked_axis_fill(mask = 1, 3, axis = 1, value = 4, 1)

with values t = [ 4, 99, 2, 3, 4, 99, 1, 8, 7, 8, 6, 8].toTensor() mask = false, true, true value = [10, 20, 30, 40].toTensor()

result = [ 4, 10, 10, 3, 20, 20, 1, 30, 30, 8, 40, 40].toTensor()

  Source Edit
proc masked_axis_fill[T](t: var Tensor[T]; mask: Tensor[bool]; axis: int;
                         value: T or Tensor[T])

Take a 1D boolean mask tensor with size equal to the t.shape[axis] The axis indexes that are set to true in the mask will be filled with value

Limitation: If value is a Tensor, only filling via broadcastable tensors is supported at the moment for example if filling axis of a tensor t of shape 4, 3 the corresponding shapes are valid 4, 3.masked_axis_fill(mask = 1, 3, axis = 1, value = 4, 1)

with values t = [ 4, 99, 2, 3, 4, 99, 1, 8, 7, 8, 6, 8].toTensor() mask = false, true, true value = [10, 20, 30, 40].toTensor()

result = [ 4, 10, 10, 3, 20, 20, 1, 30, 30, 8, 40, 40].toTensor()

  Source Edit
proc masked_axis_select[T](t: Tensor[T]; mask: openArray[bool]; axis: int): Tensor[
    T] {.noinit.}

Take elements from a tensor according to the provided boolean mask. The mask must be a 1D tensor and is applied along an axis, by default 0.

The result will be the concatenation of values for which the mask is true.

For example, for a 1D tensor t t.masked_select(t > 0) will return a tensor with only the positive values of t.

The result does not share input storage.

  Source Edit
proc masked_axis_select[T](t: Tensor[T]; mask: Tensor[bool]; axis: int): Tensor[
    T] {.noinit.}

Take elements from a tensor according to the provided boolean mask. The mask must be a 1D tensor and is applied along an axis, by default 0.

The result will be the concatenation of values for which the mask is true.

For example, for a 1D tensor t t.masked_select(t > 0) will return a tensor with only the positive values of t.

The result does not share input storage.

  Source Edit
proc masked_fill[T](t: var Tensor[T]; mask: openArray; value: openArray[T])
Version of masked_fill that takes an openArraybool as the mask and an openArray as the value   Source Edit
proc masked_fill[T](t: var Tensor[T]; mask: openArray; value: T)

For each element t[index] of the input tensor t with index index, check if mask[index] is true. If so, fill it value. Otherwise leave it untouched.

Example:

t.masked_fill(true, false, true, true, -1)

or alternatively:

t.masked_fill(true, false, true, true): -1

In this version of this procedure the boolean mask, which must have the same size as the input tensor t, is an openArray of bools, i.e.:

  • an array or sequence of bools
  • an array of arrays of bools,
  • ...
  Source Edit
proc masked_fill[T](t: var Tensor[T]; mask: openArray; value: Tensor[T])
Version of masked_fill that takes an openArraybool as the mask and a tensor as the value   Source Edit
proc masked_fill[T](t: var Tensor[T]; mask: Tensor[bool]; value: openArray[T])

Version of masked_fill that takes an openArray as the value

For each element t[index] of the input tensor t with index index, check if mask[index] is true. If so fill it with the _next element from the value openArray. Otherwise leave it untouched.

Note that this does _not fill t[index] with value[index], but with the n-th element of value where n is the number of true elements in the mask before and including the index-th mask element. Because of this, the value openArray must have at least as many elements as the number of true elements in the mask. If that is not the case an IndexDefect exception will be raised at runtime. The value tensor can have even more values which will simply be ignored.

Example:

t.masked_fill(t > 0, 3, 4, -1)

In this version of this procedure the boolean mask is a Tensor[bool] with the same size as the input tensor t.

  Source Edit
proc masked_fill[T](t: var Tensor[T]; mask: Tensor[bool]; value: T)

For each element t[index] of the input tensor t with index index, check if mask[index] is true. If so, fill it value. Otherwise leave it untouched.

Example:

t.masked_fill(t > 0, -1)

or alternatively:

t.masked_fill(t > 0): -1

In this version of this procedure the boolean mask is a Tensor[bool] with the same size as the input tensor t.

  Source Edit
proc masked_fill[T](t: var Tensor[T]; mask: Tensor[bool]; value: Tensor[T])

For each element t[index] of the input tensor t with index index, check if mask[index] is true. If so fill it with the _next element from the value tensor. Otherwise leave it untouched.

Note that this does _not fill t[index] with value[index], but with the n-th element of value where n is the number of true elements in the mask before and including the index-th mask element. Because of this, the value tensor must have at least as many elements as the number of true elements in the mask. If that is not the case an IndexDefect exception will be raised at runtime. The value tensor can have even more values which will simply be ignored.

Example:

t.masked_fill(t > 0, 3, 4, -1.toTensor)

In this version of this procedure the boolean mask is a Tensor[bool] with the same size as the input tensor t.

  Source Edit
proc masked_fill_along_axis[T](t: var Tensor[T]; mask: Tensor[bool]; axis: int;
                               value: T)
Take a boolean mask tensor and for each slice of t along the axis Set the slice elements to value if their mask is true   Source Edit
proc masked_select[T](t: Tensor[T]; mask: openArray): Tensor[T] {.noinit.}

Take elements from a tensor according to the provided boolean mask

The boolean mask must be

  • an array or sequence of bools
  • an array of arrays of bools,
  • ...

Returns a flattened tensor which is the concatenation of values for which the mask is true.

The result does not share input storage.

  Source Edit
proc masked_select[T](t: Tensor[T]; mask: Tensor[bool]): Tensor[T] {.noinit.}

Take elements from a tensor according to the provided boolean mask

Returns a flattened tensor which is the concatenation of values for which the mask is true.

The result does not share input storage.

  Source Edit
Arraymancer Technical reference Tutorial Spellbook (How-To's) Under the hood