Skip to content

Commit 5d674dc

Browse files
authored
Backports for 1.12 (#654)
2 parents cdbad55 + 0345d1a commit 5d674dc

4 files changed

Lines changed: 15 additions & 12 deletions

File tree

src/linalg.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ const WrapperMatrixTypes{T,MT} = Union{
641641
Hermitian{T,MT},
642642
}
643643

644-
function dot(A::Union{DenseMatrixUnion,WrapperMatrixTypes{<:Any,Union{DenseMatrixUnion,AbstractSparseMatrix}}}, B::AbstractSparseMatrixCSC)
644+
function dot(A::Union{DenseMatrixUnion,WrapperMatrixTypes{<:Any,<:Union{DenseMatrixUnion,AbstractSparseMatrix}}}, B::AbstractSparseMatrixCSC)
645645
T = promote_type(eltype(A), eltype(B))
646646
(m, n) = size(A)
647647
if (m, n) != size(B)
@@ -663,7 +663,7 @@ function dot(A::Union{DenseMatrixUnion,WrapperMatrixTypes{<:Any,Union{DenseMatri
663663
return s
664664
end
665665

666-
function dot(A::AbstractSparseMatrixCSC, B::Union{DenseMatrixUnion,WrapperMatrixTypes{<:Any,Union{DenseMatrixUnion,AbstractSparseMatrix}}})
666+
function dot(A::AbstractSparseMatrixCSC, B::Union{DenseMatrixUnion,WrapperMatrixTypes{<:Any,<:Union{DenseMatrixUnion,AbstractSparseMatrix}}})
667667
return conj(dot(B, A))
668668
end
669669

@@ -1210,7 +1210,7 @@ function nzrangelo(A, i, excl=false)
12101210
@inbounds r2 < r1 || rv[r1] >= i + excl ? r : (searchsortedfirst(view(rv, r1:r2), i + excl) + r1-1):r2
12111211
end
12121212

1213-
dot(x::AbstractVector, A::RealHermSymComplexHerm{<:Any,<:AbstractSparseMatrixCSC}, y::AbstractVector) =
1213+
dot(x::AbstractVector, A::RealHermSymComplexHerm{<:Real,<:AbstractSparseMatrixCSC}, y::AbstractVector) =
12141214
_dot(x, parent(A), y, A.uplo == 'U' ? nzrangeup : nzrangelo, A isa Symmetric ? identity : real, A isa Symmetric ? transpose : adjoint)
12151215
function _dot(x::AbstractVector, A::AbstractSparseMatrixCSC, y::AbstractVector, rangefun::Function, diagop::Function, odiagop::Function)
12161216
require_one_based_indexing(x, y)
@@ -1242,7 +1242,7 @@ function _dot(x::AbstractVector, A::AbstractSparseMatrixCSC, y::AbstractVector,
12421242
end
12431243
return r
12441244
end
1245-
dot(x::SparseVector, A::RealHermSymComplexHerm{<:Any,<:AbstractSparseMatrixCSC}, y::SparseVector) =
1245+
dot(x::SparseVector, A::RealHermSymComplexHerm{<:Real,<:AbstractSparseMatrixCSC}, y::SparseVector) =
12461246
_dot(x, parent(A), y, A.uplo == 'U' ? nzrangeup : nzrangelo, A isa Symmetric ? identity : real)
12471247
function _dot(x::SparseVector, A::AbstractSparseMatrixCSC, y::SparseVector, rangefun::Function, diagop::Function)
12481248
m, n = size(A)
@@ -1577,7 +1577,7 @@ function cond(A::AbstractSparseMatrixCSC, p::Real=2)
15771577
normA = opnorm(A, Inf)
15781578
return normA * normAinv
15791579
elseif p == 2
1580-
throw(ArgumentError("2-norm condition number is not implemented for sparse matrices, try cond(Array(A), 2) instead"))
1580+
throw(ArgumentError("only 1- and Inf-norm condition numbers are implemented for sparse matrices, for 2-norm try cond(Array(A), 2) instead"))
15811581
else
15821582
throw(ArgumentError("second argument must be either 1 or Inf, got $p"))
15831583
end

src/readonly.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,19 @@ ReadOnly(x::ReadOnly) = x
1313
Base.getproperty(x::ReadOnly, s::Symbol) = Base.getproperty(parent(x), s)
1414
@inline Base.parent(x::ReadOnly) = getfield(x, :parent)
1515

16-
for i in [:length, :first, :last, :eachindex, :firstindex, :lastindex, :eltype]
16+
for i in [:length, :first, :last, :axes, :size]
1717
@eval Base.@propagate_inbounds @inline Base.$i(x::ReadOnly) = Base.$i(parent(x))
1818
end
19-
for i in [:iterate, :axes, :getindex, :size, :strides]
19+
for i in [:iterate, :getindex, :strides]
2020
@eval(Base.@propagate_inbounds @inline Base.$i(x::ReadOnly, y...) = Base.$i(parent(x), y...))
2121
end
2222

23+
Base.eachindex(i::IndexLinear, x::ReadOnly) = eachindex(i, parent(x))
24+
Base.eachindex(i::IndexCartesian, x::ReadOnly) = eachindex(i, parent(x))
25+
2326
Base.unsafe_convert(x::Type{Ptr{T}}, A::ReadOnly) where T = Base.unsafe_convert(x, parent(A))
2427
Base.elsize(::Type{ReadOnly{T,N,V}}) where {T,N,V} = Base.elsize(V)
25-
Base.@propagate_inbounds @inline Base.setindex!(x::ReadOnly, v, ind...) = if v == getindex(parent(x), ind...)
28+
Base.@propagate_inbounds @inline Base.setindex!(x::ReadOnly, v, ind::Vararg{Integer}) = if v == getindex(parent(x), ind...)
2629
v
2730
else
2831
error("Can't change $(typeof(x)).")

src/solvers/cholmod.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,7 +1349,7 @@ end
13491349
size(F::Factor) = (size(F, 1), size(F, 2))
13501350
axes(A::Union{Dense,Sparse,Factor}) = map(Base.OneTo, size(A))
13511351

1352-
IndexStyle(::Dense) = IndexLinear()
1352+
IndexStyle(::Type{<:Dense}) = IndexLinear()
13531353

13541354
size(FC::FactorComponent, i::Integer) = size(FC.F, i)
13551355
size(FC::FactorComponent) = size(FC.F)
@@ -1370,7 +1370,6 @@ function getindex(A::Dense{T}, i::Integer) where {T<:VTypes}
13701370
unsafe_load(Ptr{T}(s.x), i)
13711371
end
13721372

1373-
IndexStyle(::Sparse) = IndexCartesian()
13741373
function getindex(A::Sparse{T}, i0::Integer, i1::Integer) where T
13751374
s = unsafe_load(typedpointer(A))
13761375
!(1 <= i0 <= s.nrow && 1 <= i1 <= s.ncol) && throw(BoundsError())

test/linalg.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -919,11 +919,12 @@ end
919919
@test dot(x, A, y) dot(x, Av, y)
920920
end
921921

922-
for (T, trans) in ((Float64, Symmetric), (ComplexF64, Hermitian)), uplo in (:U, :L)
922+
for (T, trans) in ((Float64, Symmetric), (ComplexF64, Symmetric), (ComplexF64, Hermitian)), uplo in (:U, :L)
923923
B = sprandn(T, 10, 10, 0.2)
924924
x = sprandn(T, 10, 0.4)
925925
S = trans(B'B, uplo)
926-
@test dot(x, S, x) dot(Vector(x), S, Vector(x)) dot(Vector(x), Matrix(S), Vector(x))
926+
Sd = trans(Matrix(B'B), uplo)
927+
@test dot(x, S, x) dot(x, Sd, x) dot(Vector(x), S, Vector(x)) dot(Vector(x), Sd, Vector(x))
927928
end
928929
end
929930

0 commit comments

Comments
 (0)