Skip to content

Commit 6ca4539

Browse files
committed
Add support for IfElse
1 parent 249b660 commit 6ca4539

File tree

5 files changed

+15
-3
lines changed

5 files changed

+15
-3
lines changed

Project.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,21 @@ uuid = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
33
version = "3.0.0"
44

55
[deps]
6+
IfElse = "615f187c-cbe4-4ef1-ba3b-2fcf58d6d173"
67
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
78
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
89
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
910

1011
[compat]
12+
IfElse = "0.1"
1113
Requires = "0.5, 1.0"
1214
julia = "1.2"
1315

1416
[extras]
1517
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
1618
BandedMatrices = "aae01518-5342-5314-be14-df237901396f"
1719
BlockBandedMatrices = "ffab5731-97b5-5995-9138-79e8c1846df0"
20+
IfElse = "615f187c-cbe4-4ef1-ba3b-2fcf58d6d173"
1821
LabelledArrays = "2ee39098-c373-598a-b85f-a56591580800"
1922
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
2023
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
@@ -23,4 +26,4 @@ SuiteSparse = "4607b0f0-06f3-5cda-b6b1-a6196a1729e9"
2326
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2427

2528
[targets]
26-
test = ["Test", "LabelledArrays", "StaticArrays", "BandedMatrices", "BlockBandedMatrices", "SuiteSparse", "Random", "OffsetArrays", "Aqua"]
29+
test = ["Test", "LabelledArrays", "StaticArrays", "BandedMatrices", "BlockBandedMatrices", "SuiteSparse", "Random", "OffsetArrays", "Aqua", "IfElse"]

src/ArrayInterface.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module ArrayInterface
22

3+
using IfElse
34
using Requires
45
using LinearAlgebra
56
using SparseArrays

src/static.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,10 @@ function lt(::StaticInt{X}, ::StaticInt{Y}) where {X,Y}
362362
end
363363
end
364364

365+
IfElse.ifelse(::True, x, y) = x
366+
367+
IfElse.ifelse(::False, x, y) = y
368+
365369
"""
366370
static(x)
367371

test/runtests.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using ArrayInterface, Test
22
using Base: setindex
3+
using IfElse
34
using ArrayInterface: StaticInt, True, False
45
import ArrayInterface: has_sparsestruct, findstructralnz, fast_scalar_indexing, lu_instance, device, contiguous_axis, contiguous_batch_size, stride_rank, dense_dims, static
56
@test ArrayInterface.ismutable(rand(3))
@@ -476,11 +477,9 @@ end
476477
@test @inferred(ArrayInterface.strides(Ap)) == strides(Ap)
477478
@test @inferred(ArrayInterface.strides(Ar)) === (StaticInt{1}(), 6, 24)
478479

479-
480480
@test @inferred(ArrayInterface.strides(S)) === (StaticInt(1), StaticInt(2), StaticInt(6))
481481
@test @inferred(ArrayInterface.strides(Sp)) === (StaticInt(6), StaticInt(1), StaticInt(2))
482482
@test @inferred(ArrayInterface.strides(Sp2)) === (StaticInt(6), StaticInt(2), StaticInt(1))
483-
484483
@test @inferred(ArrayInterface.strides(view(Sp2, :, 1, 1)')) === (StaticInt(6), StaticInt(6))
485484

486485
@test @inferred(ArrayInterface.stride(Sp2, StaticInt(1))) === StaticInt(6)

test/static.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,5 +133,10 @@ end
133133

134134
@test @inferred(ArrayInterface.le(y, x)) === t
135135
@test @inferred(ArrayInterface.le(x, y)) === f
136+
137+
@test @inferred(IfElse.ifelse(t, x, y)) === x
138+
@test @inferred(IfElse.ifelse(f, x, y)) === y
136139
end
137140

141+
142+

0 commit comments

Comments
 (0)