Hi,
>> and - does this in fact optimize the array creation time (as opposed
>> to subsequent array indexing)? I'm creating thousands of arrays of
>> various dtypes known only at run time,
>>
> No, but I doubt using the C API will be much faster.
>
> There are things you can do to speed this up, for example storing
> arguments and np.ndarray in local variables:
>
> cdef object _kwargs = {'shape': (n,), dtype=dt, buffer=data}
> cdef object _ndarray = np.ndarray
>
> arr = _ndarray(**_kwargs)
That does seem to make a small difference, but the C-API is still
about 4 times faster, in my hands (see
http://github.com/matthew-brett/arraymakers):
In [1]: run arraymakers/test_arraymaker2.py
In [4]: import sturlabench
In [5]: n = 50
In [6]: dt = np.dtype('f4')
In [7]: data = np.arange(n, dtype=dt).tostring()
In [8]: timeit a = py_make_1d_array(n, data, dt)
100000 loops, best of 3: 3.52 µs per loop
In [9]: timeit a = arraymaker2.make_1d_array(n, data, dt)
1000000 loops, best of 3: 875 ns per loop
In [10]: timeit a = sturlabench.make_local_1d_array(n, data, dt)
100000 loops, best of 3: 3.39 µs per loop>
Best,
Matthew
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev