Пример #1
0
 def f(i):
     ar = SingleDimArray(i)
     j = 0
     while j < i:
         ar.get_concrete().storage[j] = float(j)
         j += 1
     return ar.descr_add(space, ar).descr_min(space)
Пример #2
0
 def f(i):
     ar = SingleDimArray(i, dtype=NonConstant(float64_dtype))
     j = 0
     while j < i:
         ar.get_concrete().setitem(j, float64_dtype.box(1.0))
         j += 1
     return ar.descr_add(space, ar).descr_all(space).boolval
Пример #3
0
 def f(i):
     if NonConstant(False):
         dtype = int64_dtype
     else:
         dtype = float64_dtype
     ar = SingleDimArray(i, dtype=dtype)
     v = ar.descr_add(space, ar).descr_prod(space)
     assert isinstance(v, FloatObject)
     return v.floatval
Пример #4
0
 def test_binop_signature(self, space):
     ar = SingleDimArray(10)
     v1 = ar.descr_add(space, ar)
     v2 = ar.descr_add(space, FloatWrapper(2.0))
     assert v1.signature is not v2.signature
     v3 = ar.descr_add(space, FloatWrapper(1.0))
     assert v2.signature is v3.signature
     v4 = ar.descr_add(space, ar)
     assert v1.signature is v4.signature
Пример #5
0
    def test_slice_signature(self, space):
        ar = SingleDimArray(10)
        v1 = ar.descr_getitem(space, space.wrap(slice(1, 5, 1)))
        v2 = ar.descr_getitem(space, space.wrap(slice(4, 6, 1)))
        assert v1.signature is v2.signature

        v3 = ar.descr_add(space, v1)
        v4 = ar.descr_add(space, v2)
        assert v3.signature is v4.signature
Пример #6
0
 def f(i):
     if NonConstant(False):
         dtype = int64_dtype
     else:
         dtype = float64_dtype
     ar = SingleDimArray(i, dtype=dtype)
     j = 0
     while j < i:
         ar.get_concrete().setitem(j, float64_dtype.box(float(j)))
         j += 1
     v = ar.descr_add(space, ar).descr_max(space)
     assert isinstance(v, FloatObject)
     return v.floatval
Пример #7
0
 def f(n):
     if NonConstant(False):
         dtype = float64_dtype
     else:
         dtype = int32_dtype
     ar = SingleDimArray(n, dtype=dtype)
     i = 0
     while i < n:
         ar.get_concrete().setitem(i, int32_dtype.box(7))
         i += 1
     v = ar.descr_add(space, ar).descr_sum(space)
     assert isinstance(v, IntObject)
     return v.intval
Пример #8
0
 def f(i):
     step = NonConstant(3)
     ar = SingleDimArray(step*i, dtype=float64_dtype)
     ar2 = SingleDimArray(i, dtype=float64_dtype)
     ar2.get_concrete().setitem(1, float64_dtype.box(5.5))
     arg = ar2.descr_add(space, ar2)
     ar.setslice(space, 0, step*i, step, i, arg)
     return ar.get_concrete().eval(3).val
Пример #9
0
 def f(i):
     step = NonConstant(3)
     ar = SingleDimArray(step*i)
     ar2 = SingleDimArray(i)
     ar2.storage[1] = 5.5
     if NonConstant(False):
         arg = ar2
     else:
         arg = ar2.descr_add(space, ar2)
     ar.setslice(space, 0, step*i, step, i, arg)
     return ar.get_concrete().storage[3]
Пример #10
0
def fromstring(space, s):
    from pypy.module.micronumpy.interp_numarray import SingleDimArray
    length = len(s)

    if length % FLOAT_SIZE == 0:
        number = length/FLOAT_SIZE
    else:
        raise OperationError(space.w_ValueError, space.wrap(
            "string length %d not divisable by %d" % (length, FLOAT_SIZE)))

    a = SingleDimArray(number)

    start = 0
    end = FLOAT_SIZE
    i = 0
    while i < number:
        part = s[start:end]
        a.storage[i] = runpack('d', part)
        i += 1
        start += FLOAT_SIZE
        end += FLOAT_SIZE

    return space.wrap(a)
Пример #11
0
def create_array(size):
    a = SingleDimArray(size)
    for i in range(size):
        a.storage[i] = float(i % 10)
    return a
Пример #12
0
 def f(i):
     ar = SingleDimArray(i, dtype=NonConstant(float64_dtype))
     return ar.descr_add(space, ar).descr_any(space).boolval
Пример #13
0
 def f(i):
     ar = SingleDimArray(i)
     return ar.descr_add(space, ar).descr_prod(space)