Ejemplo n.º 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)"))
Ejemplo n.º 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")
Ejemplo n.º 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")
Ejemplo n.º 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")
Ejemplo n.º 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)
Ejemplo n.º 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")
Ejemplo n.º 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")
Ejemplo n.º 8
0
Archivo: ctable.py Proyecto: 87/carray
    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)
Ejemplo n.º 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")
Ejemplo n.º 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")
Ejemplo n.º 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")
Ejemplo n.º 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")
Ejemplo n.º 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))
Ejemplo n.º 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")
Ejemplo n.º 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")
Ejemplo n.º 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")
Ejemplo n.º 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")
Ejemplo n.º 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")
Ejemplo n.º 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")
Ejemplo n.º 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")
Ejemplo n.º 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")
Ejemplo n.º 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")
Ejemplo n.º 23
0
Archivo: eval.py Proyecto: 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))
Ejemplo n.º 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,
    ))
Ejemplo n.º 25
0
Archivo: eval.py Proyecto: 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))
Ejemplo n.º 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()
Ejemplo n.º 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")
Ejemplo n.º 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")