16
16
import itertools
17
17
from scipy .sparse import coo_matrix
18
18
from sagemaker .amazon .common import (record_deserializer , write_numpy_to_dense_tensor , _read_recordio ,
19
- numpy_to_record_serializer , write_numpy_to_sparse_tensor )
19
+ numpy_to_record_serializer , write_spmatrix_to_sparse_tensor )
20
20
from sagemaker .amazon .record_pb2 import Record
21
21
22
22
@@ -135,12 +135,12 @@ def test_invalid_label():
135
135
write_numpy_to_dense_tensor (f , array , label_data )
136
136
137
137
138
- def test_dense_float_write_numpy_to_sparse_tensor ():
138
+ def test_dense_float_write_spmatrix_to_sparse_tensor ():
139
139
array_data = [[1.0 , 2.0 , 3.0 ], [10.0 , 20.0 , 30.0 ]]
140
140
keys_data = [[0 , 1 , 2 ], [0 , 1 , 2 ]]
141
141
array = coo_matrix (np .array (array_data ))
142
142
with tempfile .TemporaryFile () as f :
143
- write_numpy_to_sparse_tensor (f , array )
143
+ write_spmatrix_to_sparse_tensor (f , array )
144
144
f .seek (0 )
145
145
for record_data , expected_data , expected_keys in zip (_read_recordio (f ), array_data , keys_data ):
146
146
record = Record ()
@@ -150,12 +150,12 @@ def test_dense_float_write_numpy_to_sparse_tensor():
150
150
assert record .features ["values" ].float64_tensor .shape == [len (expected_data )]
151
151
152
152
153
- def test_dense_float32_write_numpy_to_sparse_tensor ():
153
+ def test_dense_float32_write_spmatrix_to_sparse_tensor ():
154
154
array_data = [[1.0 , 2.0 , 3.0 ], [10.0 , 20.0 , 30.0 ]]
155
155
keys_data = [[0 , 1 , 2 ], [0 , 1 , 2 ]]
156
156
array = coo_matrix (np .array (array_data ).astype (np .dtype ('float32' )))
157
157
with tempfile .TemporaryFile () as f :
158
- write_numpy_to_sparse_tensor (f , array )
158
+ write_spmatrix_to_sparse_tensor (f , array )
159
159
f .seek (0 )
160
160
for record_data , expected_data , expected_keys in zip (_read_recordio (f ), array_data , keys_data ):
161
161
record = Record ()
@@ -165,12 +165,12 @@ def test_dense_float32_write_numpy_to_sparse_tensor():
165
165
assert record .features ["values" ].float32_tensor .shape == [len (expected_data )]
166
166
167
167
168
- def test_dense_int_write_numpy_to_sparse_tensor ():
168
+ def test_dense_int_write_spmatrix_to_sparse_tensor ():
169
169
array_data = [[1.0 , 2.0 , 3.0 ], [10.0 , 20.0 , 30.0 ]]
170
170
keys_data = [[0 , 1 , 2 ], [0 , 1 , 2 ]]
171
171
array = coo_matrix (np .array (array_data ).astype (np .dtype ('int' )))
172
172
with tempfile .TemporaryFile () as f :
173
- write_numpy_to_sparse_tensor (f , array )
173
+ write_spmatrix_to_sparse_tensor (f , array )
174
174
f .seek (0 )
175
175
for record_data , expected_data , expected_keys in zip (_read_recordio (f ), array_data , keys_data ):
176
176
record = Record ()
@@ -180,13 +180,13 @@ def test_dense_int_write_numpy_to_sparse_tensor():
180
180
assert record .features ["values" ].int32_tensor .shape == [len (expected_data )]
181
181
182
182
183
- def test_dense_int_numpy_to_sparse_label ():
183
+ def test_dense_int_spmatrix_to_sparse_label ():
184
184
array_data = [[1 , 2 , 3 ], [10 , 20 , 3 ]]
185
185
keys_data = [[0 , 1 , 2 ], [0 , 1 , 2 ]]
186
186
array = coo_matrix (np .array (array_data ))
187
187
label_data = np .array ([99 , 98 , 97 ])
188
188
with tempfile .TemporaryFile () as f :
189
- write_numpy_to_sparse_tensor (f , array , label_data )
189
+ write_spmatrix_to_sparse_tensor (f , array , label_data )
190
190
f .seek (0 )
191
191
for record_data , expected_data , expected_keys , label in zip (
192
192
_read_recordio (f ),
@@ -202,13 +202,13 @@ def test_dense_int_numpy_to_sparse_label():
202
202
assert record .features ["values" ].int32_tensor .shape == [len (expected_data )]
203
203
204
204
205
- def test_dense_float32_numpy_to_sparse_label ():
205
+ def test_dense_float32_spmatrix_to_sparse_label ():
206
206
array_data = [[1 , 2 , 3 ], [10 , 20 , 3 ]]
207
207
keys_data = [[0 , 1 , 2 ], [0 , 1 , 2 ]]
208
208
array = coo_matrix (np .array (array_data ).astype ('float32' ))
209
209
label_data = np .array ([99 , 98 , 97 ])
210
210
with tempfile .TemporaryFile () as f :
211
- write_numpy_to_sparse_tensor (f , array , label_data )
211
+ write_spmatrix_to_sparse_tensor (f , array , label_data )
212
212
f .seek (0 )
213
213
for record_data , expected_data , expected_keys , label in zip (
214
214
_read_recordio (f ),
@@ -224,13 +224,13 @@ def test_dense_float32_numpy_to_sparse_label():
224
224
assert record .features ["values" ].float32_tensor .shape == [len (expected_data )]
225
225
226
226
227
- def test_dense_float64_numpy_to_sparse_label ():
227
+ def test_dense_float64_spmatrix_to_sparse_label ():
228
228
array_data = [[1 , 2 , 3 ], [10 , 20 , 3 ]]
229
229
keys_data = [[0 , 1 , 2 ], [0 , 1 , 2 ]]
230
230
array = coo_matrix (np .array (array_data ).astype ('float64' ))
231
231
label_data = np .array ([99 , 98 , 97 ])
232
232
with tempfile .TemporaryFile () as f :
233
- write_numpy_to_sparse_tensor (f , array , label_data )
233
+ write_spmatrix_to_sparse_tensor (f , array , label_data )
234
234
f .seek (0 )
235
235
for record_data , expected_data , expected_keys , label in zip (
236
236
_read_recordio (f ),
@@ -252,10 +252,10 @@ def test_invalid_sparse_label():
252
252
label_data = np .array ([99 , 98 , 97 , 1000 ]).astype (np .dtype ('float64' ))
253
253
with tempfile .TemporaryFile () as f :
254
254
with pytest .raises (ValueError ):
255
- write_numpy_to_sparse_tensor (f , array , label_data )
255
+ write_spmatrix_to_sparse_tensor (f , array , label_data )
256
256
257
257
258
- def test_sparse_float_write_numpy_to_sparse_tensor ():
258
+ def test_sparse_float_write_spmatrix_to_sparse_tensor ():
259
259
n = 4
260
260
array_data = [[1.0 , 2.0 ], [10.0 , 30.0 ], [100.0 , 200.0 , 300.0 , 400.0 ], [1000.0 , 2000.0 , 3000.0 ]]
261
261
keys_data = [[0 , 1 ], [1 , 2 ], [0 , 1 , 2 , 3 ], [0 , 2 , 3 ]]
@@ -267,7 +267,7 @@ def test_sparse_float_write_numpy_to_sparse_tensor():
267
267
268
268
array = coo_matrix ((flatten_data , (x_indices , y_indices )), dtype = 'float64' )
269
269
with tempfile .TemporaryFile () as f :
270
- write_numpy_to_sparse_tensor (f , array )
270
+ write_spmatrix_to_sparse_tensor (f , array )
271
271
f .seek (0 )
272
272
for record_data , expected_data , expected_keys in zip (_read_recordio (f ), array_data , keys_data ):
273
273
record = Record ()
@@ -277,7 +277,7 @@ def test_sparse_float_write_numpy_to_sparse_tensor():
277
277
assert record .features ["values" ].float64_tensor .shape == [n ]
278
278
279
279
280
- def test_sparse_float32_write_numpy_to_sparse_tensor ():
280
+ def test_sparse_float32_write_spmatrix_to_sparse_tensor ():
281
281
n = 4
282
282
array_data = [[1.0 , 2.0 ], [10.0 , 30.0 ], [100.0 , 200.0 , 300.0 , 400.0 ], [1000.0 , 2000.0 , 3000.0 ]]
283
283
keys_data = [[0 , 1 ], [1 , 2 ], [0 , 1 , 2 , 3 ], [0 , 2 , 3 ]]
@@ -289,7 +289,7 @@ def test_sparse_float32_write_numpy_to_sparse_tensor():
289
289
290
290
array = coo_matrix ((flatten_data , (x_indices , y_indices )), dtype = 'float32' )
291
291
with tempfile .TemporaryFile () as f :
292
- write_numpy_to_sparse_tensor (f , array )
292
+ write_spmatrix_to_sparse_tensor (f , array )
293
293
f .seek (0 )
294
294
for record_data , expected_data , expected_keys in zip (_read_recordio (f ), array_data , keys_data ):
295
295
record = Record ()
@@ -299,7 +299,7 @@ def test_sparse_float32_write_numpy_to_sparse_tensor():
299
299
assert record .features ["values" ].float32_tensor .shape == [n ]
300
300
301
301
302
- def test_sparse_int_write_numpy_to_sparse_tensor ():
302
+ def test_sparse_int_write_spmatrix_to_sparse_tensor ():
303
303
n = 4
304
304
array_data = [[1.0 , 2.0 ], [10.0 , 30.0 ], [100.0 , 200.0 , 300.0 , 400.0 ], [1000.0 , 2000.0 , 3000.0 ]]
305
305
keys_data = [[0 , 1 ], [1 , 2 ], [0 , 1 , 2 , 3 ], [0 , 2 , 3 ]]
@@ -311,7 +311,7 @@ def test_sparse_int_write_numpy_to_sparse_tensor():
311
311
312
312
array = coo_matrix ((flatten_data , (x_indices , y_indices )), dtype = 'int' )
313
313
with tempfile .TemporaryFile () as f :
314
- write_numpy_to_sparse_tensor (f , array )
314
+ write_spmatrix_to_sparse_tensor (f , array )
315
315
f .seek (0 )
316
316
for record_data , expected_data , expected_keys in zip (_read_recordio (f ), array_data , keys_data ):
317
317
record = Record ()
@@ -321,10 +321,10 @@ def test_sparse_int_write_numpy_to_sparse_tensor():
321
321
assert record .features ["values" ].int32_tensor .shape == [n ]
322
322
323
323
324
- def test_dense_to_sparse_array ():
324
+ def test_dense_to_sparse ():
325
325
array_data = [[1 , 2 , 3 ], [10 , 20 , 3 ]]
326
326
array = np .array (array_data )
327
327
label_data = np .array ([99 , 98 , 97 ]).astype (np .dtype ('float64' ))
328
328
with tempfile .TemporaryFile () as f :
329
329
with pytest .raises (TypeError ):
330
- write_numpy_to_sparse_tensor (f , array , label_data )
330
+ write_spmatrix_to_sparse_tensor (f , array , label_data )
0 commit comments