示例#1
0
 def test_indexing1(self):
     """Can we get and set local elements for a complex dist?"""
     try:
         comm = create_comm_of_size(4)
     except InvalidCommSizeError:
         pass
     else:
         try:
             a = densedistarray.DistArray((16, 16, 2),
                                          dist=('c', 'b', None),
                                          comm=comm)
             b = densedistarray.DistArray((16, 16, 2),
                                          dist=('c', 'b', None),
                                          comm=comm)
         except NullCommError:
             pass
         else:
             for global_inds, value in densedistarray.ndenumerate(a):
                 a[global_inds] = 0.0
             for global_inds, value in densedistarray.ndenumerate(a):
                 b[global_inds] = a[global_inds]
             for global_inds, value in densedistarray.ndenumerate(a):
                 self.assertEquals(b[global_inds], a[global_inds])
                 self.assertEquals(a[global_inds], 0.0)
             comm.Free()
示例#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()
示例#3
0
 def test_indexing1(self):
     """Can we get and set local elements for a complex dist?"""
     try:
         comm = create_comm_of_size(4)
     except InvalidCommSizeError:
         pass
     else:        
         try:
             a = densedistarray.DistArray((16,16,2), dist=('c','b',None),comm=comm)
             b = densedistarray.DistArray((16,16,2), dist=('c','b',None),comm=comm)
         except NullCommError:
             pass
         else:
             for global_inds, value in densedistarray.ndenumerate(a):
                 a[global_inds] = 0.0
             for global_inds, value in densedistarray.ndenumerate(a):
                 b[global_inds] = a[global_inds]
             for global_inds, value in densedistarray.ndenumerate(a):
                 self.assertEquals(b[global_inds],a[global_inds])
                 self.assertEquals(a[global_inds],0.0)                
             comm.Free()    
示例#4
0
 def test_pack_unpack_index(self):
     try:
         comm = create_comm_of_size(4)
     except InvalidCommSizeError:
         pass
     else:        
         try:
             a = densedistarray.DistArray((16,16,2), dist=('c','b',None),comm=comm)
         except NullCommError:
             pass
         else:
             for global_inds, value in densedistarray.ndenumerate(a):
                 packed_ind = a.pack_index(global_inds)
                 self.assertEquals(global_inds, a.unpack_index(packed_ind))
             comm.Free()        
示例#5
0
 def test_pack_unpack_index(self):
     try:
         comm = create_comm_of_size(4)
     except InvalidCommSizeError:
         pass
     else:
         try:
             a = densedistarray.DistArray((16, 16, 2),
                                          dist=('c', 'b', None),
                                          comm=comm)
         except NullCommError:
             pass
         else:
             for global_inds, value in densedistarray.ndenumerate(a):
                 packed_ind = a.pack_index(global_inds)
                 self.assertEquals(global_inds, a.unpack_index(packed_ind))
             comm.Free()
示例#6
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()