Skip to content

Commit

Permalink
union and intersect for SOneTo (#1197)
Browse files Browse the repository at this point in the history
* union and intersect for SOneTo

* Test for exact match
  • Loading branch information
jishnub authored Sep 22, 2023
1 parent 03c13a0 commit 27a6079
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/SOneTo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,6 @@ Base.promote_rule(a::Type{Base.OneTo{T}}, ::Type{SOneTo{n}}) where {T,n} =
function Base.reduced_indices(inds::Tuple{SOneTo,Vararg{SOneTo}}, d::Int)
Base.reduced_indices(map(Base.OneTo, inds), d)
end

Base.intersect(r::SOneTo{n1}, s::SOneTo{n2}) where {n1,n2} = SOneTo(min(n1, n2))
Base.union(r::SOneTo{n1}, s::SOneTo{n2}) where {n1,n2} = SOneTo(max(n1, n2))
3 changes: 3 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -205,5 +205,8 @@
@test convert(StaticArrays.SOneTo{2}, 1:2) === StaticArrays.SOneTo{2}()
@test_throws DimensionMismatch StaticArrays.SOneTo{2}(1:3)
@test_throws DimensionMismatch StaticArrays.SOneTo{2}(1:1)

@test @inferred(intersect(SOneTo(2), SOneTo(4))) === SOneTo(2)
@test @inferred(union(SOneTo(2), SOneTo(4))) === SOneTo(4)
end
end

0 comments on commit 27a6079

Please sign in to comment.