Update of /cvsroot/pure-data/externals/grill/py/scripts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3088/scripts
Modified Files: buffer.py Log Message: more buffer functionality (support sequence and number protocols) more examples preset sys.argv for module loading support for buffer objects (preliminary)
Index: buffer.py =================================================================== RCS file: /cvsroot/pure-data/externals/grill/py/scripts/buffer.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** buffer.py 9 Mar 2005 04:58:10 -0000 1.1 --- buffer.py 10 Mar 2005 04:59:00 -0000 1.2 *************** *** 8,17 **** """This is an example script for the py/pyext object's buffer support.
! PD/Max buffers can be imported to and exported from numarray arrays. For numarray see http://numeric.scipy.org ! It will probably once be replaced by Numeric ! ! - _import(buffer): copy contents from the buffer to a new numarray object ! - _export(buffer,numarray): export contents of numarray object to the buffer """
--- 8,14 ---- """This is an example script for the py/pyext object's buffer support.
! PD/Max buffers can be mapped to numarray arrays. For numarray see http://numeric.scipy.org ! It will probably once be replaced by Numeric(3) """
*************** *** 21,25 **** import pyext except: ! print "ERROR: This script must be loaded by the PD/Max pyext external"
try: --- 18,22 ---- import pyext except: ! print "ERROR: This script must be loaded by the PD/Max py/pyext external"
try: *************** *** 29,46 ****
def mul(*args): c = pyext.Buffer(args[0]) ! dst = c.array() ! dst[:] = 0 ! a = pyext.Buffer(args[1]).array() ! b = pyext.Buffer(args[2]).array() ! dst += a*b ! c.dirty()
def add(*args): c = pyext.Buffer(args[0]) ! dst = c.array() ! dst[:] = 0 ! a = pyext.Buffer(args[1]).array() ! b = pyext.Buffer(args[2]).array() ! dst += a+b ! c.dirty() --- 26,60 ----
def mul(*args): + # create buffer objects + # as long as these variables live the underlying buffers are locked c = pyext.Buffer(args[0]) ! a = pyext.Buffer(args[1]) ! b = pyext.Buffer(args[2]) ! ! # slicing causes numarrays (mapped to buffers) to be created ! # note the c[:] - to assign contents you must assign to a slice of the buffer ! c[:] = a[:]*b[:]
def add(*args): c = pyext.Buffer(args[0]) ! a = pyext.Buffer(args[1]) ! b = pyext.Buffer(args[2]) ! ! # this is also possible, but is probably slower ! # the + converts a into a numarray, the argument b is taken as a sequence ! # depending on the implementation in numarray this may be as fast ! # as above or not ! c[:] = a+b ! ! def fadein(target): ! a = pyext.Buffer(target) ! # in place operations are ok ! a *= arange(len(a),type=Float32)/len(a) ! ! def neg(target): ! a = pyext.Buffer(target) ! # in place transformation (see numarray ufuncs) ! negative(a[:],a[:]) ! # must mark buffer content as dirty to update graph ! # (no explicit assignment occurred) ! a.dirty()