コード例 #1
0
ファイル: test_client.py プロジェクト: kwmsmith/distarray
class TestDistArrayCreation(IpclusterTestCase):

    """Test distarray creation methods"""

    def setUp(self):
        self.context = Context(self.client)

    def test_zeros(self):
        shape = (16, 16)
        zero_distarray = self.context.zeros(shape)
        zero_ndarray = numpy.zeros(shape)
        assert_array_equal(zero_distarray.tondarray(), zero_ndarray)

    def test_ones(self):
        shape = (16, 16)
        one_distarray = self.context.ones(shape)
        one_ndarray = numpy.ones(shape)
        assert_array_equal(one_distarray.tondarray(), one_ndarray)

    def test_empty(self):
        shape = (16, 16)
        empty_distarray = self.context.empty(shape)
        self.assertEqual(empty_distarray.shape, shape)

    def test_fromndarray(self):
        ndarr = numpy.arange(16).reshape(4, 4)
        distarr = self.context.fromndarray(ndarr)
        for (i, j), val in numpy.ndenumerate(ndarr):
            self.assertEqual(distarr[i, j], ndarr[i, j])
コード例 #2
0
ファイル: test_client.py プロジェクト: imclab/distarray
class TestDistArrayCreation(unittest.TestCase):

    """Test distarray creation methods"""

    def setUp(self):
        self.context = Context()

    def tearDown(self):
        self.context.close()

    def test___init__(self):
        shape = (100, 100)
        distribution = Distribution.from_shape(self.context, shape, ('b', 'c'))
        da = DistArray(distribution, dtype=int)
        da.fill(42)
        nda = numpy.empty(shape, dtype=int)
        nda.fill(42)
        assert_array_equal(da.tondarray(), nda)

    def test_zeros(self):
        shape = (16, 16)
        zero_distarray = self.context.zeros(shape)
        zero_ndarray = numpy.zeros(shape)
        assert_array_equal(zero_distarray.tondarray(), zero_ndarray)

    def test_ones(self):
        shape = (16, 16)
        one_distarray = self.context.ones(shape)
        one_ndarray = numpy.ones(shape)
        assert_array_equal(one_distarray.tondarray(), one_ndarray)

    def test_empty(self):
        shape = (16, 16)
        empty_distarray = self.context.empty(shape)
        self.assertEqual(empty_distarray.shape, shape)

    def test_fromndarray(self):
        ndarr = numpy.arange(16).reshape(4, 4)
        distarr = self.context.fromndarray(ndarr)
        for (i, j), val in numpy.ndenumerate(ndarr):
            self.assertEqual(distarr[i, j], ndarr[i, j])

    def test_grid_rank(self):
        # regression test for issue #235
        a = self.context.empty((4, 4, 4), dist=('b', 'n', 'b'),
                               grid_shape=(1, 1, 4))
        self.assertEqual(a.grid_shape, (1, 1, 4))

    def test_fromfunction(self):
        fn = lambda i, j: i + j
        shape = (7, 9)
        expected = numpy.fromfunction(fn, shape, dtype=int)
        result = self.context.fromfunction(fn, shape, dtype=int)
        assert_array_equal(expected, result.tondarray())
コード例 #3
0
ファイル: test_decorators.py プロジェクト: imclab/distarray
    def test_vectorize(self):
        """Test the @vectorize decorator for parity with NumPy's"""

        context = Context()

        a = numpy.arange(16).reshape(4, 4)
        da = context.fromndarray(a)

        @vectorize
        def da_fn(a, b, c):
            return a**2 + b + c

        @numpy.vectorize
        def a_fn(a, b, c):
            return a**2 + b + c

        a = a_fn(a, a, 6)
        db = da_fn(da, da, 6)
        assert_array_equal(db.toarray(), a)