@@ -3,23 +3,6 @@ function throw_dim_error(@nospecialize(x), @nospecialize(dim))
3
3
throw (DimensionMismatch (" $x does not have dimension corresponding to $dim " ))
4
4
end
5
5
6
- @propagate_inbounds function _promote_shape (a:: Tuple{A,Vararg{Any}} , b:: Tuple{B,Vararg{Any}} ) where {A,B}
7
- (_try_static (getfield (a, 1 ), getfield (b, 1 )), _promote_shape (tail (a), tail (b))... )
8
- end
9
- _promote_shape (:: Tuple{} , :: Tuple{} ) = ()
10
- @propagate_inbounds function _promote_shape (:: Tuple{} , b:: Tuple{B} ) where {B}
11
- (_try_static (static (1 ), getfield (b, 1 )),)
12
- end
13
- @propagate_inbounds function _promote_shape (a:: Tuple{A} , :: Tuple{} ) where {A}
14
- (_try_static (static (1 ), getfield (a, 1 )),)
15
- end
16
- @propagate_inbounds function Base. promote_shape (a:: Tuple{Vararg{CanonicalInt}} , b:: Tuple{Vararg{CanonicalInt}} )
17
- _promote_shape (a, b)
18
- end
19
-
20
- # julia> @btime ArrayInterfaceCore.is_increasing(ArrayInterfaceCore.nstatic(Val(10)))
21
- # 0.045 ns (0 allocations: 0 bytes)
22
- # ArrayInterfaceCore.True()
23
6
function is_increasing (perm:: Tuple{StaticInt{X},StaticInt{Y},Vararg} ) where {X, Y}
24
7
if X <= Y
25
8
return is_increasing (tail (perm))
@@ -44,7 +27,7 @@ is_increasing(::Tuple{}) = True()
44
27
Returns the mapping from parent dimensions to child dimensions.
45
28
"""
46
29
from_parent_dims (x) = from_parent_dims (typeof (x))
47
- from_parent_dims (:: Type{T} ) where {T} = nstatic ( Val (ndims (T)))
30
+ from_parent_dims (:: Type{T} ) where {T} = ntuple (static, StaticInt (ndims (T)))
48
31
from_parent_dims (:: Type{T} ) where {T<: VecAdjTrans } = (StaticInt (2 ),)
49
32
from_parent_dims (:: Type{T} ) where {T<: MatAdjTrans } = (StaticInt (2 ), One ())
50
33
from_parent_dims (:: Type{<:SubArray{T,N,A,I}} ) where {T,N,A,I} = _from_sub_dims (I)
65
48
from_parent_dims (:: Type{<:PermutedDimsArray{T,N,<:Any,I}} ) where {T,N,I} = static (Val (I))
66
49
function from_parent_dims (:: Type{<:ReinterpretArray{T,N,S,A,IsReshaped}} ) where {T,N,S,A,IsReshaped}
67
50
if ! IsReshaped || sizeof (S) === sizeof (T)
68
- return nstatic ( Val (ndims (A)))
51
+ return ntuple (static, StaticInt (ndims (A)))
69
52
elseif sizeof (S) > sizeof (T)
70
- return tail (nstatic ( Val (ndims (A) + 1 )))
53
+ return tail (ntuple (static, StaticInt (ndims (A) + 1 )))
71
54
else # sizeof(S) < sizeof(T)
72
- return (Zero (), nstatic ( Val (N))... )
55
+ return (Zero (), ntuple (static, StaticInt (N))... )
73
56
end
74
57
end
75
58
100
83
Returns the mapping from child dimensions to parent dimensions.
101
84
"""
102
85
to_parent_dims (x) = to_parent_dims (typeof (x))
103
- to_parent_dims (:: Type{T} ) where {T} = nstatic ( Val (ndims (T)))
86
+ to_parent_dims (:: Type{T} ) where {T} = ntuple (static, StaticInt (ndims (T)))
104
87
to_parent_dims (:: Type{T} ) where {T<: Union{Transpose,Adjoint} } = (StaticInt (2 ), One ())
105
88
to_parent_dims (:: Type{<:PermutedDimsArray{T,N,I}} ) where {T,N,I} = static (Val (I))
106
89
to_parent_dims (:: Type{<:SubArray{T,N,A,I}} ) where {T,N,A,I} = _to_sub_dims (I)
@@ -117,7 +100,7 @@ to_parent_dims(::Type{<:SubArray{T,N,A,I}}) where {T,N,A,I} = _to_sub_dims(I)
117
100
out
118
101
end
119
102
function to_parent_dims (:: Type{<:ReinterpretArray{T,N,S,A,IsReshaped}} ) where {T,N,S,A,IsReshaped}
120
- pdims = nstatic ( Val (ndims (A)))
103
+ pdims = ntuple (static, StaticInt (ndims (A)))
121
104
if ! IsReshaped || sizeof (S) === sizeof (T)
122
105
return pdims
123
106
elseif sizeof (S) > sizeof (T)
@@ -280,7 +263,7 @@ to_dims(x, @nospecialize(dim::CanonicalInt)) = dim
280
263
to_dims (x, dim:: Integer ) = Int (dim)
281
264
to_dims (x, dim:: Union{StaticSymbol,Symbol} ) = _to_dim (dimnames (x), dim)
282
265
function to_dims (x, dims:: Tuple{Vararg{Any,N}} ) where {N}
283
- eachop (_to_dims, nstatic ( Val (N)), dimnames (x), dims)
266
+ eachop (_to_dims, ntuple (static, StaticInt (N)), dimnames (x), dims)
284
267
end
285
268
@inline _to_dims (x:: Tuple , d:: Tuple , n:: StaticInt{N} ) where {N} = _to_dim (x, getfield (d, N))
286
269
@inline function _to_dim (x:: Tuple , d:: Union{Symbol,StaticSymbol} )
0 commit comments