diff --git a/src/TensorFlowNET.Core/Operations/gen_array_ops.cs b/src/TensorFlowNET.Core/Operations/gen_array_ops.cs index 491e98b3..35284eb2 100644 --- a/src/TensorFlowNET.Core/Operations/gen_array_ops.cs +++ b/src/TensorFlowNET.Core/Operations/gen_array_ops.cs @@ -507,6 +507,15 @@ namespace Tensorflow public static Tensor transpose(T1 x, T2 perm, string name = null) { + if (tf.context.executing_eagerly()) + { + var results = tf.Runner.TFE_FastPathExecute(tf.context, tf.context.device_name, + "Transpose", name, + null, + x, perm); + + return results[0]; + } var _op = tf._op_def_lib._apply_op_helper("Transpose", name, new { x, perm }); return _op.outputs[0]; } diff --git a/test/TensorFlowNET.UnitTest/TF_API/TensorOperate.cs b/test/TensorFlowNET.UnitTest/TF_API/TensorOperate.cs new file mode 100644 index 00000000..b3ce7a4a --- /dev/null +++ b/test/TensorFlowNET.UnitTest/TF_API/TensorOperate.cs @@ -0,0 +1,28 @@ +using FluentAssertions; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using NumSharp; +using System.Linq; +using Tensorflow; +using static Tensorflow.Binding; + +namespace Tensorflow.UnitTest.TF_API +{ + [TestClass] + public class TensorOperate + { + [TestMethod] + public void TransposeTest() + { + var a = tf.constant(np.array(new[, , ,] { { { { 1, 11, 2, 22 } }, { { 3, 33, 4, 44 } } }, + { { { 5, 55, 6, 66 } }, { { 7, 77, 8, 88 } } } })); + var b = tf.transpose(a, new[] { 3, 1, 2, 0 }); + var transpose_a = tf.constant(np.array(new[, , ,] { { { { 1, 5 } }, { { 3, 7 } } }, + { { { 11, 55 } }, { { 33, 77 } } }, { { { 2, 6 } }, { { 4, 8 } } }, + { { { 22, 66 } }, { { 44, 88 } } } })); + Assert.IsTrue(Enumerable.SequenceEqual(new[] { 4, 2, 1, 2 }, b.shape)); + Assert.IsTrue(Enumerable.SequenceEqual(transpose_a.numpy().ToArray(), b.numpy().ToArray())); + } + + + } +}