Skip to content

v0.0.5

Latest
Compare
Choose a tag to compare
@ShigekiKarita ShigekiKarita released this 15 May 16:59
· 3 commits to master since this release

C header only package

dub add tfd:deimos

import/export TF graph between Python and D

see example/graph_import

mir.ndslice integration

@nogc nothrow @safe
unittest
{
  import tfd;
  import mir.ndslice : iota, sliced;

  auto s = iota(2, 3);
  Tensor t = s.tensor; // reference counted TF_Tensor type
  const st = t.slicedAs(s);
  assert(t.dataType == TF_INT64);
  assert(t.shape[] == s.shape);
  assert(st == s);
}

python-like scripting session.run usage

unittest
{
  import tfd;
  /// tensor add
  with (newGraph)
  {
    import mir.ndslice : as, iota;

    auto i = iota(2, 3, 4).as!float;

    auto x = placeholder!float("x", 2, 3, 4);
    auto two = constant(i);
    auto add = x + two;

    auto results = session.run([add], [x: i.tensor]);
    assert(results[0].sliced!(float, 3) == i * 2);
  }
}

@nogc nothrow usage

version (tfd_test)
@nogc nothrow @safe
unittest
{
  import std.typecons : tuple;
  import tfd.tensor : tensor, Tensor;
  import tfd.graph : newGraph, Operation;

  with (newGraph)
  {
    Operation x = placeholder!int("x");
    Operation two = constant(2);
    Operation add = x + two;

    Operation[1] inops;
    inops[0] = x;
    Tensor[1] inputs;
    inputs[0] = 3.tensor;
    Operation[1] outops;
    outops[0] = add;
    Tensor[1] outputs;
    session.run(inops, inputs, outops, outputs);
    assert(outputs[0].scalar!int == 5);

    write("tmp.pb");
  }
  with (newGraph)
  {
    read("tmp.pb");
    // auto x = operationByName("x");
    // auto add = operationByName("add");
  }
}