diff --git a/src/TensorFlowNET.Core/NumPy/AutoNumPyAttribute.cs b/src/TensorFlowNET.Core/NumPy/AutoNumPyAttribute.cs index 06f4a2ec..6b463960 100644 --- a/src/TensorFlowNET.Core/NumPy/AutoNumPyAttribute.cs +++ b/src/TensorFlowNET.Core/NumPy/AutoNumPyAttribute.cs @@ -1,6 +1,7 @@ using MethodBoundaryAspect.Fody.Attributes; using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using Tensorflow.Eager; using Tensorflow.Functions; @@ -8,6 +9,7 @@ using static Tensorflow.Binding; namespace Tensorflow.NumPy { + [DebuggerStepThrough] public sealed class AutoNumPyAttribute : OnMethodBoundaryAspect { bool _changedMode = false; diff --git a/src/TensorFlowNET.Core/NumPy/NumPy.Sorting.Searching.Counting.cs b/src/TensorFlowNET.Core/NumPy/NumPy.Sorting.Searching.Counting.cs index b9ad9812..5aecfd6e 100644 --- a/src/TensorFlowNET.Core/NumPy/NumPy.Sorting.Searching.Counting.cs +++ b/src/TensorFlowNET.Core/NumPy/NumPy.Sorting.Searching.Counting.cs @@ -10,7 +10,7 @@ namespace Tensorflow.NumPy { [AutoNumPy] public static NDArray argmax(NDArray a, Axis axis = null) - => new NDArray(math_ops.argmax(a, axis)); + => new NDArray(math_ops.argmax(a, axis ?? 0)); [AutoNumPy] public static NDArray argsort(NDArray a, Axis axis = null) diff --git a/src/TensorFlowNET.Core/Numpy/NDArray.Creation.cs b/src/TensorFlowNET.Core/Numpy/NDArray.Creation.cs index 9b539a07..daec3b5c 100644 --- a/src/TensorFlowNET.Core/Numpy/NDArray.Creation.cs +++ b/src/TensorFlowNET.Core/Numpy/NDArray.Creation.cs @@ -31,7 +31,7 @@ namespace Tensorflow.NumPy public NDArray(IntPtr address, Shape shape, TF_DataType dtype) : base(address, shape, dtype) { NewEagerTensorHandle(); } - public NDArray(Tensor tensor, bool eval = true) : base(tensor.Handle) + public NDArray(Tensor tensor, bool clone = false) : base(tensor.Handle, clone: clone) { if (_handle is null) { diff --git a/src/TensorFlowNET.Core/Operations/Operation.Input.cs b/src/TensorFlowNET.Core/Operations/Operation.Input.cs index 62c03203..0b7bad8b 100644 --- a/src/TensorFlowNET.Core/Operations/Operation.Input.cs +++ b/src/TensorFlowNET.Core/Operations/Operation.Input.cs @@ -35,7 +35,7 @@ namespace Tensorflow tf.Status.Check(true); return num; } - public int NumInputs => c_api.TF_OperationNumInputs(_handle); + public int NumInputs => _handle == IntPtr.Zero ? -1 : c_api.TF_OperationNumInputs(_handle); private TF_DataType[] _input_types => _inputs_val._inputs.Select(x => x.dtype).ToArray(); protected InputList _inputs_val; diff --git a/src/TensorFlowNET.Core/Operations/Operation.Output.cs b/src/TensorFlowNET.Core/Operations/Operation.Output.cs index 921403ee..2fd80fb3 100644 --- a/src/TensorFlowNET.Core/Operations/Operation.Output.cs +++ b/src/TensorFlowNET.Core/Operations/Operation.Output.cs @@ -23,7 +23,7 @@ namespace Tensorflow { public partial class Operation { - public int NumOutputs => c_api.TF_OperationNumOutputs(_handle); + public int NumOutputs => _handle == IntPtr.Zero ? -1 : c_api.TF_OperationNumOutputs(_handle); public TF_DataType OutputType(int index) => c_api.TF_OperationOutputType(_tf_output(index)); public int OutputListLength(string name) @@ -38,7 +38,7 @@ namespace Tensorflow public virtual Tensor[] outputs => _outputs; public Tensor output => _outputs.FirstOrDefault(); - public int NumControlOutputs => c_api.TF_OperationNumControlOutputs(_handle); + public int NumControlOutputs => _handle == IntPtr.Zero ? -1 : c_api.TF_OperationNumControlOutputs(_handle); public int OutputNumConsumers(int index) => c_api.TF_OperationOutputNumConsumers(new TF_Output(_handle, index)); diff --git a/src/TensorFlowNET.Core/Tensors/Tensor.Creation.cs b/src/TensorFlowNET.Core/Tensors/Tensor.Creation.cs index 8d948dbc..6b39f7f8 100644 --- a/src/TensorFlowNET.Core/Tensors/Tensor.Creation.cs +++ b/src/TensorFlowNET.Core/Tensors/Tensor.Creation.cs @@ -39,9 +39,12 @@ namespace Tensorflow /// Create a Tensor object from an existing TF handle /// /// Handle to a object. - public Tensor(SafeTensorHandle handle) + public unsafe Tensor(SafeTensorHandle handle, bool clone = false) { _handle = handle; + if (clone) + _handle = TF_NewTensor(shape, dtype, data: TensorDataPointer.ToPointer()); + isCreatedInGraphMode = !tf.executing_eagerly(); } diff --git a/src/TensorFlowNET.Core/Tensors/Tensor.Value.cs b/src/TensorFlowNET.Core/Tensors/Tensor.Value.cs index 20257ea5..5f00e6d9 100644 --- a/src/TensorFlowNET.Core/Tensors/Tensor.Value.cs +++ b/src/TensorFlowNET.Core/Tensors/Tensor.Value.cs @@ -55,7 +55,7 @@ namespace Tensorflow return new NDArray(str, shape); } - return new NDArray(this); + return new NDArray(this, clone: true); } ///