def _new_operator1(shape, **kwargs): infield = DenseData(name='infield', shape=shape, dtype=np.int32) infield.data[:] = np.arange(reduce(mul, shape), dtype=np.int32).reshape(shape) outfield = DenseData(name='outfield', shape=shape, dtype=np.int32) stencil = Eq(outfield.indexify(), outfield.indexify() + infield.indexify()*3.0) # Run the operator op = Operator(stencil, **kwargs) op(infield=infield, outfield=outfield) return outfield, op
def symbol(name, dimensions, value=0., mode='function'): """Short-cut for symbol creation to test "function" and "indexed" API.""" assert(mode in ['function', 'indexed']) s = DenseData(name=name, dimensions=dimensions) s.data[:] = value return s.indexify() if mode == 'indexed' else s
def test_arithmetic_deep(expr, result): """Tests basic point-wise arithmetic on multi-dimensional data""" i = Dimension(name='i', size=3) j = Dimension(name='j', size=4) k = Dimension(name='k', size=5) l = Dimension(name='l', size=6) a = DenseData(name='a', dimensions=(i, j, k, l)) a.data[:] = 2. ai = a.indexify() b = DenseData(name='b', dimensions=(j, k)) b.data[:] = 3. bi = b.indexify() eqn = eval(expr) StencilKernel(eqn)(ai.base.function, bi.base.function) assert np.allclose(ai.base.function.data, result, rtol=1e-12)
def bi(x, y, name='b', value=3.): b = DenseData(name=name, dimensions=(x, y)) b.data[:] = value return b.indexify()
def ai(x, y, name='a', value=2.): a = DenseData(name=name, dimensions=(x, y)) a.data[:] = value return a.indexify()