Browse Source

Implement gen_math_ops.mul for Tensors #93

tags/v0.1.0-Tensor
Oceania2018 6 years ago
parent
commit
7f1c92e77d
3 changed files with 18 additions and 2 deletions
  1. +11
    -0
      src/TensorFlowNET.Core/Operations/gen_math_ops.cs
  2. +5
    -0
      src/TensorFlowNET.Core/Tensors/Tensor.Operators.cs
  3. +2
    -2
      test/TensorFlowNET.Examples/BasicOperations.cs

+ 11
- 0
src/TensorFlowNET.Core/Operations/gen_math_ops.cs View File

@@ -19,5 +19,16 @@ namespace Tensorflow


return new Tensor(_op, 0, _op.OutputType(0)); return new Tensor(_op, 0, _op.OutputType(0));
} }

public static Tensor mul(Tensor x, Tensor y)
{
var keywords = new Dictionary<string, object>();
keywords.Add("x", x);
keywords.Add("y", y);

var _op = _op_def_lib._apply_op_helper("Mul", name: "mul", keywords: keywords);

return new Tensor(_op, 0, _op.OutputType(0));
}
} }
} }

+ 5
- 0
src/TensorFlowNET.Core/Tensors/Tensor.Operators.cs View File

@@ -10,5 +10,10 @@ namespace Tensorflow
{ {
return gen_math_ops.add(t1, t2); return gen_math_ops.add(t1, t2);
} }

public static Tensor operator *(Tensor t1, Tensor t2)
{
return gen_math_ops.mul(t1, t2);
}
} }
} }

+ 2
- 2
test/TensorFlowNET.Examples/BasicOperations.cs View File

@@ -18,13 +18,13 @@ namespace TensorFlowNET.Examples
// of the Constant op. // of the Constant op.
var a = tf.constant(2); var a = tf.constant(2);
var b = tf.constant(3); var b = tf.constant(3);
var c = a * b;
// Launch the default graph. // Launch the default graph.
using (var sess = tf.Session()) using (var sess = tf.Session())
{ {
Console.WriteLine("a=2, b=3"); Console.WriteLine("a=2, b=3");
Console.WriteLine($"Addition with constants: {sess.run(a + b)}"); Console.WriteLine($"Addition with constants: {sess.run(a + b)}");
//Console.WriteLine($"Multiplication with constants: {sess.run(a * b)}");
Console.WriteLine($"Multiplication with constants: {sess.run(a * b)}");
} }
} }
} }


Loading…
Cancel
Save