def test_copy_subset_works_with_strides(self): # Given l1 = LongArray(8) l1.set_data(numpy.arange(8)) l2 = LongArray(4) l2.set_data(numpy.arange(10, 14)) # When l1.copy_subset(l2, 2, 3, stride=2) # Then numpy.testing.assert_array_equal( l1.get_npy_array(), [0, 1, 2, 3, 10, 11, 6, 7] ) # When l1.copy_subset(l2, 2, 4, stride=2) # Then numpy.testing.assert_array_equal( l1.get_npy_array(), [0, 1, 2, 3, 10, 11, 12, 13] )
def test_copy_subset(self): l1 = LongArray(10) l1.set_data(numpy.arange(10)) l2 = LongArray(4) l2[0] = 4 l2[1] = 3 l2[2] = 2 l2[3] = 1 # a valid copy. l1.copy_subset(l2, 5, 9) self.assertEqual(numpy.allclose([0, 1, 2, 3, 4, 4, 3, 2, 1, 9], l1.get_npy_array()), True) # try to copy different sized arrays without any index specification. l1.set_data(numpy.arange(10)) # copy to the last k values of source array. l1.copy_subset(l2, start_index=6) self.assertEqual(numpy.allclose([0, 1, 2, 3, 4, 5, 4, 3, 2, 1], l1.get_npy_array()), True) l1.set_data(numpy.arange(10)) l1.copy_subset(l2, start_index=7) self.assertEqual(numpy.allclose([0, 1, 2, 3, 4, 5, 6, 4, 3, 2], l1.get_npy_array()), True) # some invalid operations. l1.set_data(numpy.arange(10)) self.assertRaises(ValueError, l1.copy_subset, l2, -1, 1) self.assertRaises(ValueError, l1.copy_subset, l2, 3, 2) self.assertRaises(ValueError, l1.copy_subset, l2, 0, 11) self.assertRaises(ValueError, l1.copy_subset, l2, 10, 20) self.assertRaises(ValueError, l1.copy_subset, l2, -1, -1)