tensor

Undocumented in source. Be warned that the author may not have intended to support it.
  1. Tensor tensor(Args args)
  2. Tensor tensor(TF_Tensor* t)
    @nogc nothrow @trusted
    tensor
    (
    TF_Tensor* t
    )

Examples

Make a scalar RCTensor.

const t = tensor(123);

// check content
assert(t.payload!int[0] == 123);
assert(t.ndim == 0);
assert(t.elementCount == 1);
assert(t.shape.length == 0);
assert(t.dataType == TF_INT32);

// check RC
assert(t._counter == 1);
{
  const t1 = t;
  assert(t._counter == 2);
  assert(t1._counter == 2);
}
assert(t._counter == 1);

Make an empty multi-dim RCTensor.

const t = createSlimRC!TensorOwner(empty!double(1, 2, 3));

// check content
assert(t.ndim == 3);
static immutable expectedShape = [1, 2, 3];
assert(t.shape[] == expectedShape);
assert(t.dataType == TF_DOUBLE);

Make a Tensor from iota slice.

import mir.ndslice : iota, sliced;

auto s = iota(2, 3);
auto t = s.tensor;
const st = t.slicedAs(s);
assert(t.dataType == TF_INT64);
assert(t.shape[] == s.shape);
assert(st == s);

Meta