@@ -7,15 +7,15 @@ import LinearAlgebra: mul!, BLAS, BlasFloat, generic_matvecmul!, MulAddMul
7
7
8
8
export SymmetricPacked
9
9
10
- struct SymmetricPacked{T,S<: AbstractMatrix{<:T} } <: AbstractMatrix{T}
10
+ struct SymmetricPacked{T,S<: AbstractMatrix{<:T} ,V } <: AbstractMatrix{T}
11
11
tri:: Vector{T}
12
12
n:: Int
13
13
uplo:: Char
14
14
15
- function SymmetricPacked {T,S} (tri, n, uplo) where {T,S<: AbstractMatrix{<:T} }
15
+ function SymmetricPacked {T,S,V } (tri, n, uplo) where {T,S<: AbstractMatrix{<:T} ,V }
16
16
require_one_based_indexing (tri)
17
17
uplo== ' U' || uplo== ' L' || throw (ArgumentError (" uplo must be either 'U' (upper) or 'L' (lower)" ))
18
- new {T,S} (tri, n, uplo)
18
+ new {T,S,V } (tri, n, uplo)
19
19
end
20
20
end
21
21
@@ -33,10 +33,11 @@ function pack(A::AbstractMatrix{T}, uplo::Symbol) where {T}
33
33
end
34
34
35
35
"""
36
- SymmetricPacked(A, uplo=:U)
36
+ SymmetricPacked(A, uplo=:U, offdiag=Val(:RO) )
37
37
38
38
Construct a `Symmetric` matrix in packed form of the upper (if `uplo = :U`)
39
- or lower (if `uplo = :L`) triangle of the matrix `A`.
39
+ or lower (if `uplo = :L`) triangle of the matrix `A`. `offdiag` specifies
40
+ whether elements not on the diagaonal can be set (if `:RW`) or not (if `:RO`).
40
41
41
42
# Examples
42
43
```jldoctest
@@ -63,20 +64,20 @@ julia> Base.summarysize(AP)
63
64
184
64
65
```
65
66
"""
66
- function SymmetricPacked (A:: AbstractMatrix{T} , uplo:: Symbol = :U ) where {T}
67
+ function SymmetricPacked (A:: AbstractMatrix{T} , uplo:: Symbol = :U , offdiag = Val ( :RO ) ) where {T}
67
68
n = checksquare (A)
68
- SymmetricPacked {T,typeof(A)} (pack (A, uplo), n, char_uplo (uplo))
69
+ SymmetricPacked {T,typeof(A),offdiag } (pack (A, uplo), n, char_uplo (uplo))
69
70
end
70
71
71
- function SymmetricPacked (x:: SymmetricPacked{T,S} ) where {T,S}
72
- SymmetricPacked {T,S} (T .(x. tri), x. n, x. uplo)
72
+ function SymmetricPacked (x:: SymmetricPacked{T,S,V } ) where {T,S,V }
73
+ SymmetricPacked {T,S,V } (T .(x. tri), x. n, x. uplo)
73
74
end
74
75
75
76
checksquare (x:: SymmetricPacked ) = x. n
76
77
77
- convert (:: Type{SymmetricPacked{T,S}} , x:: SymmetricPacked ) where {T,S} = SymmetricPacked {T,S} (T .(x. tri), x. n, x. uplo)
78
+ convert (:: Type{SymmetricPacked{T,S,V }} , x:: SymmetricPacked ) where {T,S,V } = SymmetricPacked {T,S} (T .(x. tri), x. n, x. uplo)
78
79
79
- unsafe_convert (:: Type{Ptr{T}} , A:: SymmetricPacked{T,S} ) where {T,S} = Base. unsafe_convert (Ptr{T}, A. tri)
80
+ unsafe_convert (:: Type{Ptr{T}} , A:: SymmetricPacked{T,S,V } ) where {T,S,V } = Base. unsafe_convert (Ptr{T}, A. tri)
80
81
81
82
size (A:: SymmetricPacked ) = (A. n,A. n)
82
83
97
98
return r
98
99
end
99
100
100
- function setindex! (A:: SymmetricPacked , v, i:: Int , j:: Int )
101
- i!= j && throw (ArgumentError (" Cannot set a non-diagonal index in a symmetric matrix" ))
101
+ function _setindex! (A:: SymmetricPacked , v, i:: Int , j:: Int )
102
102
@boundscheck checkbounds (A, i, j)
103
103
if A. uplo== ' U'
104
104
i,j = minmax (i,j)
@@ -110,15 +110,22 @@ function setindex!(A::SymmetricPacked, v, i::Int, j::Int)
110
110
return v
111
111
end
112
112
113
+ function setindex! (A:: SymmetricPacked{T,S,Val(:RO)} , v, i:: Int , j:: Int ) where {T,S}
114
+ i!= j && throw (ArgumentError (" Cannot set a non-diagonal index in a symmetric matrix" ))
115
+ _setindex! (A, v, i, j)
116
+ end
117
+
118
+ setindex! (A:: SymmetricPacked{T,S,Val(:RW)} , v, i:: Int , j:: Int ) where {T,S} = _setindex! (A, v, i, j)
119
+
113
120
function copy (A:: SymmetricPacked{T,S} ) where {T,S}
114
121
B = copy (A. tri)
115
122
SymmetricPacked {T,S} (B, A. n, A. uplo)
116
123
end
117
124
118
125
@inline function mul! (y:: StridedVector{T} ,
119
- AP:: SymmetricPacked{T,<:StridedMatrix} ,
126
+ AP:: SymmetricPacked{T,<:StridedMatrix,V } ,
120
127
x:: StridedVector{T} ,
121
- α:: Number , β:: Number ) where {T<: BlasFloat }
128
+ α:: Number , β:: Number ) where {T<: BlasFloat ,V }
122
129
alpha, beta = promote (α, β, zero (T))
123
130
if alpha isa Union{Bool,T} && beta isa Union{Bool,T}
124
131
BLAS. spmv! (AP. uplo, alpha, AP. tri, x, beta, y)
0 commit comments