|
2 | 2 | using System.Collections.Generic; |
3 | 3 | using System.Linq; |
4 | 4 | using System.Text; |
| 5 | +using static Tensorflow.Binding; |
5 | 6 |
|
6 | 7 | namespace Tensorflow.NumPy |
7 | 8 | { |
@@ -55,48 +56,12 @@ public NDArray(Shape shape, NumpyDType dtype = NumpyDType.Float) |
55 | 56 | Initialize(shape, dtype: dtype); |
56 | 57 | } |
57 | 58 |
|
58 | | - public NDArray(Tensor value) |
| 59 | + public NDArray(Tensor value, Shape? shape = null) |
59 | 60 | { |
60 | | - _tensor = value; |
61 | | - } |
62 | | - |
63 | | - public NDArray this[params int[] index] |
64 | | - { |
65 | | - get |
66 | | - { |
67 | | - throw new NotImplementedException(""); |
68 | | - } |
69 | | - |
70 | | - set |
71 | | - { |
72 | | - |
73 | | - } |
74 | | - } |
75 | | - |
76 | | - public NDArray this[params Slice[] slices] |
77 | | - { |
78 | | - get |
79 | | - { |
80 | | - throw new NotImplementedException(""); |
81 | | - } |
82 | | - |
83 | | - set |
84 | | - { |
85 | | - |
86 | | - } |
87 | | - } |
88 | | - |
89 | | - public NDArray this[NDArray mask] |
90 | | - { |
91 | | - get |
92 | | - { |
93 | | - throw new NotImplementedException(""); |
94 | | - } |
95 | | - |
96 | | - set |
97 | | - { |
98 | | - |
99 | | - } |
| 61 | + if (shape is not null) |
| 62 | + _tensor = tf.reshape(value, shape); |
| 63 | + else |
| 64 | + _tensor = value; |
100 | 65 | } |
101 | 66 |
|
102 | 67 | public static NDArray Scalar<T>(T value) where T : unmanaged |
@@ -129,15 +94,14 @@ public NDIterator<T> AsIterator<T>(bool autoreset = false) where T : unmanaged |
129 | 94 |
|
130 | 95 | public bool HasNext() => throw new NotImplementedException(""); |
131 | 96 | public T MoveNext<T>() => throw new NotImplementedException(""); |
132 | | - public NDArray reshape(params int[] shape) => throw new NotImplementedException(""); |
133 | | - public NDArray reshape(params long[] shape) => throw new NotImplementedException(""); |
| 97 | + public NDArray reshape(Shape newshape) => new NDArray(_tensor, newshape); |
134 | 98 | public NDArray astype(Type type) => throw new NotImplementedException(""); |
135 | 99 | public NDArray astype(NumpyDType type) => throw new NotImplementedException(""); |
136 | 100 | public bool array_equal(NDArray rhs) => throw new NotImplementedException(""); |
137 | 101 | public NDArray ravel() => throw new NotImplementedException(""); |
138 | 102 | public void shuffle(NDArray nd) => throw new NotImplementedException(""); |
139 | 103 | public Array ToMuliDimArray<T>() => throw new NotImplementedException(""); |
140 | | - public byte[] ToByteArray() => _tensor.ToArray<byte>(); |
| 104 | + public byte[] ToByteArray() => _tensor.BufferToArray(); |
141 | 105 | public static string[] AsStringArray(NDArray arr) => throw new NotImplementedException(""); |
142 | 106 |
|
143 | 107 | public T[] Data<T>() where T : unmanaged |
|
0 commit comments