| @@ -52,7 +52,6 @@ namespace Tensorflow | |||||
| using (var status = new Status()) | using (var status = new Status()) | ||||
| using (var graph_def = new Buffer(bytes)) | using (var graph_def = new Buffer(bytes)) | ||||
| { | { | ||||
| as_default(); | |||||
| c_api.TF_ImportGraphDefOptionsSetPrefix(opts.Handle, prefix); | c_api.TF_ImportGraphDefOptionsSetPrefix(opts.Handle, prefix); | ||||
| c_api.TF_GraphImportGraphDef(_handle, graph_def.Handle, opts.Handle, status.Handle); | c_api.TF_GraphImportGraphDef(_handle, graph_def.Handle, opts.Handle, status.Handle); | ||||
| status.Check(true); | status.Check(true); | ||||
| @@ -2,6 +2,7 @@ | |||||
| using System; | using System; | ||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||
| using System.Diagnostics; | using System.Diagnostics; | ||||
| using System.Threading; | |||||
| using static Tensorflow.Binding; | using static Tensorflow.Binding; | ||||
| namespace Tensorflow.NumPy | namespace Tensorflow.NumPy | ||||
| @@ -10,9 +11,12 @@ namespace Tensorflow.NumPy | |||||
| public sealed class AutoNumPyAttribute : OnMethodBoundaryAspect | public sealed class AutoNumPyAttribute : OnMethodBoundaryAspect | ||||
| { | { | ||||
| bool _changedMode = false; | bool _changedMode = false; | ||||
| bool _locked = false; | |||||
| static object locker = new Object(); | |||||
| public override void OnEntry(MethodExecutionArgs args) | public override void OnEntry(MethodExecutionArgs args) | ||||
| { | { | ||||
| Monitor.Enter(locker, ref _locked); | |||||
| if (!tf.executing_eagerly()) | if (!tf.executing_eagerly()) | ||||
| { | { | ||||
| tf.Context.eager_mode(); | tf.Context.eager_mode(); | ||||
| @@ -24,6 +28,9 @@ namespace Tensorflow.NumPy | |||||
| { | { | ||||
| if (_changedMode) | if (_changedMode) | ||||
| tf.Context.restore_mode(); | tf.Context.restore_mode(); | ||||
| if (_locked) | |||||
| Monitor.Exit(locker); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -30,6 +30,7 @@ namespace Tensorflow.NumPy | |||||
| [AutoNumPy] | [AutoNumPy] | ||||
| public NDArray reshape(Shape newshape) => new NDArray(tf.reshape(this, newshape)); | public NDArray reshape(Shape newshape) => new NDArray(tf.reshape(this, newshape)); | ||||
| [AutoNumPy] | |||||
| public NDArray astype(TF_DataType dtype) => new NDArray(math_ops.cast(this, dtype)); | public NDArray astype(TF_DataType dtype) => new NDArray(math_ops.cast(this, dtype)); | ||||
| public NDArray ravel() => throw new NotImplementedException(""); | public NDArray ravel() => throw new NotImplementedException(""); | ||||
| public void shuffle(NDArray nd) => np.random.shuffle(nd); | public void shuffle(NDArray nd) => np.random.shuffle(nd); | ||||
| @@ -126,7 +126,6 @@ namespace Tensorflow | |||||
| return tf_with(ops.name_scope(name, "Cast", new { x }), scope => | return tf_with(ops.name_scope(name, "Cast", new { x }), scope => | ||||
| { | { | ||||
| name = scope; | name = scope; | ||||
| x = ops.convert_to_tensor(x, name: "x"); | |||||
| if (x.dtype.as_base_dtype() != base_type) | if (x.dtype.as_base_dtype() != base_type) | ||||
| x = gen_math_ops.cast(x, base_type, name: name); | x = gen_math_ops.cast(x, base_type, name: name); | ||||
| @@ -101,7 +101,7 @@ namespace Tensorflow | |||||
| value is NDArray nd && | value is NDArray nd && | ||||
| nd.dtype != dtype) | nd.dtype != dtype) | ||||
| { | { | ||||
| value = nd.astype(dtype); | |||||
| value = math_ops.cast(nd, dtype); | |||||
| } | } | ||||
| // non ascii char | // non ascii char | ||||
| @@ -197,13 +197,6 @@ namespace TensorFlowNET.UnitTest | |||||
| return new AndConstraint<NDArrayAssertions>(this); | return new AndConstraint<NDArrayAssertions>(this); | ||||
| } | } | ||||
| public AndConstraint<NDArrayAssertions> BeScalar(object value) | |||||
| { | |||||
| Subject.shape.IsScalar.Should().BeTrue(); | |||||
| Subject.GetValue().Should().Be(value); | |||||
| return new AndConstraint<NDArrayAssertions>(this); | |||||
| } | |||||
| public AndConstraint<NDArrayAssertions> BeOfType(Type typeCode) | public AndConstraint<NDArrayAssertions> BeOfType(Type typeCode) | ||||
| { | { | ||||
| Subject.dtype.Should().Be(typeCode); | Subject.dtype.Should().Be(typeCode); | ||||