Skip to content

Commit 7ec1422

Browse files
committed
fix tensor creation from n-dim array.
1 parent 0c7638f commit 7ec1422

2 files changed

Lines changed: 28 additions & 6 deletions

File tree

‎src/TensorFlowNET.Core/Tensors/constant_op.cs‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,18 +142,32 @@ private static EagerTensor convert_to_eager_tensor(object value, Context ctx, TF
142142
return new EagerTensor(val, ctx.device_name);
143143
case int[,] val:
144144
return new EagerTensor(val, ctx.device_name);
145+
case int[,,] val:
146+
return new EagerTensor(val, ctx.device_name);
145147
case long val:
146148
return new EagerTensor(val, ctx.device_name);
149+
case long[] val:
150+
return new EagerTensor(val, ctx.device_name);
151+
case long[,] val:
152+
return new EagerTensor(val, ctx.device_name);
153+
case long[,,] val:
154+
return new EagerTensor(val, ctx.device_name);
147155
case float val:
148156
return new EagerTensor(val, ctx.device_name);
157+
case float[] val:
158+
return new EagerTensor(val, ctx.device_name);
149159
case float[,] val:
150160
return new EagerTensor(val, ctx.device_name);
151-
case double val:
161+
case float[,,] val:
152162
return new EagerTensor(val, ctx.device_name);
153-
case float[] val:
163+
case double val:
154164
return new EagerTensor(val, ctx.device_name);
155165
case double[] val:
156166
return new EagerTensor(val, ctx.device_name);
167+
case double[,] val:
168+
return new EagerTensor(val, ctx.device_name);
169+
case double[,,] val:
170+
return new EagerTensor(val, ctx.device_name);
157171
default:
158172
throw new NotImplementedException($"convert_to_eager_tensor {value.GetType()}");
159173
}

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,18 @@ public void TransposeTest()
2626
[TestMethod]
2727
public void InitTensorTest()
2828
{
29-
var a = tf.constant(new NDArray(new[, ,] { { { 1 }, { 2 }, { 3 } }, { { 4 }, { 5 }, { 6 } } }));
30-
var b = tf.constant(new[, ,] { { { 1 }, { 2 }, { 3 } }, { { 4 }, { 5 }, { 6 } } });
31-
//Test Result : a is OK , and b is error .
29+
var a = tf.constant(np.array(new[, ,]
30+
{
31+
{ { 1 }, { 2 }, { 3 } },
32+
{ { 4 }, { 5 }, { 6 } }
33+
}));
3234
Assert.IsTrue(Enumerable.SequenceEqual(new[] { 2, 3, 1 }, a.shape));
35+
36+
var b = tf.constant(new[, ,]
37+
{
38+
{ { 1 }, { 2 }, { 3 } },
39+
{ { 4 }, { 5 }, { 6 } }
40+
});
3341
Assert.IsTrue(Enumerable.SequenceEqual(new[] { 2, 3, 1 }, b.shape));
3442
}
3543

@@ -46,7 +54,7 @@ public void ConcatTest()
4654

4755
[TestMethod]
4856
public void ConcatDoubleTest()
49-
{//double type has some error
57+
{
5058
var a = tf.constant(new[,] { { 1.0, 2.0 }, { 3.0, 4.0 } });
5159
var b = tf.constant(new[,] { { 5.0, 6.0 }, { 7.0, 8.0 } });
5260
var c = tf.constant(new[,] { { 9.0, 10.0 }, { 11.0, 12.0 } });

0 commit comments

Comments
 (0)