Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use copy_to in assign() and ref() where possible #190

Closed
JeffBezanson opened this issue Sep 3, 2011 · 5 comments
Closed

use copy_to in assign() and ref() where possible #190

JeffBezanson opened this issue Sep 3, 2011 · 5 comments
Labels
help wanted Indicates that a maintainer wants help on an issue or pull request performance Must go faster

Comments

@JeffBezanson
Copy link
Member

assign is a kernel for cat and some other functions.

@ViralBShah
Copy link
Member

The only place where memcpy can be used is in ref() and assign() when the input is a Range1. Otherwise, we need a strided memcpy. BLAS has such a thing, but in the case of openblas, it turns out to be significantly slower than memcpy on large regions.

See OpenMathLib/OpenBLAS#45

@ViralBShah
Copy link
Member

I think that something like this should cover most cases for ref, and the same can be done for assign.

function ref{T}(A::Array{T}, I::Range1)
X = Array(T, length(I))
copy_to (pointer(X), pointer(A, I.start), length(I))
return X
end

@JeffBezanson
Copy link
Member Author

We should avoid using pointer. Copying functions should just take arrays, offsets, strides, etc. and then handle it using pointers and memcpy internally where possible.

@ViralBShah
Copy link
Member

Yes, I was trying to avoid it. Do we have such copy functions defined? I was in fact thinking of doing exactly the same.

@timholy
Copy link
Member

timholy commented Jul 1, 2012

I just pushed a semi-working draft of this to the arrays branch. It only works for ref (not assign), and it's not complete. In some cases it seems to give an improvement in the range of 2-fold or so. Not as big a deal as the linear indexing from a couple days ago, and it's more code, but perhaps still worth doing.

Testing this: start from master and run test/arrayperf.jl. Then switch to arrays, make, and do the same thing. Only the "whole array" and "contiguous blocks" of "ref" are relevant.

@JeffBezanson, one hitch will be turning on the passing of Colon() objects---you can see that for now I bypassed that issue by making changes to arrayperf. Colons in successive dimensions are combined until the first non-colon index, allowing a single memcpy call to handle multiple dimensions when possible. For dimensions after the first non-colon index, any remaining colons need to be replaced by Range1{Int}s, which in this branch is currently done at runtime by the function replace_colons (in array.jl). It would be nice to get rid of replace_colons: in some cases, e.g., the non-contiguous cases, this function can make the performance worse than what's currently in master.

So: rather than changing the compiler so that all colons pass though, can we keep the compiler's current behavior for those colons that need to be replaced? I.e., the ones after the first non-colon index?

HarlanH pushed a commit to HarlanH/julia that referenced this issue Jul 18, 2012
StefanKarpinski pushed a commit that referenced this issue Feb 8, 2018
cmcaine pushed a commit to cmcaine/julia that referenced this issue Sep 24, 2020
LilithHafner pushed a commit to LilithHafner/julia that referenced this issue Oct 11, 2021
* Add in Rényi entropies.

* Add in comments on which entropies are used

* Add in dependency for Distributions, and qualification for span() as it is in Distributions and StatsBase.

* Add in Renyi entropy tests.

* Removed dependences on Distributions.jl.

* Adding in testing for generalised probability distributions (sum(p) != 1).

* No longer variable length.

* Unnecessary qualification now tests don't use Distributions.jl.

* Correct to american spelling.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Indicates that a maintainer wants help on an issue or pull request performance Must go faster
Projects
None yet
Development

No branches or pull requests

3 participants