@@ -251,6 +251,11 @@ def test_extract_vec(vs):
251251 operations .extract (z2 , x , None )
252252 vector_compare (z2 , xidx , xvals )
253253
254+ # Extract duplicates
255+ z3 = Vector .new (x .dtype , 5 )
256+ operations .extract (z3 , x , [0 , 3 , 3 , 3 , 2 ])
257+ vector_compare (z3 , [1 , 2 , 3 , 4 ], [30. , 30. , 30. , 20. ])
258+
254259
255260def test_extract_mat (mm ):
256261 x , _ = mm
@@ -262,22 +267,22 @@ def test_extract_mat(mm):
262267 matrix_compare (z , xrows , xcols , xvals )
263268
264269 # Extract some rows, some cols
265- z2 = Matrix .new (x .dtype , 2 , 4 )
266- operations .extract (z2 , x , [0 , 4 ], [1 , 2 , 3 , 5 ])
267- matrix_compare (z2 , [0 , 0 , 1 ], [2 , 3 , 1 ], [1.1 , 2.2 , 6.6 ])
270+ z2 = Matrix .new (x .dtype , 2 , 5 )
271+ operations .extract (z2 , x , [0 , 4 ], [1 , 2 , 3 , 5 , 3 ])
272+ matrix_compare (z2 , [0 , 0 , 0 , 1 ], [2 , 3 , 4 , 1 ], [1.1 , 2.2 , 1.1 , 6.6 ])
268273
269274 # Extract some rows, all cols
270- z3 = Matrix .new (x .dtype , 2 , x .shape [1 ])
271- operations .extract (z3 , x , [0 , 4 ], None )
272- matrix_compare (z3 , [0 , 0 , 1 ], [3 , 5 , 2 ], [1.1 , 2.2 , 6.6 ])
275+ z3 = Matrix .new (x .dtype , 4 , x .shape [1 ])
276+ operations .extract (z3 , x , [0 , 4 , 3 , 0 ], None )
277+ matrix_compare (z3 , [0 , 0 , 1 , 3 , 3 ], [3 , 5 , 2 , 3 , 5 ], [1.1 , 2.2 , 6.6 , 1.1 , 2.2 ])
273278
274279 # Extract all rows, some cols
275- z4 = Matrix .new (x .dtype , x .shape [0 ], 4 )
276- operations .extract (z4 , x , None , [1 , 5 , 3 , 2 ])
280+ z4 = Matrix .new (x .dtype , x .shape [0 ], 5 )
281+ operations .extract (z4 , x , None , [1 , 5 , 3 , 2 , 1 ])
277282 matrix_compare (z4 ,
278- [0 , 0 , 1 , 2 , 4 ],
279- [1 , 2 , 2 , 0 , 3 ],
280- [2.2 , 1.1 , 3.3 , 5.5 , 6.6 ])
283+ [0 , 0 , 1 , 2 , 2 , 4 ],
284+ [1 , 2 , 2 , 0 , 4 , 3 ],
285+ [2.2 , 1.1 , 3.3 , 5.5 , 5.5 , 6.6 ])
281286
282287
283288def test_extract_vec_from_mat (mm ):
@@ -293,9 +298,9 @@ def test_extract_vec_from_mat(mm):
293298 vector_compare (z1 , [0 , 1 ], [1.1 , 3.3 ])
294299
295300 # Extract partial row
296- z2 = Vector .new (x .dtype , 5 )
297- operations .extract (z2 , x , 0 , [0 , 1 , 3 , 4 , 5 ])
298- vector_compare (z2 , [2 , 4 ], [1.1 , 2.2 ])
301+ z2 = Vector .new (x .dtype , 8 )
302+ operations .extract (z2 , x , 0 , [0 , 1 , 3 , 4 , 5 , 3 , 5 , 3 ])
303+ vector_compare (z2 , [2 , 4 , 5 , 6 , 7 ], [1.1 , 2.2 , 1.1 , 2.2 , 1.1 ])
299304
300305 # Extract full row
301306 z3 = Vector .new (x .dtype , x .shape [1 ])
0 commit comments