Skip to content

Commit 47ba2ae

Browse files
pepureOceania2018
authored andcommitted
add tf.split problem describe
1 parent 13f20d2 commit 47ba2ae

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

‎src/TensorFlowNET.Core/Operations/gen_array_ops.cs‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,16 @@ public static Tensor slice(Tensor input, Tensor begin, Tensor size, string name
485485

486486
public static Tensor[] split(Tensor axis, Tensor value, int num_split, string name = null)
487487
{
488+
if (tf.context.executing_eagerly())
489+
{
490+
var results = tf.Runner.TFE_FastPathExecute(tf.context, tf.context.device_name,
491+
"Split", name,
492+
null,
493+
axis, value, num_split);
494+
495+
return results;
496+
}
497+
488498
var _op = tf._op_def_lib._apply_op_helper("Split", name, new { split_dim = axis, value, num_split });
489499
return _op.outputs;
490500
}

‎test/TensorFlowNET.UnitTest/TF_API/TensorOperate.cs‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,19 @@ public void ConcatDoubleTest()
5252
var concatValue = tf.concat(new[] { a, b, c }, axis: 0);
5353
Assert.IsTrue(Enumerable.SequenceEqual(new[] { 6, 2 }, concatValue.shape));
5454
}
55+
[TestMethod]
56+
public void SplitTest()
57+
{
58+
var a = tf.constant(new[,] { { 1, 2 }, { 3, 4 } });
59+
var b = tf.constant(new[,] { { 5, 6 }, { 7, 8 } });
60+
var c = tf.constant(new[,] { { 9, 10 }, { 11, 12 } });
61+
62+
var concatValue = tf.concat(new[] { a, b, c }, axis: 0);
63+
64+
var splitValue = tf.split(concatValue, 3, axis: new Tensor(0));
65+
Assert.IsTrue(Enumerable.SequenceEqual(new[] { 2, 2 }, splitValue[0].shape));
66+
67+
}
68+
5569
}
5670
}

0 commit comments

Comments
 (0)