8

I would like to add (arithmetics) two large System.Arrays element-wise in IronPython and store the result in the first array like this:

    for i in range(0:ArrA.Count) :
      arrA.SetValue(i, arrA.GetValue(i) + arrB.GetValue(i));

However, this seems very slow. Having a C background I would like to use pointers or iterators. However, I do not know how I should apply the IronPython idiom in a fast way. I cannot use Python lists, as my objects are strictly from type System.Array. The type is 3d float.

What is the fastests / a fast way to perform to compute this computation?

Edit:

  • The number of elements is appr. 256^3.
  • 3d float means that the array can be accessed like this: array.GetValue(indexX, indexY, indexZ). I am not sure how the respective memory is organized in IronPython's System.Array.
  • Background: I wrote an interface to an IronPython API, which gives access to data in a simulation software tool. I retrieve 3d scalar data and accumulate it to a temporal array in my IronPython script. The accumulation is performed 10,000 times and should be fast, so that the simulation does not take ages.
c_k
  • 1,746
  • 1
  • 20
  • 35

1 Answers1

0

Is it possible to use the numpy library developed for IronPython?

https://pytools.codeplex.com/wikipage?title=NumPy%20and%20SciPy%20for%20.Net

It appears to be supported, and as far as I know is as close you can get in python to C style pointer functionality with arrays and such.

Create an array:

x = np.array([[1, 2, 3], [4, 5, 6]], np.int32)

Multiply all elements by 3.0:

x *= 3.0
beiller
  • 3,105
  • 1
  • 11
  • 19
  • Unfortunately, as I am interfacing an API I cannot go away from System.Array. Converting to numpy first would not make it faster, really? – c_k Feb 24 '15 at 08:41
  • Can you try the generic access methods IE `for i in range(0:ArrA.Count) : arrA[i] = arrA[i] + arrB[i]`? Also compare with full on converting to numpy, then back to the array. Who knows? :) – beiller Feb 24 '15 at 15:02
  • The generic access methods do not work on 3D arrays. As far as I know, for converting to numpy I have to do the same (time expensive loop) as shown in my question. – c_k Feb 24 '15 at 16:15
  • try `x = np.array(ArrA)` to initialize the array to numpy. Also I feel that the array you are using does not separate into tuples, so you have to use 3 gets. – beiller Feb 24 '15 at 16:19