From 083c8e8d6f91c9ddd44b0d37043fa9d74c479af0 Mon Sep 17 00:00:00 2001 From: Oceania2018 Date: Sun, 11 Jul 2021 18:23:20 -0500 Subject: [PATCH] fix ndarray to tensor implicit convertion. --- src/TensorFlowNET.Core/Binding.Util.cs | 6 ++++++ src/TensorFlowNET.Core/NumPy/NDArray.Implicit.cs | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/TensorFlowNET.Core/Binding.Util.cs b/src/TensorFlowNET.Core/Binding.Util.cs index b6403193..5c7641e0 100644 --- a/src/TensorFlowNET.Core/Binding.Util.cs +++ b/src/TensorFlowNET.Core/Binding.Util.cs @@ -508,6 +508,12 @@ namespace Tensorflow public static Shape GetShape(this object data) { + if (data is NDArray nd) + return nd.shape; + + if (data is Tensor tensor) + return tensor.shape; + if (!data.GetType().IsArray) return Shape.Scalar; diff --git a/src/TensorFlowNET.Core/NumPy/NDArray.Implicit.cs b/src/TensorFlowNET.Core/NumPy/NDArray.Implicit.cs index 825c0ac2..1f3064a8 100644 --- a/src/TensorFlowNET.Core/NumPy/NDArray.Implicit.cs +++ b/src/TensorFlowNET.Core/NumPy/NDArray.Implicit.cs @@ -37,7 +37,7 @@ namespace Tensorflow.NumPy => new NDArray(value); public static implicit operator Tensor(NDArray nd) - => nd._tensor; + => constant_op.constant(nd); public static implicit operator NDArray(Tensor tensor) => new NDArray(tensor);