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

Remove all @pure, does not actually fix #115. #116

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
deps/deps.jl
Manifest.toml
*~
*#*
*#*#
4 changes: 2 additions & 2 deletions src/ArrayInterface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ using Requires
using LinearAlgebra
using SparseArrays

using Base: @pure, @propagate_inbounds, tail, OneTo, LogicalIndex, Slice, ReinterpretArray
using Base: @propagate_inbounds, tail, OneTo, LogicalIndex, Slice, ReinterpretArray

Base.@pure __parameterless_type(T) = Base.typename(T).wrapper
@generated __parameterless_type(::Type{T}) where {T} = Base.typename(T).wrapper
parameterless_type(x) = parameterless_type(typeof(x))
parameterless_type(x::Type) = __parameterless_type(x)

Expand Down
31 changes: 17 additions & 14 deletions src/dimensions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -148,32 +148,35 @@ to_dims(x::Tuple{Vararg{Symbol}}, d::Colon) = d # `:` is the default for most
end
return i
end
Base.@pure function _sym_to_dim(x::Tuple{Vararg{Symbol,N}}, sym::Symbol) where {N}
for i in 1:N
getfield(x, i) === sym && return i
@generated function _sym_to_dim(x::Tuple{Vararg{Symbol,N}}, sym::Symbol) where {N}
quote
$(Expr(:meta,:inline))
Base.Cartesian.@nexprs $N n -> getfield(x, n) === sym && return n
return 0
end
return 0
end

"""
tuple_issubset

A version of `issubset` sepecifically for `Tuple`s of `Symbol`s, that is `@pure`.
This helps it get optimised out of existance. It is less of an abuse of `@pure` than
most of the stuff for making `NamedTuples` work.
A version of `issubset` sepecifically for `Tuple`s of `Symbol`s.
"""
Base.@pure function tuple_issubset(
@generated function tuple_issubset(
lhs::Tuple{Vararg{Symbol,N}}, rhs::Tuple{Vararg{Symbol,M}}
) where {N,M}
N <= M || return false
for a in lhs
found = false
for b in rhs
found |= a === b
quote
$(Expr(:meta,:inline))
Base.Cartesian.@nexprs $N n -> begin
a = lhs[n]
found = false
Base.Cartesian.@nexprs $M m -> begin
found |= a === rhs[m]
end
found || return false
end
found || return false
return true
end
return true
end

"""
Expand Down
10 changes: 5 additions & 5 deletions src/static.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const One = StaticInt{1}

Base.show(io::IO, ::StaticInt{N}) where {N} = print(io, "static($N)")

Base.@pure StaticInt(N::Int) = StaticInt{N}()
@inline StaticInt(N::Int) = StaticInt{N}()
StaticInt(N::Integer) = StaticInt(convert(Int, N))
StaticInt(::StaticInt{N}) where {N} = StaticInt{N}()
StaticInt(::Val{N}) where {N} = StaticInt{N}()
Expand Down Expand Up @@ -250,7 +250,7 @@ Base.promote_rule(::Type{<:StaticBool}, ::Type{<:StaticBool}) = StaticBool
Base.promote_rule(::Type{<:StaticBool}, ::Type{Bool}) = Bool
Base.promote_rule(::Type{Bool}, ::Type{<:StaticBool}) = Bool

Base.@pure _get_tuple(::Type{T}, ::StaticInt{i}) where {T<:Tuple, i} = T.parameters[i]
@generated _get_tuple(::Type{T}, ::StaticInt{i}) where {T<:Tuple, i} = T.parameters[i]

Base.all(::Tuple{Vararg{True}}) = true
Base.all(::Tuple{Vararg{Union{True,False}}}) = false
Expand All @@ -260,14 +260,14 @@ Base.any(::Tuple{Vararg{True}}) = true
Base.any(::Tuple{Vararg{Union{True,False}}}) = true
Base.any(::Tuple{Vararg{False}}) = false

Base.@pure nstatic(::Val{N}) where {N} = ntuple(i -> StaticInt(i), Val(N))
@generated nstatic(::Val{N}) where {N} = ntuple(StaticInt, Val(N))

# I is a tuple of Int
@pure function _val_to_static(::Val{I}) where {I}
@inline function _val_to_static(::Val{I}) where {I}
return ntuple(i -> StaticInt(getfield(I, i)), Val(length(I)))
end

@pure is_permuting(perm::Tuple{Vararg{StaticInt,N}}) where {N} = perm !== nstatic(Val(N))
@inline is_permuting(perm::Tuple{Vararg{StaticInt,N}}) where {N} = perm !== nstatic(Val(N))

permute(x::Tuple, perm::Tuple) = eachop(getindex, x, perm)
function permute(x::Tuple{Vararg{Any,N}}, perm::Tuple{Vararg{Any,N}}) where {N}
Expand Down
8 changes: 6 additions & 2 deletions src/stridelayout.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,12 @@ function contiguous_axis_indicator(::Type{A}) where {D,A<:AbstractArray{<:Any,D}
end
contiguous_axis_indicator(::A) where {A<:AbstractArray} = contiguous_axis_indicator(A)
contiguous_axis_indicator(::Nothing, ::Val) = nothing
Base.@pure function contiguous_axis_indicator(::StaticInt{N}, ::Val{D}) where {N,D}
return ntuple(d -> StaticBool(d === N), Val{D}())
@generated function contiguous_axis_indicator(::StaticInt{N}, ::Val{D}) where {N,D}
t = Expr(:tuple)
for d in 1:D
push!(t.args, Expr(:call, d == N ? :True : :False))
end
t
end

function rank_to_sortperm(R::Tuple{Vararg{StaticInt,N}}) where {N}
Expand Down
7 changes: 7 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,13 @@ end
@test @inferred(ArrayInterface.offsets(Op)) === (11, 4, 8)

@test @inferred(ArrayInterface.offsets((1,2,3))) === (StaticInt(1),)

if VERSION ≥ v"1.6.0-DEV.1581"
colors = [(R = rand(), G = rand(), B = rand()) for i ∈ 1:100];

colormat = reinterpret(reshape, Float64, colors)
@test @inferred(ArrayInterface.strides(colormat)) === (StaticInt(1), StaticInt(3))
end
end

@test ArrayInterface.can_avx(ArrayInterface.can_avx) == false
Expand Down