@@ -6,7 +6,8 @@ import Base: size, getindex, setindex!, IndexStyle, checkbounds, convert,
6
6
+ , - , * , / , \ , diff, sum, cumsum, maximum, minimum, sort, sort!,
7
7
any, all, axes, isone, iterate, unique, allunique, permutedims, inv,
8
8
copy, vec, setindex!, count, == , reshape, _throw_dmrs, map, zero,
9
- show, view, in, mapreduce, one, reverse, promote_op, promote_rule, repeat
9
+ show, view, in, mapreduce, one, reverse, promote_op, promote_rule, repeat,
10
+ parent
10
11
11
12
import LinearAlgebra: rank, svdvals!, tril, triu, tril!, triu!, diag, transpose, adjoint, fill!,
12
13
dot, norm2, norm1, normInf, normMinusInf, normp, lmul!, rmul!, diagzero, AdjointAbsVec, TransposeAbsVec,
@@ -369,6 +370,8 @@ axes(T::UpperOrLowerTriangular{<:Any,<:AbstractFill}) = axes(parent(T))
369
370
axes (rd:: RectDiagonal ) = rd. axes
370
371
size (rd:: RectDiagonal ) = map (length, rd. axes)
371
372
373
+ parent (rd:: RectDiagonal ) = rd. diag
374
+
372
375
@inline function getindex (rd:: RectDiagonal{T} , i:: Integer , j:: Integer ) where T
373
376
@boundscheck checkbounds (rd, i, j)
374
377
if i == j
@@ -411,7 +414,8 @@ Base.replace_in_print_matrix(A::RectDiagonal, i::Integer, j::Integer, s::Abstrac
411
414
412
415
413
416
const RectOrDiagonal{T,V,Axes} = Union{RectDiagonal{T,V,Axes}, Diagonal{T,V}}
414
- const RectDiagonalEye{T} = RectDiagonal{T,<: Ones{T,1} }
417
+ const RectOrDiagonalFill{T,V<: AbstractFillVector{T} ,Axes} = RectOrDiagonal{T,V,Axes}
418
+ const RectDiagonalFill{T,V<: AbstractFillVector{T} } = RectDiagonal{T,V}
415
419
const SquareEye{T,Axes} = Diagonal{T,Ones{T,1 ,Tuple{Axes}}}
416
420
const Eye{T,Axes} = RectOrDiagonal{T,Ones{T,1 ,Tuple{Axes}}}
417
421
@@ -537,6 +541,15 @@ convert(::Type{AbstractSparseArray{Tv,Ti}}, Z::Eye{T}) where {T,Tv,Ti} =
537
541
convert (:: Type{AbstractSparseArray{Tv,Ti,2}} , Z:: Eye{T} ) where {T,Tv,Ti} =
538
542
convert (SparseMatrixCSC{Tv,Ti}, Z)
539
543
544
+ function SparseMatrixCSC {Tv} (R:: RectOrDiagonalFill ) where {Tv}
545
+ SparseMatrixCSC {Tv,eltype(axes(R,1))} (R)
546
+ end
547
+ function SparseMatrixCSC {Tv,Ti} (R:: RectOrDiagonalFill ) where {Tv,Ti}
548
+ Base. require_one_based_indexing (R)
549
+ v = parent (R)
550
+ J = getindex_value (v)* I
551
+ SparseMatrixCSC {Tv,Ti} (J, size (R))
552
+ end
540
553
541
554
# ########
542
555
# maximum/minimum
0 commit comments