On Tue, Dec 1, 2015 at 1:10 AM, Antonio Suriano
<
antonio...@gmail.com> wrote:
> 1 dimension contiguous arrays of different sizes.
> I wrote the function with np,ndarray[np.float64_t] because double[:] was a
> little bit slower.
>
> The point is this:
>
> why does LLVMLite JIT (numba) succeed in matching np.copyto and memcpy and
> not cython.
>
> Anyhow if you write a memcpy wrapper in cython or use the a[:]=b (that
> probably makes the same) you don't reach numba and np.copy.
Cython's buffer/memoryview optimization only applies to direct
indexing, and as mentioned a naive C loop (which this compiles down
to) is not going to beat memcpy or an optimized BLAS, so you're asking
"Why isn't Cython faster than C?"
> So is this intrinsic in cython functions ? (call overhead).
There is non-trivial "call" overhead in acquiring the buffer. How big
are your arrays? Do the timings scale proportionally with the size of
the array? As you notices a significant difference between the old
buffer syntax and memory views, I'd guess your arrays are small enough
that this dominates.
Also, Cython doesn't know your arrays are contiguous; declaring them
as np,ndarray [np.float64_t, mode='c'] could help.
> Il giorno martedì 1 dicembre 2015 09:27:55 UTC+1, Sturla Molden ha scritto:
>>
>> On 30/11/15 20:18, Antonio Suriano wrote:
>>
>> > What is wrong in my code?
>>
>> You are probably trying to beat the speed of a memcpy, which is
>> implemented in the operating system. That is silly business. Do you have
>> any idea how many work hours have been put into optimizing that
>> particular piece of code?
>>
>> Also, you did not specify the number of dimensions and whether the array
>> is contiguous.
>>
>> Another thing is you should use typed memoryviews instead of the old
>> numpy syntax (though it will not make your code faster).
>>
>> As for dot product, you are competing against the BLAS subroutines
>> *GEMM, *GEMV, and *DOT. Chances are you are competing against
>> performance code written by engineers at Intel, Apple or AMD, depending
>> on which BLAS implementation you use (that is, MKL, Accelerate
>> Framework, or ACML, repectively). And if you are not, you are likely
>> trying to beat the performance of the most optimized kernels in ATLAS or
>> OpenBLAS. You will not succeed, so spend your time om something less
>> futile instead.
>>
>>
>> Sturla
>>
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "cython-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to
cython-users...@googlegroups.com.
> For more options, visit
https://groups.google.com/d/optout.