| @@ -18,7 +18,7 @@ namespace Tensorflow.NumPy | |||||
| public static NDArray squeeze(NDArray x1, Axis? axis = null) => new NDArray(array_ops.squeeze(x1, axis)); | public static NDArray squeeze(NDArray x1, Axis? axis = null) => new NDArray(array_ops.squeeze(x1, axis)); | ||||
| [AutoNumPy] | [AutoNumPy] | ||||
| public static NDArray stack(NDArray arrays, Axis axis = null) => new NDArray(array_ops.stack(arrays, axis ?? 0)); | |||||
| public static NDArray stack(params NDArray[] arrays) => new NDArray(array_ops.stack(arrays)); | |||||
| [AutoNumPy] | [AutoNumPy] | ||||
| public static NDArray dstack(params NDArray[] tup) => throw new NotImplementedException(""); | public static NDArray dstack(params NDArray[] tup) => throw new NotImplementedException(""); | ||||
| @@ -94,7 +94,7 @@ namespace Tensorflow.NumPy | |||||
| { | { | ||||
| -1 => "<unknown>", | -1 => "<unknown>", | ||||
| 0 => "()", | 0 => "()", | ||||
| 1 => $"({shape.dims[0]},)", | |||||
| 1 => $"({shape.dims[0].ToString().Replace("-1", "None")},)", | |||||
| _ => $"({string.Join(", ", shape.dims).Replace("-1", "None")})" | _ => $"({string.Join(", ", shape.dims).Replace("-1", "None")})" | ||||
| }; | }; | ||||
| } | } | ||||
| @@ -134,12 +134,41 @@ namespace Tensorflow | |||||
| TensorShape = shape.as_shape_proto() | TensorShape = shape.as_shape_proto() | ||||
| }; | }; | ||||
| // scalar | |||||
| if (values is NDArray nd) | if (values is NDArray nd) | ||||
| { | { | ||||
| var len = nd.dtypesize * nd.size; | |||||
| byte[] bytes = nd.ToByteArray(); | |||||
| tensor_proto.TensorContent = Google.Protobuf.ByteString.CopyFrom(bytes); | |||||
| // scalar | |||||
| if (nd.shape.IsScalar) | |||||
| { | |||||
| switch (nd.dtype) | |||||
| { | |||||
| case TF_DataType.TF_BOOL: | |||||
| tensor_proto.BoolVal.AddRange(nd.ToArray<bool>()); | |||||
| break; | |||||
| case TF_DataType.TF_UINT8: | |||||
| tensor_proto.IntVal.AddRange(nd.ToArray<byte>().Select(x => (int)x).ToArray()); | |||||
| break; | |||||
| case TF_DataType.TF_INT32: | |||||
| tensor_proto.IntVal.AddRange(nd.ToArray<int>()); | |||||
| break; | |||||
| case TF_DataType.TF_INT64: | |||||
| tensor_proto.Int64Val.AddRange(nd.ToArray<long>()); | |||||
| break; | |||||
| case TF_DataType.TF_FLOAT: | |||||
| tensor_proto.FloatVal.AddRange(nd.ToArray<float>()); | |||||
| break; | |||||
| case TF_DataType.TF_DOUBLE: | |||||
| tensor_proto.DoubleVal.AddRange(nd.ToArray<double>()); | |||||
| break; | |||||
| default: | |||||
| throw new Exception("make_tensor_proto Not Implemented"); | |||||
| } | |||||
| } | |||||
| else | |||||
| { | |||||
| var len = nd.dtypesize * nd.size; | |||||
| byte[] bytes = nd.ToByteArray(); | |||||
| tensor_proto.TensorContent = Google.Protobuf.ByteString.CopyFrom(bytes); | |||||
| } | |||||
| } | } | ||||
| else if (dtype == TF_DataType.TF_STRING && !(values is NDArray)) | else if (dtype == TF_DataType.TF_STRING && !(values is NDArray)) | ||||
| { | { | ||||
| @@ -21,6 +21,7 @@ namespace TensorFlowNET.UnitTest.NumPy | |||||
| var zeros = np.zeros((2, 2)); | var zeros = np.zeros((2, 2)); | ||||
| var ones = np.ones((2, 2)); | var ones = np.ones((2, 2)); | ||||
| var full = np.full((2, 2), 0.1f); | var full = np.full((2, 2), 0.1f); | ||||
| Assert.AreEqual(np.float32, full.dtype); | |||||
| } | } | ||||
| [TestMethod] | [TestMethod] | ||||