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.

Operation.Implicit.cs 1.9 kB

5 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*****************************************************************************
  2. Copyright 2018 The TensorFlow.NET Authors. All Rights Reserved.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ******************************************************************************/
  13. using System;
  14. namespace Tensorflow
  15. {
  16. /// <summary>
  17. /// Convert to other datatype implicitly
  18. /// </summary>
  19. public partial class Operation
  20. {
  21. // make sure the new op is in the same graph instance
  22. public static implicit operator Operation(IntPtr handle)
  23. => new Operation(handle);
  24. public static implicit operator IntPtr(Operation op)
  25. => op._handle;
  26. public static implicit operator Tensor(Operation op)
  27. => op.output;
  28. public static implicit operator RefVariable(Operation op)
  29. => new RefVariable(op);
  30. public override string ToString()
  31. {
  32. return _handle == IntPtr.Zero ? "tf.Operation Undefined" : $"<tf.Operation '{name}' type={OpType}>";
  33. }
  34. public override bool Equals(object obj)
  35. {
  36. switch (obj)
  37. {
  38. case IntPtr val:
  39. return val == _handle;
  40. case Operation val:
  41. return val._handle == _handle;
  42. }
  43. return base.Equals(obj);
  44. }
  45. }
  46. }