| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 6ec39ba commit 0347299
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -162,14 +162,17 @@ public Tensor transpose<T1>(T1 a, Axis perm = null, string name = "transpose", b | |||
| 162 | 162 | /// Reverses specific dimensions of a tensor. | |
| 163 | 163 | /// </summary> | |
| 164 | 164 | /// <param name="tensor"></param> | |
| 165 | - /// <param name="axis"></param> | ||
| 165 | + /// <param name="axis">The indices of the dimensions to reverse. Must be in the range [-rank(tensor), rank(tensor)).</param> | ||
| 166 | 166 | /// <param name="name"></param> | |
| 167 | 167 | /// <returns></returns> | |
| 168 | - public Tensor reverse(Tensor tensor, int[] axis, string name = null) | ||
| 169 | - => gen_array_ops.reverse(tensor, ops.convert_to_tensor(axis), name: name); | ||
| 170 | - | ||
| 171 | - public Tensor reverse(Tensor tensor, Tensor axis, string name = null) | ||
| 172 | - => gen_array_ops.reverse(tensor, axis, name: name); | ||
| 168 | + public Tensor reverse(Tensor tensor, Axis axis, string name = null) | ||
| 169 | + { | ||
| 170 | + if (axis.IsScalar) | ||
| 171 | + { | ||
| 172 | + axis = new Axis(axis.axis); | ||
| 173 | + } | ||
| 174 | + return array_ops.reverse(tensor, axis, name: name); | ||
| 175 | + } | ||
| 173 | 176 | ||
| 174 | 177 | /// <summary> | |
| 175 | 178 | /// Returns the rank of a tensor. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -413,6 +413,16 @@ public static Tensor reshape(Tensor tensor, object[] shape, string name = null) | |||
| 413 | 413 | return gen_array_ops.reshape(tensor, dims, name: name); | |
| 414 | 414 | } | |
| 415 | 415 | ||
| 416 | + public static Tensor reverse(Tensor tensor, Tensor axis, string name = null) | ||
| 417 | + => tf.Context.ExecuteOp("ReverseV2", name, new ExecuteOpArgs(tensor, axis) | ||
| 418 | + { | ||
| 419 | + GetGradientAttrs = (op) => new | ||
| 420 | + { | ||
| 421 | + T = op.get_attr<TF_DataType>("T"), | ||
| 422 | + Tidx = op.get_attr<TF_DataType>("Tidx") | ||
| 423 | + } | ||
| 424 | + }); | ||
| 425 | + | ||
| 416 | 426 | private static Tensor ones_like_impl<T>(T tensor, TF_DataType dtype, string name, bool optimize = true) | |
| 417 | 427 | { | |
| 418 | 428 | return tf_with(ops.name_scope(name, "ones_like", new { tensor }), scope => | |
@@ -658,19 +668,17 @@ public static Tensor tile(Tensor input, Tensor multiples, string name = null) | |||
| 658 | 668 | } | |
| 659 | 669 | }); | |
| 660 | 670 | ||
| 661 | - public static Tensor tile(Tensor input, object[] multiples, string name = null) | ||
| 671 | + /*public static Tensor tile(Tensor input, Shape multiples, string name = null) | ||
| 662 | 672 | { | |
| 663 | - Shape dims = shape_utils.from_object_array(multiples); | ||
| 664 | - | ||
| 665 | - return tf.Context.ExecuteOp("Tile", name, new ExecuteOpArgs(input, dims) | ||
| 673 | + return tf.Context.ExecuteOp("Tile", name, new ExecuteOpArgs(input, multiples) | ||
| 666 | 674 | { | |
| 667 | 675 | GetGradientAttrs = (op) => new | |
| 668 | 676 | { | |
| 669 | 677 | T = op.get_attr<TF_DataType>("T"), | |
| 670 | 678 | Tmultiples = op.get_attr<TF_DataType>("Tmultiples") | |
| 671 | 679 | } | |
| 672 | 680 | }); | |
| 673 | - } | ||
| 681 | + }*/ | ||
| 674 | 682 | ||
| 675 | 683 | public static Tensor zeros_like(Tensor tensor, TF_DataType dtype = TF_DataType.DtInvalid, string name = null, bool optimize = true) | |
| 676 | 684 | { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,6 +2,7 @@ | |||
| 2 | 2 | using Tensorflow.NumPy; | |
| 3 | 3 | using Tensorflow; | |
| 4 | 4 | using static Tensorflow.Binding; | |
| 5 | + using System.Linq; | ||
| 5 | 6 | ||
| 6 | 7 | namespace TensorFlowNET.UnitTest.ManagedAPI | |
| 7 | 8 | { | |
@@ -92,5 +93,17 @@ public void TensorArray() | |||
| 92 | 93 | Assert.AreEqual(ta.read(1).numpy(), 20f); | |
| 93 | 94 | Assert.AreEqual(ta.read(2).numpy(), 30f); | |
| 94 | 95 | } | |
| 96 | + | ||
| 97 | + /// <summary> | ||
| 98 | + /// https://www.tensorflow.org/api_docs/python/tf/reverse | ||
| 99 | + /// </summary> | ||
| 100 | + [TestMethod] | ||
| 101 | + public void ReverseArray() | ||
| 102 | + { | ||
| 103 | + var a = tf.random.normal((2, 3)); | ||
| 104 | + var b = tf.reverse(a, -1); | ||
| 105 | + Assert.IsTrue(Equal(a[0].ToArray<float>().Reverse().ToArray(), b[0].ToArray<float>())); | ||
| 106 | + Assert.IsTrue(Equal(a[1].ToArray<float>().Reverse().ToArray(), b[1].ToArray<float>())); | ||
| 107 | + } | ||
| 95 | 108 | } | |
| 96 | 109 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments