def test_apply_pcbabs(self): sz = 25 i = [0, 2, 4, 6, 8, 10] v = [0, -4, 8, -12,16, 20] vec = self.initializeSpParVec(sz, i, v) vec.apply(pcb.abs()) vecExpected = [0, 0, 4, 0, 8, 0, 12, 0, 16, 0, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] self.assertEqual(sz, len(vec)) for ind in range(sz): self.assertEqual(vecExpected[ind], vec[ind])
import kdt.pyCombBLAS as pcb import time print "Using built-in, C++ backed op" d = pcb.pyDenseParVec.range(10, -5) print "before Apply:" d.printall() time1 = time.time() print pcb.abs() for i in xrange(1000000): d.Apply(pcb.my_op()) time2 = time.time() print "Builtin Time: ", (time2-time1) print "after Apply:" d.printall() ######################################## print "\n\nUsing Python op" d = pcb.pyDenseParVec.range(10, -5) print "before Apply:" d.printall() def pyabs(x): if (x < 0): return -x return x
import kdt.pyCombBLAS as pcb import time print "Using built-in, C++ backed op" d = pcb.pyDenseParVec.range(100, -50) print "before Apply:" #d.printall() print pcb.abs() time1 = time.time() for i in xrange(1000000): d.Apply(pcb.abs()) time2 = time.time() print "Builtin Time: ", (time2-time1) print "after Apply:" #d.printall() ######################################## # print "\n\nUsing Python op" # d = pcb.pyDenseParVec.range(10, -5) # print "before Apply:" # d.printall() # def pyabs(x): # if (x < 0): # return -x # return x