Example #1
0
def compute_with_sca(type, xin, N, is_out=True, factor=None, coef=None, prefix=True,
                     optimize=False, change_coef=False):
    if optimize:
        xin = nlcpy.sca.convert_optimized_array(xin, xin.dtype)
    if is_out:
        xout = nlcpy.zeros_like(xin)
        if optimize:
            xout = nlcpy.sca.convert_optimized_array(xout, xout.dtype)
        dxin, dxout = nlcpy.sca.create_descriptor((xin, xout))
    else:
        dxin = nlcpy.sca.create_descriptor((xin))
        xout = None
    _coef = nlcpy.zeros_like(coef) if change_coef else coef
    if type == 'xya':
        if xin.ndim < 2:
            return True, True
        desc = create_description_xya(
            dxin, N, factor=factor, coef=_coef, prefix=prefix)
    elif type == 'xza':
        if xin.ndim < 3:
            return True, True
        desc = create_description_xza(
            dxin, N, factor=factor, coef=_coef, prefix=prefix)
    elif type == 'xwa':
        if xin.ndim < 4:
            return True, True
        desc = create_description_xwa(
            dxin, N, factor=factor, coef=_coef, prefix=prefix)
    elif type == 'yza':
        if xin.ndim < 3:
            return True, True
        desc = create_description_yza(
            dxin, N, factor=factor, coef=_coef, prefix=prefix)
    elif type == 'ywa':
        if xin.ndim < 4:
            return True, True
        desc = create_description_ywa(
            dxin, N, factor=factor, coef=_coef, prefix=prefix)
    elif type == 'zwa':
        if xin.ndim < 4:
            return True, True
        desc = create_description_zwa(
            dxin, N, factor=factor, coef=_coef, prefix=prefix)
    else:
        raise TypeError
    if is_out:
        kern = nlcpy.sca.create_kernel(desc, dxout[...])
    else:
        kern = nlcpy.sca.create_kernel(desc)
    if change_coef:
        _coef[...] = coef
    res = kern.execute()
    return res, xout
Example #2
0
def compute_with_naive(type, xin, N, factor=None, coef=None):
    xout = nlcpy.zeros_like(xin)
    if type == 'xyd':
        if xin.ndim < 2:
            return True
        naive_xyd(xin, xout, N, factor=factor, coef=coef)
    elif type == 'xzd':
        if xin.ndim < 3:
            return True
        naive_xzd(xin, xout, N, factor=factor, coef=coef)
    elif type == 'xwd':
        if xin.ndim < 4:
            return True
        naive_xwd(xin, xout, N, factor=factor, coef=coef)
    elif type == 'yzd':
        if xin.ndim < 3:
            return True
        naive_yzd(xin, xout, N, factor=factor, coef=coef)
    elif type == 'ywd':
        if xin.ndim < 4:
            return True
        naive_ywd(xin, xout, N, factor=factor, coef=coef)
    elif type == 'zwd':
        if xin.ndim < 4:
            return True
        naive_zwd(xin, xout, N, factor=factor, coef=coef)
    else:
        raise TypeError
    return xout
Example #3
0
def compute_with_naive(type, xin, N, factor=None, coef=None, div=False, sub=False):
    xout = nlcpy.zeros_like(xin)
    if type == 'xa':
        naive_xa(xin, xout, N, factor=factor, coef=coef, div=div, sub=sub)
    else:
        raise TypeError
    return xout
Example #4
0
def compute_with_sca(type, xin, N, is_out=True, factor=None, coef=None, prefix=True,
                     optimize=False, change_coef=False, div=False, sub=False):
    if optimize:
        xin = nlcpy.sca.convert_optimized_array(xin, xin.dtype)
    if is_out:
        xout = nlcpy.zeros_like(xin)
        if optimize:
            xout = nlcpy.sca.convert_optimized_array(xout, xout.dtype)
        dxin, dxout = nlcpy.sca.create_descriptor((xin, xout))
    else:
        dxin = nlcpy.sca.create_descriptor((xin))
        xout = None
    _coef = nlcpy.ones_like(coef) if change_coef else coef
    if type == 'xa':
        desc = create_description_xa(
            dxin, N, factor=factor, coef=_coef, prefix=prefix, div=div, sub=sub)
    else:
        raise TypeError
    if is_out:
        kern = nlcpy.sca.create_kernel(desc, dxout[...])
    else:
        kern = nlcpy.sca.create_kernel(desc)
    if change_coef:
        _coef[...] = coef
    res = kern.execute()
    return res, xout
Example #5
0
def test_me_case_1():
    a = ny.array([[10, 7, 4], [3, 2, 1]])

    na = ny.array(a)
    ans = ny.std(na, axis=0)
    out = ny.zeros_like(ans)
    dst = ny.std(na, axis=0, out=out)
    assert_array_almost_equal(dst.get(), out.get())
Example #6
0
def compute_with_naive(type, xin, N, factor=None, coef=None):
    xout = nlcpy.zeros_like(xin)
    if type == 'xyzw':
        if xin.ndim < 4:
            return True
        naive_xyzw(xin, xout, N, factor=factor, coef=coef)
    else:
        raise TypeError
    return xout
Example #7
0
def compute_with_naive(type, xin, N, factor=None, coef=None):
    xout = nlcpy.zeros_like(xin)
    if type == 'xa':
        naive_xa(xin, xout, N, factor=factor, coef=coef)
    elif type == 'ya':
        if xin.ndim < 2:
            return True
        naive_ya(xin, xout, N, factor=factor, coef=coef)
    elif type == 'za':
        if xin.ndim < 3:
            return True
        naive_za(xin, xout, N, factor=factor, coef=coef)
    elif type == 'wa':
        if xin.ndim < 4:
            return True
        naive_wa(xin, xout, N, factor=factor, coef=coef)
    else:
        raise TypeError
    return xout
Example #8
0
def ca4(arg):
    d = arg[0]
    t = arg[1]
    a = arg[2]

    ss = 1
    for x in d:
        ss *= x

    if t == 'int32' or t == 'int64' or t == 'uint32' or t == 'uint64':
        seed = [random.randint(1, ss * ss) for i in range(ss)]
    elif t == 'float64' or t == 'float32':
        seed = [random.random() for i in range(ss)]
    else:
        pass

    na = ny.array(seed)
    ans = ny.mean(na, axis=a)
    out = ny.zeros_like(ans)
    dst = ny.mean(na, axis=a, out=out)

    return dst, out
Example #9
0
 def test_zeros_like_reshape_nlcpy_only(self, dtype, order):
     a = testing.shaped_arange((2, 3, 4), nlcpy, dtype)
     b = nlcpy.zeros_like(a, shape=self.shape)
     c = nlcpy.zeros(self.shape, order=order, dtype=dtype)
     testing.assert_array_equal(b, c)
Example #10
0
 def test_zeros_like_subok(self):
     a = nlcpy.ndarray((2, 3, 4))
     return nlcpy.zeros_like(a, subok=True)