Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_iterator_labelled(self):
with self.assertRaises(TypeError):
dimod.as_samples(([-1] for _ in range(10)), 'a')
def test_ndarray(self):
arr, labels = dimod.as_samples(np.ones(5, dtype=np.int32))
np.testing.assert_array_equal(arr, np.ones((1, 5)))
self.assertEqual(labels, list(range(5)))
self.assertEqual(arr.dtype, np.int32)
def test_iterator(self):
with self.assertRaises(TypeError):
dimod.as_samples(([-1] for _ in range(10)))
def test_list_of_empty(self):
arr, labels = dimod.as_samples([[], [], []])
np.testing.assert_array_equal(arr, np.empty((3, 0)))
self.assertEqual(labels, [])
arr, labels = dimod.as_samples([{}, {}, {}])
np.testing.assert_array_equal(arr, np.empty((3, 0)))
self.assertEqual(labels, [])
arr, labels = dimod.as_samples(np.empty((3, 0)))
np.testing.assert_array_equal(arr, np.empty((3, 0)))
self.assertEqual(labels, [])
def test_copy_false(self):
samples_like = np.ones((5, 5))
labels = list('abcde')
arr, lab = dimod.as_samples((samples_like, labels))
np.testing.assert_array_equal(arr, np.ones((5, 5)))
self.assertEqual(lab, list('abcde'))
self.assertIs(labels, lab)
self.assertTrue(np.shares_memory(arr, samples_like))
def test_empty_list(self):
# no samples, no labels
arr, labels = dimod.as_samples([])
np.testing.assert_array_equal(arr, np.zeros((0, 0)))
self.assertEqual(labels, [])
def time_empty(self):
dimod.as_samples({})
def time_dict1x1000(self):
dimod.as_samples(self.dict1x1000)
def time_dict1000(self):
dimod.as_samples(self.dict1000)
def time_list1000(self):
dimod.as_samples(self.list1000)