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

Ensure that ArrayLS and ArrayLSLS really are LinearSlow #16

Merged
merged 1 commit into from
Jul 12, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions src/array/sumindex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,26 @@ end

ArrayStrides1(A::Array) = ArrayStrides1(A, size(A,1))

Base.similar{T}(A::ArrayLSLS, ::Type{T}, dims::Tuple{Vararg{Int}}) = ArrayLSLS(similar(A.data, T, dims))

@inline Base.setindex!(A::ArrayLSLS, v, I::Int...) = A.data[I...] = v

@inline Base.unsafe_setindex!(A::ArrayLSLS, v, I::Int...) = Base.unsafe_setindex!(A.data, v, I...)

Base.first(A::ArrayLSLS) = first(A.data)

Base.size(A::MyArray) = size(A.data)
# To ensure that ArrayLS and ArrayLSLS really are LinearSlow even
# after inlining, let's make the size differ from the parent array
# (ref https://github.com/JuliaLang/julia/pull/17355#issuecomment-231748251)
@inline Base.size{T}(A::ArrayLS{T,1}) = (sz = size(A.data); (sz[1]-1,))
@inline Base.size{T}(A::ArrayLSLS{T,1}) = (sz = size(A.data); (sz[1]-1,))
@inline Base.size{T}(A::ArrayLS{T,2}) = (sz = size(A.data); (sz[1]-1,sz[2]-1))
@inline Base.size{T}(A::ArrayLSLS{T,2}) = (sz = size(A.data); (sz[1]-1,sz[2]-1))
@inline Base.size(A::ArrayLS) = map(n->n-1, size(A.data))
@inline Base.size(A::ArrayLSLS) = map(n->n-1, size(A.data))

@inline Base.similar{T}(A::ArrayLSLS, ::Type{T}, dims::Tuple{Int}) = ArrayLSLS(similar(A.data, T, (dims[1]+1,)))
@inline Base.similar{T}(A::ArrayLSLS, ::Type{T}, dims::Tuple{Int,Int}) = ArrayLSLS(similar(A.data, T, (dims[1]+1,dims[2]+1)))
@inline Base.similar{T}(A::ArrayLSLS, ::Type{T}, dims::Tuple{Vararg{Int}}) = ArrayLSLS(similar(A.data, T, map(n->n+1, dims)))

@inline Base.getindex(A::ArrayLF, i::Int) = getindex(A.data, i)
@inline Base.getindex(A::ArrayLF, i::Int, i2::Int) = getindex(A.data, i, i2)
Expand All @@ -181,8 +192,10 @@ end

function makearrays{T}(::Type{T}, r::Integer, c::Integer)
A = samerand(T, r, c)
AS = ArrayLS(A)
ASS = ArrayLSLS(A)
B = similar(A, r+1, c+1)
B[1:r, 1:c] = A
AS = ArrayLS(B)
ASS = ArrayLSLS(B)
Copy link
Member

@jrevels jrevels Jul 11, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ASS = ArrayLSLS(B)

😯 😄

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, maybe we should change those names 😄

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I didn't notice it before...maybe it's now an immortal piece of Julia benchmarking history? I'll leave it up to you to decide. 😁

AF = ArrayLF(A)
Astrd = ArrayStrides(A)
Astrd1 = ArrayStrides1(A)
Expand Down