@@ -22,6 +22,14 @@ def sample_ndarray_2way():
22
22
params = {'data' :ndarrayInstance , 'shape' :shape }
23
23
return params , ndarrayInstance
24
24
25
+ @pytest .fixture ()
26
+ def sample_tensor_3way ():
27
+ data = np .array ([1. , 2. , 3. , 4. , 5. , 6. , 7. , 8. , 9. , 10. , 11. , 12. ])
28
+ shape = (2 , 3 , 2 )
29
+ params = {'data' :np .reshape (data , np .array (shape ), order = 'F' ), 'shape' : shape }
30
+ tensorInstance = ttb .tensor ().from_data (data , shape )
31
+ return params , tensorInstance
32
+
25
33
@pytest .fixture ()
26
34
def sample_ndarray_4way ():
27
35
shape = (2 , 2 , 2 , 2 )
@@ -184,8 +192,9 @@ def test_tenmat_initialization_from_data(sample_ndarray_1way, sample_ndarray_2wa
184
192
assert exc in str (excinfo )
185
193
186
194
@pytest .mark .indevelopment
187
- def test_tenmat_initialization_from_tensor_type (sample_tenmat_4way , sample_tensor_4way ):
195
+ def test_tenmat_initialization_from_tensor_type (sample_tenmat_4way , sample_tensor_3way , sample_tensor_4way ):
188
196
(_ , tensorInstance ) = sample_tensor_4way
197
+ (_ , tensorInstance3 ) = sample_tensor_3way
189
198
(params , tenmatInstance ) = sample_tenmat_4way
190
199
tshape = params ['tshape' ]
191
200
rdims = params ['rdims' ]
@@ -208,6 +217,11 @@ def test_tenmat_initialization_from_tensor_type(sample_tenmat_4way, sample_tenso
208
217
assert tenmatInstance .shape == tenmatTensorRdims .shape
209
218
assert tenmatInstance .tshape == tenmatTensorRdims .tshape
210
219
220
+ # Constructor from tensor using empty rdims
221
+ tenmatTensorRdims = ttb .tenmat .from_tensor_type (tensorInstance3 , rdims = np .array ([]))
222
+ data = np .reshape (np .arange (1 ,13 ),(1 ,12 ))
223
+ assert (tenmatTensorRdims .data == data ).all ()
224
+
211
225
# Constructor from tensor using cdims only
212
226
tenmatTensorCdims = ttb .tenmat .from_tensor_type (tensorInstance , cdims = cdims )
213
227
assert (tenmatInstance .data == tenmatTensorCdims .data ).all ()
@@ -216,6 +230,11 @@ def test_tenmat_initialization_from_tensor_type(sample_tenmat_4way, sample_tenso
216
230
assert tenmatInstance .shape == tenmatTensorCdims .shape
217
231
assert tenmatInstance .tshape == tenmatTensorCdims .tshape
218
232
233
+ # Constructor from tensor using empty cdims
234
+ tenmatTensorCdims = ttb .tenmat .from_tensor_type (tensorInstance3 , cdims = np .array ([]))
235
+ data = np .reshape (np .arange (1 ,13 ),(12 ,1 ))
236
+ assert (tenmatTensorCdims .data == data ).all ()
237
+
219
238
# Constructor from tensor using rdims and cdims
220
239
tenmatTensorRdimsCdims = ttb .tenmat .from_tensor_type (tensorInstance , rdims = rdims , cdims = cdims )
221
240
assert (tenmatInstance .data == tenmatTensorRdimsCdims .data ).all ()
0 commit comments