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()
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()
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()
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()
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()
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()