def test_non_existing_backend(): with pytest.raises(RuntimeError, match="backend"): gt_store.empty( "non_existing_backend", default_origin=[0, 0, 0], shape=[10, 10, 10], dtype=(np.float64, (3,)), )
def test_masked_storage_asserts(): default_origin = (1, 1, 1) shape = (2, 2, 2) with pytest.raises(ValueError): gt_store.empty( dtype=np.float64, default_origin=default_origin, shape=shape, mask=(), backend="gtx86", )
def test_masked_storage_asserts(): default_origin = (1, 1, 1) shape = (2, 2, 2) mask = () try: gt_store.empty( dtype=np.float64, default_origin=default_origin, shape=shape, mask=mask, backend="gtx86", ) except ValueError: pass except Exception as e: raise e else: assert False
def test_masked_storage_gpu(param_dict): mask = param_dict["mask"] default_origin = param_dict["default_origin"] shape = param_dict["shape"] # no assert when all is defined in descriptor, no grid_group store = gt_store.empty( dtype=np.float64, default_origin=default_origin, shape=shape, mask=mask, backend="gtcuda" ) assert sum(store.mask) == store.ndim assert sum(store.mask) == len(store.data.shape)
def test_storage(self): self.run_test( gt_storage.empty( shape=(3, 3), mask=[True, False, True], dtype=np.float64, backend="debug", default_origin=(0, 0), ), "The storage for '.*' has mask '\(True, False, True\)', but the API signature expects '\(True, True, False\)'", )
def test_mismatch(self, sample_stencil): with pytest.raises( ValueError, match="Field '.*' expects data dimensions \(2,\) but got \(3,\)" ): sample_stencil(field_out=gt_storage.empty( shape=(3, 3, 1), mask=[True, True, True], dtype=(np.float64, (3, )), backend=self.backend, default_origin=(0, 0, 0), ))
def test_storage(self, sample_stencil): with pytest.raises( Exception, match= "Storage for '.*' has domain mask '.*' but the API signature expects '\[I, J\]'", ): sample_stencil(field_out=gt_storage.empty( shape=(3, 3), mask=[True, False, True], dtype=np.float64, backend="debug", default_origin=(0, 0), ))
def new(self, axes, dtype, pad_k=False): k_add = 0 if pad_k else -1 if axes == IJK: origin = (self.ng, self.ng, 0) shape = (self.full_domain_nx, self.full_domain_ny, self.km + k_add) mask = None elif axes == IJ: mask = (True, True, False) origin = (self.ng, self.ng) shape = (self.full_domain_nx, self.full_domain_ny) elif axes == K: mask = (False, False, True) origin = (0, ) shape = (self.km + k_add, ) else: raise ValueError("Axes unrecognized") return gt_storage.empty(backend=self._backend, default_origin=origin, shape=shape, dtype=dtype, mask=mask)
def make_storage_from_shape( shape: Tuple[int, int, int], origin: Tuple[int, int, int] = origin, *, dtype: DTypes = np.float64, init: bool = True, mask: Tuple[bool, bool, bool] = (True, True, True), ) -> Field: """Create a new gt4py storage of a given shape. Args: shape: Shape of the new storage origin: Default origin for gt4py stencil calls dtype: Data type init: If True, initializes the storage to the default value for the type mask: Tuple indicating the axes used when initializing the storage Returns: Field[dtype]: New storage Examples: 1) utmp = utils.make_storage_from_shape(ua.shape) 2) qx = utils.make_storage_from_shape( qin.shape, origin=(grid().is_, grid().jsd, kstart) ) 3) q_out = utils.make_storage_from_shape(q_in.shape, origin, init=True) """ storage = gt_storage.empty( backend=global_config.get_backend(), default_origin=origin, shape=shape, dtype=dtype, mask=mask, managed_memory=managed_memory, ) if init: storage[:] = dtype() return storage
def test_dim_red_slice_copy(backend): arr = gt_store.empty( backend, default_origin=[0, 0, 0], shape=[10, 10, 10], dtype=(np.float64, (3,)) ) with pytest.raises(RuntimeError, match="slicing storages is not supported"): s = arr[:, :, 0]
def empty(self, *args, **kwargs): """Create a storage with uninitialized fields.""" keywords = self._kwargs.copy() keywords.update(kwargs) return storage.empty(*args, **keywords)