Пример #1
0
 def test02(self):
     """Testing evaluation of ndcarrays (reduction, no axis)"""
     a = np.arange(np.prod(self.shape)).reshape(self.shape)
     b = ca.arange(np.prod(self.shape)).reshape(self.shape)
     if ca.defaults.eval_vm == "python":
         assert_array_equal(sum(a), ca.eval("sum(b)"),
                            "Arrays are not equal")
     else:
         self.assertEqual(a.sum(), ca.eval("sum(b)"))
Пример #2
0
 def test02b(self):
     """Testing evaluation of ndcarrays (reduction, with axis)"""
     a = np.arange(np.prod(self.shape)).reshape(self.shape)
     b = ca.arange(np.prod(self.shape)).reshape(self.shape)
     if ca.defaults.eval_vm == "python":
         # The Python VM does not have support for `axis` param
         assert_array_equal(sum(a), ca.eval("sum(b)"),
                            "Arrays are not equal")
     else:
         assert_array_equal(a.sum(axis=1), ca.eval("sum(b, axis=1)"),
                            "Arrays are not equal")
Пример #3
0
 def test11(self):
     """Testing eval() with functions like `np.sin()`"""
     a, b = np.arange(self.N), np.arange(1, self.N + 1)
     c, d = ca.carray(a), ca.carray(b)
     if self.vm == "python":
         cr = ca.eval("np.sin(c) + 2 * np.log(d) - 3")
     else:
         cr = ca.eval("sin(c) + 2 * log(d) - 3")
     nr = np.sin(a) + 2 * np.log(b) - 3
     #print "ca.eval ->", cr
     #print "numpy   ->", nr
     assert_array_equal(cr[:], nr, "eval does not work correctly")
Пример #4
0
 def test11(self):
     """Testing eval() with functions like `np.sin()`"""
     a, b = np.arange(self.N), np.arange(1, self.N+1)
     c, d = ca.carray(a), ca.carray(b)
     if self.vm == "python":
         cr = ca.eval("np.sin(c) + 2 * np.log(d) - 3")
     else:
         cr = ca.eval("sin(c) + 2 * log(d) - 3")
     nr = np.sin(a) + 2 * np.log(b) - 3
     #print "ca.eval ->", cr
     #print "numpy   ->", nr
     assert_array_equal(cr[:], nr, "eval does not work correctly")
Пример #5
0
    def eval(self, expression, **kwargs):
        """
        eval(expression, **kwargs)

        Evaluate the `expression` on columns and return the result.

        Parameters
        ----------
        expression : string
            A string forming an expression, like '2*a+3*b'. The values
            for 'a' and 'b' are variable names to be taken from the
            calling function's frame.  These variables may be column
            names in this table, scalars, carrays or NumPy arrays.
        kwargs : list of parameters or dictionary
            Any parameter supported by the `eval()` first level function.

        Returns
        -------
        out : carray object
            The outcome of the expression.  You can tailor the
            properties of this carray by passing additional arguments
            supported by carray constructor in `kwargs`.

        See Also
        --------
        eval (first level function)

        """

        # Get the desired frame depth
        depth = kwargs.pop("depth", 3)
        # Call top-level eval with cols as user_dict
        return ca.eval(expression, user_dict=self.cols, depth=depth, **kwargs)
Пример #6
0
 def test01(self):
     """Testing evaluation of ndcarrays (int out)"""
     a = np.arange(np.prod(self.shape)).reshape(self.shape)
     b = ca.arange(np.prod(self.shape)).reshape(self.shape)
     outa = eval("a*2.+1")
     outb = ca.eval("b*2.+1")
     assert_array_equal(outa, outb, "Arrays are not equal")
Пример #7
0
 def test00b(self):
     """Testing evaluation of ndcarrays (bool out, NumPy)"""
     a = np.arange(np.prod(self.shape)).reshape(self.shape)
     b = ca.arange(np.prod(self.shape)).reshape(self.shape)
     outa = eval("a>0")
     outb = ca.eval("b>0", out_flavor='numpy')
     assert_array_equal(outa, outb, "Arrays are not equal")
Пример #8
0
    def eval(self, expression, **kwargs):
        """
        eval(expression, **kwargs)

        Evaluate the `expression` on columns and return the result.

        Parameters
        ----------
        expression : string
            A string forming an expression, like '2*a+3*b'. The values
            for 'a' and 'b' are variable names to be taken from the
            calling function's frame.  These variables may be column
            names in this table, scalars, carrays or NumPy arrays.
        kwargs : list of parameters or dictionary
            Any parameter supported by the `eval()` first level function.

        Returns
        -------
        out : carray object
            The outcome of the expression.  You can tailor the
            properties of this carray by passing additional arguments
            supported by carray constructor in `kwargs`.

        See Also
        --------
        eval (first level function)

        """

        # Get the desired frame depth
        depth = kwargs.pop('depth', 3)
        # Call top-level eval with cols as user_dict
        return ca.eval(expression, user_dict=self.cols, depth=depth, **kwargs)
Пример #9
0
 def test01(self):
     """Testing evaluation of ndcarrays (int out)"""
     a = np.arange(np.prod(self.shape)).reshape(self.shape)
     b = ca.arange(np.prod(self.shape)).reshape(self.shape)
     outa = eval("a*2.+1")
     outb = ca.eval("b*2.+1")
     assert_array_equal(outa, outb, "Arrays are not equal")
Пример #10
0
 def test02(self):
     """Testing eval() with only ndarrays"""
     a, b = np.arange(self.N), np.arange(1, self.N+1)
     cr = ca.eval("a * b")
     nr = a * b
     #print "ca.eval ->", cr
     #print "numpy   ->", nr
     assert_array_equal(cr[:], nr, "eval does not work correctly")
Пример #11
0
 def test02(self):
     """Testing eval() with only ndarrays"""
     a, b = np.arange(self.N), np.arange(1, self.N + 1)
     cr = ca.eval("a * b")
     nr = a * b
     #print "ca.eval ->", cr
     #print "numpy   ->", nr
     assert_array_equal(cr[:], nr, "eval does not work correctly")
Пример #12
0
 def test06(self):
     """Testing eval() with only scalars and arrays"""
     a, b = np.arange(self.N), np.arange(1, self.N + 1)
     c, d = ca.carray(a), b
     cr = ca.eval("d - 3")
     nr = b - 3
     #print "ca.eval ->", cr
     #print "numpy   ->", nr
     assert_array_equal(cr[:], nr, "eval does not work correctly")
Пример #13
0
def compute_carray(sexpr, clevel, kernel):
    # Uncomment the next for disabling threading
    # ca.set_nthreads(1)
    # ca.blosc_set_nthreads(1)
    print ("*** carray (using compression clevel = %d):" % clevel)
    x = cx  # comment this for using numpy arrays in inputs
    t0 = time()
    cout = ca.eval(sexpr, kernel=kernel, cparams=ca.cparams(clevel))
    print ("Time for ca.eval (%s) --> %.3f" % (kernel, time() - t0))
Пример #14
0
 def test05(self):
     """Testing eval() with a mix of carray, ndarray and scalars"""
     a, b = np.arange(self.N), np.arange(1, self.N+1)
     c, d = ca.carray(a), b
     cr = ca.eval("a + 2 * d - 3")
     nr = a + 2 * b - 3
     #print "ca.eval ->", cr
     #print "numpy   ->", nr
     assert_array_equal(cr[:], nr, "eval does not work correctly")
Пример #15
0
 def test05(self):
     """Testing eval() with a mix of carray, ndarray and scalars"""
     a, b = np.arange(self.N), np.arange(1, self.N + 1)
     c, d = ca.carray(a), b
     cr = ca.eval("a + 2 * d - 3")
     nr = a + 2 * b - 3
     #print "ca.eval ->", cr
     #print "numpy   ->", nr
     assert_array_equal(cr[:], nr, "eval does not work correctly")
Пример #16
0
 def test03(self):
     """Testing eval() with a mix of carrays and ndarrays"""
     a, b = np.arange(self.N), np.arange(1, self.N + 1)
     c, d = ca.carray(a), ca.carray(b)
     cr = ca.eval("a * d")
     nr = a * b
     #print "ca.eval ->", cr
     #print "numpy   ->", nr
     assert_array_equal(cr[:], nr, "eval does not work correctly")
Пример #17
0
 def test06(self):
     """Testing eval() with only scalars and arrays"""
     a, b = np.arange(self.N), np.arange(1, self.N+1)
     c, d = ca.carray(a), b
     cr = ca.eval("d - 3")
     nr = b - 3
     #print "ca.eval ->", cr
     #print "numpy   ->", nr
     assert_array_equal(cr[:], nr, "eval does not work correctly")
Пример #18
0
 def test03(self):
     """Testing eval() with a mix of carrays and ndarrays"""
     a, b = np.arange(self.N), np.arange(1, self.N+1)
     c, d = ca.carray(a), ca.carray(b)
     cr = ca.eval("a * d")
     nr = a * b
     #print "ca.eval ->", cr
     #print "numpy   ->", nr
     assert_array_equal(cr[:], nr, "eval does not work correctly")
Пример #19
0
 def test12(self):
     """Testing eval() with `out_flavor` == 'numpy'"""
     a, b = np.arange(self.N), np.arange(1, self.N+1)
     c, d = ca.carray(a), ca.carray(b)
     cr = ca.eval("c + 2 * d - 3", out_flavor='numpy')
     nr = a + 2 * b - 3
     #print "ca.eval ->", cr, type(cr)
     #print "numpy   ->", nr
     self.assert_(type(cr) == np.ndarray)
     assert_array_equal(cr, nr, "eval does not work correctly")
Пример #20
0
 def test00b(self):
     """Testing eval() with only constants"""
     f0, f1, f2 = 1, 2, 3
     # Populate the name space with functions from math
     from math import sin
     ctr = ca.eval("f0 * f1 * sin(f2)")
     rar = f0 * f1 * sin(f2)
     #print "ctable ->", ctr
     #print "python ->", rar
     self.assert_(ctr == rar, "values are not correct")
Пример #21
0
 def test12(self):
     """Testing eval() with `out_flavor` == 'numpy'"""
     a, b = np.arange(self.N), np.arange(1, self.N + 1)
     c, d = ca.carray(a), ca.carray(b)
     cr = ca.eval("c + 2 * d - 3", out_flavor='numpy')
     nr = a + 2 * b - 3
     #print "ca.eval ->", cr, type(cr)
     #print "numpy   ->", nr
     self.assert_(type(cr) == np.ndarray)
     assert_array_equal(cr, nr, "eval does not work correctly")
Пример #22
0
 def test00b(self):
     """Testing eval() with only constants"""
     f0, f1, f2 = 1, 2, 3
     # Populate the name space with functions from math
     from math import sin
     ctr = ca.eval("f0 * f1 * sin(f2)")
     rar = f0 * f1 * sin(f2)
     #print "ctable ->", ctr
     #print "python ->", rar
     self.assert_(ctr == rar, "values are not correct")
Пример #23
0
Файл: eval.py Проект: 87/carray
def compute_carray(sexpr, clevel, kernel):
    # Uncomment the next for disabling threading
    # Maybe due to some contention between Numexpr and Blosc?
    # ca.set_nthreads(ca.ncores//2)
    print "*** carray (using compression clevel = %d):" % clevel
    if clevel > 0:
        x, y, z = cx, cy, cz
    t0 = time()
    cout = ca.eval(sexpr, kernel=kernel, cparams=ca.cparams(clevel))
    print "Time for ca.eval (%s) --> %.3f" % (kernel, time()-t0,),
    print ", cratio (out): %.1f" % (cout.nbytes / float(cout.cbytes))
Пример #24
0
def compute_carray(sexpr, clevel, kernel):
    # Uncomment the next for disabling threading
    #ca.set_nthreads(1)
    #ca.blosc_set_nthreads(1)
    print("*** carray (using compression clevel = %d):" % clevel)
    x = cx  # comment this for using numpy arrays in inputs
    t0 = time()
    cout = ca.eval(sexpr, kernel=kernel, cparams=ca.cparams(clevel))
    print("Time for ca.eval (%s) --> %.3f" % (
        kernel,
        time() - t0,
    ))
Пример #25
0
Файл: eval.py Проект: 87/carray
def compute_carray(sexpr, clevel, kernel):
    # Uncomment the next for disabling threading
    # Maybe due to some contention between Numexpr and Blosc?
    # ca.set_nthreads(ca.ncores//2)
    print "*** carray (using compression clevel = %d):" % clevel
    if clevel > 0:
        x, y, z = cx, cy, cz
    t0 = time()
    cout = ca.eval(sexpr, kernel=kernel, cparams=ca.cparams(clevel))
    print "Time for ca.eval (%s) --> %.3f" % (
        kernel,
        time() - t0,
    ),
    print ", cratio (out): %.1f" % (cout.nbytes / float(cout.cbytes))
Пример #26
0
t0 = time()
c = ca.carray(rootdir='myarray')
print "time open (disk) ->", round(time()-t0, 3)
#print "meta (disk):", c.read_meta()
print "data (disk):", repr(c)

t0 = time()
print sum(ac)
print "time sum (memory, iter) ->", round(time()-t0, 3)

t0 = time()
print sum(c)
print "time sum (disk, iter) ->", round(time()-t0, 3)

t0 = time()
print ca.eval('sum(ac)')
print "time sum (memory, eval) ->", round(time()-t0, 3)

t0 = time()
print ca.eval('sum(c)')
print "time sum (disk, eval) ->", round(time()-t0, 3)

t0 = time()
print ac.sum()
print "time sum (memory, method) ->", round(time()-t0, 3)

t0 = time()
print c.sum()
print "time sum (disk, method) ->", round(time()-t0, 3)

t0 = time()
Пример #27
0
 def test00(self):
     """Testing eval() with only scalars and constants"""
     a = 3
     cr = ca.eval("2 * a")
     #print "ca.eval ->", cr
     self.assert_(cr == 6, "eval does not work correctly")
Пример #28
0
 def test00(self):
     """Testing eval() with only scalars and constants"""
     a = 3
     cr = ca.eval("2 * a")
     #print "ca.eval ->", cr
     self.assert_(cr == 6, "eval does not work correctly")