vop: a fast vector module for Python

installation: either run:

    easy_install vop
or download here: vop-1.2.1.tar.gz

vop is a Python module that supports a simple set of operators on one-dimensional vectors of floating-point numbers. It is styled after Numeric, but offers nowhere near Numeric's capabilities. vop has a significant edge in speed: on some tasks it is 7X faster than Numeric.

$ ./try.py 
300000000 operations took 0.387395s, 774.403576 megaflops
$ ./try_numeric.py 
300000000 operations took 3.237142s, 92.674345 megaflops

vop requires a CPU with SSE2.

Here are some examples of what vop can do:

>>> import vop
>>> a = vop.arange(10)
>>> print a.tolist()
[0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]
>>> print (a + 100).tolist()
[100.0, 101.0, 102.0, 103.0, 104.0, 105.0, 106.0, 107.0, 108.0, 109.0]
>>> print (a * a).tolist()
[0.0, 1.0, 4.0, 9.0, 16.0, 25.0, 36.0, 49.0, 64.0, 81.0]
>>> print vop.sqrt(a).tolist()
[0.0, 1.0, 1.4142135381698608, 1.7320507764816284, 2.0, 2.2360680103302002, 2.4494898319244385, 2.6457512378692627, 2.8284270763397217, 3.0]

Note that operators on a vop (the usual arithmetic operators and sqrt, floot, sin and cos) accept either vops or scalars as arguments. For example, in the above code (a + 100) means that the additon operator adds the scalar value 100 to every element of the vector a. This is the same behavior as Numeric, and means that you can use the same code for scalar arithmetic as handling vops. For example, this function:

def pythagoras(a, b):
    return sqrt((a * a) + (b * b))

works just fine with 'a' and 'b' as both scalars, both vops, or a mixture.


Return a vop created from input x. x may be a list of scalars, or a string. If it is a string, then it is treated as a list of numbers between 0 and 255.


Return a vop created from input x. x is a string, and is treated as the native binary values of floating-point numbers. Hence len(x) must be a multiple of 4.


Return a vop consiting of the numbers 0.0 through (x - 1).


Returns true if any elements in x are non-zero.


Returns true if all elements in x are non-zero.

minimum(a, b)

Returns the lower of each element of a and b.

maximum(a, b)

Returns the higher of each element of a and b.


Returns a count of the total number of operations performed by the module.

take(a, b)

Evaluates a[b]. Similar to Numeric's 'take' operator, but allows either argument to be a scalar.

where(p, a, b)

Evaluates p ? a : b. Similar to Numeric's 'where' operator, but allows any argument to be a scalar.

compress(m, v)

Returns a new vector that contains only v[i] for which m[i] is true. The length of the returned vector is equal to the number of true elements in m.

expand(m, v, def)

Returns a new vector with the same length as m with every true element in m replaced with the next value in vector v, and every false value replaced with scalar def.

replicate(m, c)

Returns a new vector with length (len(m) * c) with every original element in m repeated c times.

duplicate(m, c)

Returns a new vector with length (len(m) * c) with vector m repeated c times.