Skip to content

Commit 780b3fc

Browse files
authored
Implement promotion (#21)
* Implement promotion * Back to master
1 parent ca45ae9 commit 780b3fc

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
run: |
3131
using Pkg
3232
Pkg.add([
33-
PackageSpec(name="MathOptInterface", rev="bl/constraint_not_inv"),
33+
PackageSpec(name="MathOptInterface", rev="master"),
3434
])
3535
- uses: julia-actions/julia-buildpkg@v1
3636
- uses: julia-actions/julia-runtest@v1

src/sets.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,15 @@ function Base.getindex(m::Factorization, i::Int, j::Int)
194194
)
195195
end
196196

197+
function Base.promote_rule(
198+
::Type{Factorization{T,M,S1}},
199+
::Type{Factorization{T,V,S2}},
200+
) where {T,M<:AbstractMatrix{T},V<:AbstractVector{T},S1,S2}
201+
return Factorization{T,M,S1}
202+
end
203+
197204
function Base.convert(
198-
::Type{<:Factorization{T,F,V}},
205+
::Type{Factorization{T,F,V}},
199206
f::Factorization{S,<:AbstractVector{S},<:AbstractArray{S,0}},
200207
) where {T,S,F<:AbstractMatrix{T},V<:AbstractVector{T}}
201208
return Factorization{T,F,V}(

test/sets.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,17 @@ end
7171

7272
_test_convert(f, a, b) = _test_convert(f(a), f(b))
7373

74+
function test_promotion()
75+
F = ones(2, 2)
76+
f = ones(2)
77+
a = LRO.Factorization(F, ones(2))
78+
b = LRO.Factorization(f, 1.0)
79+
@test Base.promote_typeof(a, b) == typeof(a)
80+
@test Base.promote_typeof(b, a) == typeof(a)
81+
@test eltype([a, b]) == typeof(a)
82+
@test eltype([b, a]) == typeof(a)
83+
end
84+
7485
function test_conversion()
7586
F = reshape([1, 2], 2, 1)
7687
lowrank = LRO.Factorization(F, [1])

0 commit comments

Comments
 (0)