# Fast Transfer of Points in/out Python Scripts?

Hi everyone!
I am currently working on a boids simulation in python. I started with the example from here:
derivative.ca/Forum/viewtopi … =22&t=3794

I am now trying to scale this up to a large number of boids.

I found a very nice numpy example that can handle 100,000 boids in realtime:
github.com/vispy/vispy/blob/mas … o/boids.py

While profiling my attempts to combine these two examples, I realized that the main performance problem is: transfering points from touchdesigner into the python script and back.

For example, for 1000 boids, my stats are:

• total time: 68 msec
• transfer TD => Python: 8 msec
• applying boid rules: 25 msec
• transfer Python => TD: 30 msec
So, about 1/2 of my computation time is spent on transfers.
When I vary the number of boids, this ratio stays roughly the same.

Inside my python script, the code looks something like:

1. TD=>Python

[code]myPoints = scriptOP.points
if not myPoints:
scriptOP.copy(scriptOP.inputs[0])
myPoints = scriptOP.points

n = len(myPoints)
P = np.empty([n,2])

count = 0
for i in myPoints:
P[count]=[i.x,i.y,]
count += 1
[/code]
2) Python=>TD

```count = 0 for i in myPoints: [i.x,i.y,]=P[count] count += 1 ```

I have considered other approaches, for example using a TOP instead of Points as Interface to python. Ideally, I would want to do something like:

1. TD=>Python
P = TOP.getPixels()
2. Python=>TD
TOP.setPixels(P)

But, from what I read so far, it looks to me that python scripts can’t really modify the content of TOPs.

I am a TD newbie and like it very much so far! This is my first major hurdle… Any advice would be super appreciated!

Thanks!

You may consider working in CHOP Channel samples and converting those back into points.
docs.derivative.ca/index.php?title=Limit_CHOP

The Script CHOP allows you to transfer an array of values to or from a CHOP channel in one statement, through the Channel.vals member

docs.derivative.ca/index.php?ti … nnel_Class

Hope this helps,
Cheers,
Rob.

hi rob!