From 809cc821e6c318a0401d8190837c6411aee136bb Mon Sep 17 00:00:00 2001 From: Matt Bauman Date: Fri, 17 Apr 2015 09:39:27 -0400 Subject: [PATCH 1/2] Document and improve consistency of linearindexing Always have array subtypes define `linearindexing` in the type-domain, so they do not need to have two definitions. --- base/abstractarray.jl | 10 ++++------ base/multidimensional.jl | 1 - doc/stdlib/arrays.rst | 8 ++++++++ 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/base/abstractarray.jl b/base/abstractarray.jl index 36a07bdd98b74..6d6a1a44639f7 100644 --- a/base/abstractarray.jl +++ b/base/abstractarray.jl @@ -106,12 +106,10 @@ abstract LinearIndexing immutable LinearFast <: LinearIndexing end immutable LinearSlow <: LinearIndexing end -linearindexing(::AbstractArray) = LinearSlow() -linearindexing(::Array) = LinearFast() -linearindexing(::Range) = LinearFast() -linearindexing{A<:AbstractArray}(::Type{A}) = LinearSlow() -linearindexing{A<:Array}(::Type{A}) = LinearFast() -linearindexing{A<:Range}(::Type{A}) = LinearFast() +linearindexing(A::AbstractArray) = linearindexing(typeof(A)) +linearindexing{T<:AbstractArray}(::Type{T}) = LinearSlow() +linearindexing{T<:Array}(::Type{T}) = LinearFast() +linearindexing{T<:Range}(::Type{T}) = LinearFast() ## Bounds checking ## checkbounds(sz::Int, ::Colon) = nothing diff --git a/base/multidimensional.jl b/base/multidimensional.jl index 268ddb782f1d2..b29ad27cb1e3a 100644 --- a/base/multidimensional.jl +++ b/base/multidimensional.jl @@ -8,7 +8,6 @@ import Base: @nref, @ncall, @nif, @nexprs, LinearFast, LinearSlow, to_index export CartesianIndex, CartesianRange # Traits for linear indexing -linearindexing(::BitArray) = LinearFast() linearindexing{A<:BitArray}(::Type{A}) = LinearFast() # CartesianIndex diff --git a/doc/stdlib/arrays.rst b/doc/stdlib/arrays.rst index 09a7f5efe5990..685455655e2ea 100644 --- a/doc/stdlib/arrays.rst +++ b/doc/stdlib/arrays.rst @@ -59,6 +59,14 @@ Basic functions (iter.I_1,iter.I_2) = (2,3) A[iter] = 0.8090413606455655 +.. function:: Base.linearindexing(A) + + ``linearindexing`` defines how an AbstractArray most efficiently accesses its elements. If ``Base.linearindexing(A)`` returns ``Base.LinearFast()``, this means that linear indexing with only one index is an efficient operation. If it instead returns ``Base.LinearSlow()`` (by default), this means that the array intrinsically accesses its elements with indices specified for every dimension. Since converting a linear index to multiple indexing subscripts is typically very expensive, this provides a traits-based mechanism to enable efficient generic code for all array types. + + An abstract array subtype ``MyArray`` that wishes to opt into fast linear indexing behaviors should define ``linearindexing`` in the type-domain:: + + Base.linearindexing{T<:MyArray}(::Type{T}) = Base.LinearFast() + .. function:: countnz(A) Counts the number of nonzero values in array A (dense or sparse). Note that this is not a constant-time operation. For sparse matrices, one should usually use ``nnz``, which returns the number of stored values. From ec8f5d9ceab5ce6efa2b8338f43cf67714aec68c Mon Sep 17 00:00:00 2001 From: Stefan Karpinski Date: Fri, 17 Apr 2015 10:32:19 -0400 Subject: [PATCH 2/2] LICENSE: clarify that GMP is dual licensed as GPL2 or LGPL3 --- LICENSE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE.md b/LICENSE.md index dc8f00ace49ca..2c2b9c81704cd 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -53,7 +53,7 @@ their own licenses: - [OPENSPECFUN](https://github.com/JuliaLang/openspecfun) [MIT, public domain] - [FADDEEVA](http://ab-initio.mit.edu/Faddeeva) [MIT] - [FFTW](http://fftw.org/doc/License-and-Copyright.html) [GPL2+] -- [GMP](http://gmplib.org/manual/Copying.html#Copying) [LGPL3+, GPL2+] +- [GMP](http://gmplib.org/manual/Copying.html#Copying) [LGPL3+ or GPL2+] - [LIBGIT2](https://github.com/libgit2/libgit2/blob/development/COPYING) [GPL2+ with unlimited linking exception] - [MPFR](http://www.mpfr.org/mpfr-current/mpfr.html#Copying) [LGPL3+] - [OPENBLAS](https://raw.github.com/xianyi/OpenBLAS/master/LICENSE) [BSD-3]