Skip to content

Commit fcb6341

Browse files
committed
Clean up code and version bump
1 parent db391f3 commit fcb6341

File tree

5 files changed

+16
-72
lines changed

5 files changed

+16
-72
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ArrayInterface"
22
uuid = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
3-
version = "3.0.2"
3+
version = "3.1"
44

55
[deps]
66
IfElse = "615f187c-cbe4-4ef1-ba3b-2fcf58d6d173"

src/ArrayInterface.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ using LinearAlgebra
66
using SparseArrays
77
using Base.Cartesian
88

9-
using Base: @pure, @propagate_inbounds, tail, OneTo, LogicalIndex, Slice, ReinterpretArray
9+
using Base: @propagate_inbounds, tail, OneTo, LogicalIndex, Slice, ReinterpretArray
1010

1111
Base.@pure __parameterless_type(T) = Base.typename(T).wrapper
1212
parameterless_type(x) = parameterless_type(typeof(x))

src/dimensions.jl

Lines changed: 5 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -172,26 +172,8 @@ end
172172
i === nothing && no_dimname_error(T, dim)
173173
return i
174174
end
175-
#=
176-
return i
177-
i = 1
178-
out = 0
179-
for s in dimnames(T)
180-
if Symbol(s) === dim
181-
out = i
182-
break
183-
else
184-
i += i
185-
end
186-
end
187-
if out === 0
188-
no_dimname_error(T, dim)
189-
end
190-
return out
191-
end
192-
=#
193-
194175
to_dims(::Type{T}, dims::Tuple) where {T} = map(i -> to_dims(T, i), dims)
176+
195177
#=
196178
order_named_inds(names, namedtuple)
197179
order_named_inds(names, subnames, inds)
@@ -235,49 +217,6 @@ function _order_named_inds_check(inds::Tuple{Vararg{Any,N}}, nkwargs::Int) where
235217
return nothing
236218
end
237219

238-
239-
#=
240-
name_to_idx(name::StaticSymbol, kwargs::Tuple, inds::Tuple, )
241-
name_to_idx(name::StaticSymbol, kwargs::Tuple, inds::Tuple) = _name_to_index(find_first_eq(), inds)
242-
_name_to_index(::Zero, ::Tuple) = Colon()
243-
_name_to_index(::StaticInt{N}, inds::Tuple) where {N} = getfield(inds, N)
244-
245-
# return permute(inds, static_find_all_in(nd, x))
246-
_colon_or_inds(inds::Tuple, ::Zero) = :
247-
_colon_or_inds(inds::Tuple, ::StaticInt{I}) where {I} = getfield(inds, I)
248-
249-
n_i -> _colon_or_inds(inds, find_first_eq(n_i, x))
250-
# FIXME this needs to insert a colon on missing names
251-
252-
@inline function order_named_inds(val::Val{L}; kwargs...) where {L}
253-
if isempty(kwargs)
254-
return ()
255-
else
256-
return order_named_inds(val, kwargs.data)
257-
end
258-
end
259-
@generated function order_named_inds(val::Val{L}, ni::NamedTuple{K}) where {L,K}
260-
tuple_issubset(K, L) || throw(DimensionMismatch("Expected subset of $L, got $K"))
261-
exs = map(L) do n
262-
if Base.sym_in(n, K)
263-
qn = QuoteNode(n)
264-
:(getfield(ni, $qn))
265-
else
266-
:(Colon())
267-
end
268-
end
269-
return Expr(:tuple, exs...)
270-
end
271-
=#
272-
273-
@generated function _perm_tuple(::Type{T}, ::Val{P}) where {T,P}
274-
out = Expr(:curly, :Tuple)
275-
for p in P
276-
push!(out.args, T.parameters[p])
277-
end
278-
Expr(:block, Expr(:meta, :inline), out)
279-
end
280-
281220
"""
282221
axes_types(::Type{T}[, d]) -> Type
283222
@@ -293,14 +232,11 @@ function axes_types(::Type{T}) where {T}
293232
return axes_types(parent_type(T))
294233
end
295234
end
296-
function axes_types(::Type{T}) where {T<:Adjoint}
297-
return _perm_tuple(axes_types(parent_type(T)), Val((2, 1)))
298-
end
299-
function axes_types(::Type{T}) where {T<:Transpose}
300-
return _perm_tuple(axes_types(parent_type(T)), Val((2, 1)))
235+
function axes_types(::Type{T}) where {T<:MatAdjTrans}
236+
return eachop_tuple(_get_tuple, axes_types(parent_type(T)), to_parent_dims(T))
301237
end
302-
function axes_types(::Type{T}) where {I1,T<:PermutedDimsArray{<:Any,<:Any,I1}}
303-
return _perm_tuple(axes_types(parent_type(T)), Val(I1))
238+
function axes_types(::Type{T}) where {T<:PermutedDimsArray}
239+
return eachop_tuple(_get_tuple, axes_types(parent_type(T)), to_parent_dims(T))
304240
end
305241
function axes_types(::Type{T}) where {T<:AbstractRange}
306242
if known_length(T) === nothing

src/indexing.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,3 +662,4 @@ end
662662
) where {N}
663663
return _generate_unsafe_setindex!_body(N)
664664
end
665+

src/static.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,6 @@ function invariant_permutation(x::T, y::T) where {N,T<:Tuple{Vararg{StaticInt,N}
272272
end
273273

274274
permute(x::Tuple, perm::Val) = permute(x, static(perm))
275-
# TODO delete this? permute(x::Tuple, perm::Tuple) = eachop(getindex, x, perm)
276275
function permute(x::Tuple{Vararg{Any}}, perm::Tuple{Vararg{StaticInt}})
277276
if invariant_permutation(perm, perm) isa False
278277
return eachop(getindex, x, perm)
@@ -297,6 +296,14 @@ end
297296
Expr(:block, Expr(:meta, :inline), t)
298297
end
299298

299+
@generated function eachop_tuple(op, x, ::I) where {I}
300+
t = Expr(:curly, :Tuple)
301+
for p in I.parameters
302+
push!(t.args, :(op(x, StaticInt{$(p.parameters[1])}())))
303+
end
304+
Expr(:block, Expr(:meta, :inline), t)
305+
end
306+
300307
"""
301308
eq(x::StaticInt, y::StaticInt) -> StaticBool
302309

0 commit comments

Comments
 (0)