Ejemplo n.º 1
0
    def test_complex128(self):
        try:
            comm = create_comm_of_size(4)
        except InvalidCommSizeError:
            pass
        else:
            try:

                def f(i, j):
                    return i + j

                da = densedistarray.fromfunction(f, (16, 16),
                                                 dist=('b', None),
                                                 comm=comm,
                                                 dtype='complex128')
            except NullCommError:
                pass
            else:
                result = fftw.fft2(da)
                numpy_result = np.fft.fft2(
                    np.fromfunction(f, (16, 16), dtype='complex128'))
                (low, high) = result.global_limits(0)
                assert_array_almost_equal(result.local_view(),
                                          numpy_result[low:high + 1, :], 6)
                # Compare the part of numpy_result that this processor has with result.local_array
                comm.Free()
Ejemplo n.º 2
0
    def test_fromfunction_complicated(self):
        """
        Can we build an array using fromfunction and a nontrivial function.
        """
        def f(*global_inds):
            return sum(global_inds)

        try:
            comm = create_comm_of_size(4)
        except InvalidCommSizeError:
            pass
        else:
            try:
                a = densedistarray.fromfunction(f, (16, 16),
                                                dtype='int64',
                                                dist=('b', 'c'),
                                                comm=comm)
            except NullCommError:
                pass
            else:
                self.assertEquals(a.shape, (16, 16))
                self.assertEquals(a.dtype, np.dtype('int64'))
                for global_inds, value in densedistarray.ndenumerate(a):
                    self.assertEquals(sum(global_inds), value)
                comm.Free()
Ejemplo n.º 3
0
 def test_complex128(self):
     try:
         comm = create_comm_of_size(4)
     except InvalidCommSizeError:
         pass
     else:
         try:
             def f(i,j):
                 return i+j
             da = densedistarray.fromfunction(f,(16,16), dist=('b',None),comm=comm,dtype='complex128')
         except NullCommError:
             pass
         else:
             result = fftw.fft2(da)
             numpy_result = np.fft.fft2(np.fromfunction(f,(16,16),dtype='complex128'))
             (low, high) = result.global_limits(0)
             assert_array_almost_equal(result.local_view(), numpy_result[low:high+1,:], 6)
             # Compare the part of numpy_result that this processor has with result.local_array
             comm.Free()
Ejemplo n.º 4
0
 def test_fromfunction_complicated(self):
     """
     Can we build an array using fromfunction and a nontrivial function.
     """
     def f(*global_inds):
         return sum(global_inds)
     
     try:
         comm = create_comm_of_size(4)
     except InvalidCommSizeError:
         pass
     else:
         try:
             a = densedistarray.fromfunction(f, (16,16), dtype='int64', dist=('b','c'), comm=comm)
         except NullCommError:
             pass
         else:
             self.assertEquals(a.shape, (16,16))
             self.assertEquals(a.dtype, np.dtype('int64'))
             for global_inds, value in densedistarray.ndenumerate(a):
                 self.assertEquals(sum(global_inds), value)
             comm.Free()