@@ -169,8 +169,41 @@ function combine_nameddimsarraytype(
169
169
end
170
170
combine_nameddimsarraytype (:: Type{T} , :: Type{T} ) where {T<: AbstractNamedDimsArray } = T
171
171
172
- Base. axes (a:: AbstractNamedDimsArray ) = map (named, axes (dename (a)), nameddimsindices (a))
173
- Base. size (a:: AbstractNamedDimsArray ) = map (named, size (dename (a)), nameddimsindices (a))
172
+ using Base. Broadcast: Broadcasted, Style
173
+
174
+ struct NaiveOrderedSet{Values}
175
+ values:: Values
176
+ end
177
+ Base. Tuple (s:: NaiveOrderedSet ) = s. values
178
+ Base. length (s:: NaiveOrderedSet ) = length (Tuple (s))
179
+ Base. axes (s:: NaiveOrderedSet ) = axes (Tuple (s))
180
+ Base.:(== )(s1:: NaiveOrderedSet , s2:: NaiveOrderedSet ) = issetequal (Tuple (s1), Tuple (s2))
181
+ Base. iterate (s:: NaiveOrderedSet , args... ) = iterate (Tuple (s), args... )
182
+ Base. getindex (s:: NaiveOrderedSet , I:: Int ) = Tuple (s)[I]
183
+ Base. invperm (s:: NaiveOrderedSet ) = NaiveOrderedSet (invperm (Tuple (s)))
184
+ Base. Broadcast. _axes (:: Broadcasted , axes:: NaiveOrderedSet ) = axes
185
+ Base. Broadcast. BroadcastStyle (:: Type{<:NaiveOrderedSet} ) = Style {NaiveOrderedSet} ()
186
+ Base. Broadcast. broadcastable (s:: NaiveOrderedSet ) = s
187
+
188
+ function Base. copy (
189
+ bc:: Broadcasted{Style{NaiveOrderedSet},<:Any,<:Any,<:Tuple{<:NaiveOrderedSet}}
190
+ )
191
+ return NaiveOrderedSet (bc. f .(Tuple (only (bc. args))))
192
+ end
193
+ # Multiple arguments not supported.
194
+ function Base. copy (bc:: Broadcasted{Style{NaiveOrderedSet}} )
195
+ return error (" This broadcasting expression of `NaiveOrderedSet` is not supported." )
196
+ end
197
+ function Base. map (f:: Function , s:: NaiveOrderedSet )
198
+ return NaiveOrderedSet (map (f, Tuple (s)))
199
+ end
200
+
201
+ function Base. axes (a:: AbstractNamedDimsArray )
202
+ return NaiveOrderedSet (map (named, axes (dename (a)), nameddimsindices (a)))
203
+ end
204
+ function Base. size (a:: AbstractNamedDimsArray )
205
+ return NaiveOrderedSet (map (named, size (dename (a)), nameddimsindices (a)))
206
+ end
174
207
175
208
# Circumvent issue when ndims isn't known at compile time.
176
209
function Base. axes (a:: AbstractNamedDimsArray , d)
@@ -267,6 +300,9 @@ struct NamedDimsCartesianIndices{
267
300
return new {length(indices),typeof(indices),Tuple{eltype.(indices)...}} (indices)
268
301
end
269
302
end
303
+ function NamedDimsCartesianIndices (indices:: NaiveOrderedSet )
304
+ return NamedDimsCartesianIndices (Tuple (indices))
305
+ end
270
306
271
307
Base. eltype (I:: NamedDimsCartesianIndices ) = eltype (typeof (I))
272
308
Base. axes (I:: NamedDimsCartesianIndices ) = map (only ∘ axes, I. indices)
@@ -672,20 +708,25 @@ end
672
708
Broadcast. combine_axes (a:: AbstractNamedDimsArray ) = axes (a)
673
709
674
710
function Broadcast. broadcast_shape (
675
- ax1:: Tuple{Vararg{AbstractNamedUnitRange}} ,
676
- ax2:: Tuple{Vararg{AbstractNamedUnitRange}} ,
677
- ax_rest:: Tuple{Vararg{AbstractNamedUnitRange}} ...,
711
+ ax1:: NaiveOrderedSet , ax2:: NaiveOrderedSet , ax_rest:: NaiveOrderedSet...
678
712
)
679
713
return broadcast_shape (broadcast_shape (ax1, ax2), ax_rest... )
680
714
end
681
715
682
- function Broadcast. broadcast_shape (
683
- ax1:: Tuple{Vararg{AbstractNamedUnitRange}} , ax2:: Tuple{Vararg{AbstractNamedUnitRange}}
684
- )
716
+ function Broadcast. broadcast_shape (ax1:: NaiveOrderedSet , ax2:: NaiveOrderedSet )
685
717
return promote_shape (ax1, ax2)
686
718
end
687
719
688
- function Base. promote_shape (
720
+ # Handle scalar values.
721
+ function Broadcast. broadcast_shape (ax1:: Tuple{} , ax2:: NaiveOrderedSet )
722
+ return ax2
723
+ end
724
+
725
+ function Base. promote_shape (ax1:: NaiveOrderedSet , ax2:: NaiveOrderedSet )
726
+ return NaiveOrderedSet (set_promote_shape (Tuple (ax1), Tuple (ax2)))
727
+ end
728
+
729
+ function set_promote_shape (
689
730
ax1:: Tuple{AbstractNamedUnitRange,Vararg{AbstractNamedUnitRange,N}} ,
690
731
ax2:: Tuple{AbstractNamedUnitRange,Vararg{AbstractNamedUnitRange,N}} ,
691
732
) where {N}
@@ -695,8 +736,11 @@ function Base.promote_shape(
695
736
return named .(ax_promoted, name .(ax1))
696
737
end
697
738
698
- # Avoid comparison of `NamedInteger` against `1`.
699
- function Broadcast. check_broadcast_shape (
739
+ function Broadcast. check_broadcast_shape (ax1:: NaiveOrderedSet , ax2:: NaiveOrderedSet )
740
+ return set_check_broadcast_shape (Tuple (ax1), Tuple (ax2))
741
+ end
742
+
743
+ function set_check_broadcast_shape (
700
744
ax1:: Tuple{AbstractNamedUnitRange,Vararg{AbstractNamedUnitRange,N}} ,
701
745
ax2:: Tuple{AbstractNamedUnitRange,Vararg{AbstractNamedUnitRange,N}} ,
702
746
) where {N}
@@ -706,24 +750,17 @@ function Broadcast.check_broadcast_shape(
706
750
return nothing
707
751
end
708
752
709
- # Handle scalars.
710
- function Base. promote_shape (
711
- ax1:: Tuple{AbstractNamedUnitRange,Vararg{AbstractNamedUnitRange}} , ax2:: Tuple{}
712
- )
713
- return ax1
714
- end
715
-
716
753
# Dename and lazily permute the arguments using the reference
717
754
# dimension names.
718
755
# TODO : Make a version that gets the nameddimsindices from `m`.
719
756
function denamed (m:: Mapped , nameddimsindices)
720
757
return mapped (m. f, map (arg -> denamed (arg, nameddimsindices), m. args)... )
721
758
end
722
759
723
- function Base. similar (bc:: Broadcasted{<:AbstractNamedDimsArrayStyle} , elt:: Type , ax:: Tuple )
760
+ function Base. similar (bc:: Broadcasted{<:AbstractNamedDimsArrayStyle} , elt:: Type , ax)
724
761
nameddimsindices = name .(ax)
725
762
m′ = denamed (Mapped (bc), nameddimsindices)
726
- return nameddims (similar (m′, elt, dename .(ax )), nameddimsindices)
763
+ return nameddims (similar (m′, elt, dename .(Tuple (ax) )), nameddimsindices)
727
764
end
728
765
729
766
function Base. copyto! (
0 commit comments