Fork me on GitHub

src/arraymancer/tensor/exporting

  Source Edit

Procs

proc export_tensor[T](t: Tensor[T]): tuple[shape: seq[int], strides: seq[int],
    data: seq[T]] {.noSideEffect.}
Export the tensor as a tuple containing
  • shape
  • strides
  • data

If the tensor was not contiguous (a slice for example), it is reshaped. Data is exported in C order (last index changes the fastest, column in 2D case)

  Source Edit
proc toFlatSeq[T](t: Tensor[T]): seq[T]
Export the data of the Tensor flattened as a Seq   Source Edit
proc toRawSeq[T](t: Tensor[T]): seq[T] {.noSideEffect, ...deprecated: "This proc cannot be reimplemented in a backward compatible way.".}
Deprecated: This proc cannot be reimplemented in a backward compatible way.

Convert a tensor to the raw sequence of data. Important: Up to v0.6.0, Arraymancer always took full ownership of the data it operated on. In particular, even after slicing, it kept tracked of the full memory allocated initially.

This proc used to return the raw in-memory representation of the data without reshaping due to views/slices and offsets This is not true anymore.

It instead returns the canonical row-major serialization of the data.

It is recommended that you implement your own serialization using Arraymancer's unsafe_raw_buf + shape + strides + offset or that you raise your use-case in the issue tracker https://github.com/mratsim/Arraymancer/issues so that more suitable primitives can be crafted

  Source Edit
proc toSeq1D[T](t: Tensor[T]): seq[T]
Exports a rank-1 tensor to a 1D sequence   Source Edit
proc toSeq2D[T](t: Tensor[T]): seq[seq[T]]
Exports a rank-2 tensor to a 2D sequence.   Source Edit
proc toSeq3D[T](t: Tensor[T]): seq[seq[seq[T]]]
Exports a rank-3 tensor to a 3D sequence.   Source Edit
proc toSeq4D[T](t: Tensor[T]): seq[seq[seq[seq[T]]]]
Exports a rank-4 tensor to a 4D sequence.   Source Edit
proc toSeq5D[T](t: Tensor[T]): seq[seq[seq[seq[seq[T]]]]]
Exports a rank-5 tensor to a 5D sequence.   Source Edit
Arraymancer Technical reference Tutorial Spellbook (How-To's) Under the hood