How to use the dimod.as_samples function in dimod

To help you get started, we’ve selected a few dimod examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dwavesystems / dimod / tests / test_sampleset.py View on Github external
def test_iterator_labelled(self):
        with self.assertRaises(TypeError):
            dimod.as_samples(([-1] for _ in range(10)), 'a')
github dwavesystems / dimod / tests / test_sampleset.py View on Github external
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)
github dwavesystems / dimod / tests / test_sampleset.py View on Github external
def test_iterator(self):
        with self.assertRaises(TypeError):
            dimod.as_samples(([-1] for _ in range(10)))
github dwavesystems / dimod / tests / test_sampleset.py View on Github external
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, [])
github dwavesystems / dimod / tests / test_sampleset.py View on Github external
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))
github dwavesystems / dimod / tests / test_sampleset.py View on Github external
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, [])
github dwavesystems / dimod / benchmarks / benchmarks / bench_as_samples.py View on Github external
def time_dict1x1000(self):
        dimod.as_samples(self.dict1x1000)
github dwavesystems / dimod / benchmarks / benchmarks / bench_as_samples.py View on Github external
def time_dict1000(self):
        dimod.as_samples(self.dict1000)
github dwavesystems / dimod / benchmarks / benchmarks / bench_as_samples.py View on Github external
def time_list1000(self):
        dimod.as_samples(self.list1000)