Fast operations on arrays of structured data.
Project description
StructArray allows you to perform fast arithmetic operations on arrays of structured (or unstructured) data.
This library is useful for performing the same operation on every item in an array.
I’ve included an example showing a simple particle engine. It animates 10,000 particles without much trouble.
This is the “release early” part of the “release early, release often” equation. It’s 80% done. I just need to finish the other 80%.
Quick Introduction
Here’s a quick introduction to what you can do with it:
>>> import structarray, random
First, create a StructArray with attributes for position and velocity, starting with a length of 1000.
>>> particles = structarray.StructArray(('x', 'y', 'dx', 'dy'), size=10000)
Let’s give the particles a little random motion. We can loop through each item and assign attributes.
>>> for p in particles: ... p.dx = random.random() * 20 - 10 ... p.dy = random.random() * 50
We can also assign values by index like this:
>>> particles[0].dy = 100
Or we could assign all four values to an index:
>>> particles[0] = (0, 20, 5, 100) # (x, y, dx, dy)
We can assign a value to every item by assigning it directly to an attribute of the array:
>>> particles.x = 0 # set x to zero for every item
We can also copy the values of one attribute into another:
>>> particles.y = particles.x
We can also do arithmetic while we are at it:
>>> particles.y = particles.x + 10
So now, how would we go about a simulation loop?
>>> particles.x += particles.dx >>> particles.y += particles.dy >>> particles.dy -= 9.81
What’s important here is that each of these three operations is applied to every item in the array. And it all happens in a tight loop in C, so it’s very fast. Even for 10,000 particles.
Sending the data off to the video card is pretty easy:
>>> glVertexPointer(2, GL_FLOAT, ... particles.get_data_stride(), ... particles.get_data_addr())
Of course there’s more to it than that to get it to display. Check out the source distribution for a working example
Download
I always upload the latest version to the StructArray page on PyPI.
Installation
Run this command to download and install a precompiled binary.:
sudo easy_install StructArray
To compile StructArray from source, you need the python development headers installed. (This is named python-dev in debian and ubuntu distributions. I think rpm distros name it python-devel.)
The C files are included, so you don’t need Pyrex installed. However, if you do have Pyrex, I’ve only tested it with Pyrex-0.9.6.3. Results may vary with older versions.
Installing is just like most any other python module:
python setup.py build sudo python setup.py install
Documentation
You can find the StructArray reference documentation here
It’s also included when you download the source distribution.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file StructArray-0.1.tar.gz
.
File metadata
- Download URL: StructArray-0.1.tar.gz
- Upload date:
- Size: 54.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b9b508bdfa64d41b4384ab3d699f054f15c33fc0c750d7bb2fbba8b632123e7d |
|
MD5 | c9b478692b9de7577b317dab7624c6d9 |
|
BLAKE2b-256 | 206f68aad1203fd5bae9af02b179c38bea8a053a9dbdb8a07e95b34d5678f753 |
Provenance
File details
Details for the file StructArray-0.1.win32-py2.5.exe
.
File metadata
- Download URL: StructArray-0.1.win32-py2.5.exe
- Upload date:
- Size: 100.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0eeb2923c6da64182c5094cb36c8be12a3cc17fed60f5f4830a0e24a6a797ec9 |
|
MD5 | ca62a41765f40a25661d87b216c3349a |
|
BLAKE2b-256 | 4d676f539c20c593bbc9f714467f8a960ec6d3cb8b74e4b729eca2c3b6bd540b |
Provenance
File details
Details for the file StructArray-0.1-py2.5-win32.egg
.
File metadata
- Download URL: StructArray-0.1-py2.5-win32.egg
- Upload date:
- Size: 35.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41811eab348b8c08607c6036f59de3c6b805a481218be233e2fc0e78f5905266 |
|
MD5 | 7a22fa01b6cb8ad8910ad700002affd0 |
|
BLAKE2b-256 | 68e7d1859136057fc9427078349174b6b0f965d92abc498484e7f9504aa6ea0e |
Provenance
File details
Details for the file StructArray-0.1-py2.5-linux-i686.egg
.
File metadata
- Download URL: StructArray-0.1-py2.5-linux-i686.egg
- Upload date:
- Size: 94.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f85fff5b99a174206eb565d92db61b11c74af67da2c91d1bd24789a990ba456 |
|
MD5 | 2d4b25ed2dc42d6f1d9ff5851872c5a5 |
|
BLAKE2b-256 | def4db23b20fd15a93b8c7d0a2882aa8ba77a75e79ed6db69e2e92c678bb1259 |
Provenance
File details
Details for the file StructArray-0.1-py2.4-linux-i686.egg
.
File metadata
- Download URL: StructArray-0.1-py2.4-linux-i686.egg
- Upload date:
- Size: 93.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 57489dfca4a230420bfd0dd5fc3174fd720832b8adc604b0d6010f517bd8d595 |
|
MD5 | eb3452cabe7b224cd7172613decda84f |
|
BLAKE2b-256 | fdb4fbbee75e89240654a1e9fcd046a6b62c8c79bad78ef294fa6c1b4a17abfc |