You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

AutoNumPyAttribute.cs 714 B

1234567891011121314151617181920212223242526272829
  1. using MethodBoundaryAspect.Fody.Attributes;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using static Tensorflow.Binding;
  6. namespace Tensorflow.NumPy
  7. {
  8. [DebuggerStepThrough]
  9. public sealed class AutoNumPyAttribute : OnMethodBoundaryAspect
  10. {
  11. bool _changedMode = false;
  12. public override void OnEntry(MethodExecutionArgs args)
  13. {
  14. if (!tf.executing_eagerly())
  15. {
  16. tf.Context.eager_mode();
  17. _changedMode = true;
  18. }
  19. }
  20. public override void OnExit(MethodExecutionArgs args)
  21. {
  22. if (_changedMode)
  23. tf.Context.restore_mode();
  24. }
  25. }
  26. }