Browse Source

Add tf.math.erf #738

tags/yolov3
Oceania2018 4 years ago
parent
commit
c8643c4266
3 changed files with 41 additions and 0 deletions
  1. +9
    -0
      src/TensorFlowNET.Core/APIs/tf.math.cs
  2. +23
    -0
      src/TensorFlowNET.Core/Operations/math_ops.cs
  3. +9
    -0
      test/TensorFlowNET.UnitTest/ManagedAPI/MathApiTest.cs

+ 9
- 0
src/TensorFlowNET.Core/APIs/tf.math.cs View File

@@ -23,6 +23,15 @@ namespace Tensorflow
{
public Tensor log(Tensor x, string name = null)
=> gen_math_ops.log(x, name);

/// <summary>
/// Computes the Gauss error function of `x` element-wise.
/// </summary>
/// <param name="x"></param>
/// <param name="name"></param>
/// <returns></returns>
public Tensor erf(Tensor x, string name = null)
=> math_ops.erf(x, name);
}

public Tensor abs(Tensor x, string name = null)


+ 23
- 0
src/TensorFlowNET.Core/Operations/math_ops.cs View File

@@ -265,6 +265,29 @@ namespace Tensorflow
public static Tensor equal<Tx, Ty>(Tx x, Ty y, string name = null)
=> gen_math_ops.equal(x, y, name: name);

/// <summary>
/// Computes the Gauss error function of `x` element-wise.
/// </summary>
/// <param name="x"></param>
/// <param name="name"></param>
/// <returns></returns>
public static Tensor erf(Tensor x, string name = null)
=> tf.Context.RunInAutoMode2(
() => tf.OpDefLib._apply_op_helper("Erf", name, new { x }).output,
() => tf.Runner.TFE_FastPathExecute(tf.Context, tf.Context.DeviceName,
"Erf", name,
null,
x).FirstOrDefault(),
(op) =>
{
var attrs = new object[]
{
"T", op.get_attr<TF_DataType>("T")
};
tf.Runner.RecordGradient("Erf", op.inputs, attrs, op.outputs);
},
new Tensors(x));

public static Tensor sqrt(Tensor x, string name = null)
=> gen_math_ops.sqrt(x, name: name);



+ 9
- 0
test/TensorFlowNET.UnitTest/ManagedAPI/MathApiTest.cs View File

@@ -48,5 +48,14 @@ namespace TensorFlowNET.UnitTest.ManagedAPI
var x5 = tf.reduce_sum(b, (0, 1));
Assert.AreEqual(-4.7f, (float)x5);
}

[TestMethod]
public void Erf()
{
var erf = tf.math.erf(a, name: "erf");
var expected = new float[] { 0.8427007f, -0.5204999f, 0.99999845f, -0.9970206f, 0f, -1f };
var actual = erf.ToArray<float>();
Assert.IsTrue(Equal(expected, actual));
}
}
}

Loading…
Cancel
Save