On Mon, Apr 2, 2012 at 10:57 PM, J Diviney <justd...@gmail.com> wrote:Perhaps this would be more naturally written as a class with methods?
> I have a series of arrays each with at least 1000 elements and each of which
> needs to be accessed by about 10 different functions for different purposes.
> I've declared them as global to make the code simpler and to avoid passing
> them as arguments when it's much simpler to pass indices.
(Or maybe not, it all depends and I don't have enough information to
> In any case, I've tried these things, ndarray declarations with buffer typesCould you give a short, complete example of something that doesn't
> just aren't working for me, regardless of where I make them.
work for you? If there's a bug here, we'd like to know.
> On 3 April 2012 06:53, Robert Bradshaw <rober...@gmail.com> wrote:
>> On Mon, Apr 2, 2012 at 10:38 PM, J Diviney <justd...@gmail.com> wrote:
>> If you really need this, you can assign to a local variable within
>> > I realise that the ndarray declarations you've used are faster, but
>> > 'ndarray' is not a type identifier
>> Could you please send the smallest, complete example you can create
>> > On 2 April 2012 16:32, Aronne Merrelli <aronne.merre...@gmail.com>
>> >> On Sun, Apr 1, 2012 at 3:49 PM, J Diviney <justd...@gmail.com> wrote:
>> >> Correct - if you do:
>> >> from libc.math cimport sqrt
>> >> Then you are "done" - all later calls to sqrt(x) in your cdef function
>> >> In your example code you - do you really need to pull in the variable
>> >> start=nu.zeros(10000,dtype=nu.float)
>> >> With the following:
>> >> def run_test2(int n_loops, nu.ndarray[nu.float_t, ndim=1] start):
>> >> If you also typedef the arr variable same way - specifically, replace:
>> >> cdef nu.ndarray arr=nu.zeros(len(start),dtype=nu.float)
>> >> With this (I like to make this 2 steps, it is clearer to me):
>> >> cdef nu.ndarray[nu.float_t, ndim=1] arr
>> >> The cython version is then substantially faster - here is a timing
>> >> In : %timeit dummy.run_test(10)
>> >> In : %timeit dummy.run_test2(10,np.zeros(10000))
>> >> Hope that helps,
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.