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.

NDArray.cs 2.1 kB

4 years ago
4 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*****************************************************************************
  2. Copyright 2021 Haiping Chen. 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. using System.Collections;
  15. using System.Collections.Generic;
  16. using System.Linq;
  17. using System.Text;
  18. using Tensorflow.Util;
  19. using static Tensorflow.Binding;
  20. namespace Tensorflow.NumPy
  21. {
  22. public partial class NDArray : Tensor, IEnumerable<NDArray>
  23. {
  24. public IntPtr data => TensorDataPointer;
  25. [AutoNumPy]
  26. public NDArray reshape(Shape newshape) => new NDArray(tf.reshape(this, newshape));
  27. [AutoNumPy]
  28. public NDArray astype(TF_DataType dtype) => new NDArray(math_ops.cast(this, dtype));
  29. public NDArray ravel() => throw new NotImplementedException("");
  30. public void shuffle(NDArray nd) => np.random.shuffle(nd);
  31. public unsafe Array ToMultiDimArray<T>() where T : unmanaged
  32. => NDArrayConverter.ToMultiDimArray<T>(this);
  33. public byte[] ToByteArray() => BufferToArray();
  34. public override string ToString() => NDArrayRender.ToString(this);
  35. public IEnumerator<NDArray> GetEnumerator()
  36. {
  37. for (int i = 0; i < dims[0]; i++)
  38. yield return this[i];
  39. }
  40. IEnumerator IEnumerable.GetEnumerator()
  41. => GetEnumerator();
  42. public static explicit operator NDArray(Array array)
  43. => new NDArray(array);
  44. }
  45. }