@@ -119,29 +119,35 @@ end
119
119
120
120
Base. copy (D:: Diagonal{T, <:AbstractGPUArray{T, N}} ) where {T, N} = Diagonal (copy (D. diag))
121
121
122
+ _isrealandpositive (x) = isreal (x) && real (x) > 0
123
+
122
124
if VERSION <= v " 1.8-"
123
125
function LinearAlgebra. cholesky! (D:: Diagonal{<:Any, <:AbstractGPUArray} ,
124
126
:: Val{false} = Val (false ); check:: Bool = true )
125
- info = 0
126
- if mapreduce (x -> isreal (x) && isposdef (x), & , D . diag )
127
+ info = findfirst ( ! _isrealandpositive, D . diag)
128
+ if isnothing (info )
127
129
D. diag .= sqrt .(D. diag)
130
+ info = 0
131
+ elseif check
132
+ throw (PosDefException (info))
128
133
else
129
- info = findfirst (x -> ! isreal (x) || ! isposdef (x), collect (D. diag))
130
- check && throw (PosDefException (info))
134
+ D. diag[begin : info- 1 ] .= sqrt .(D. diag[begin : info- 1 ])
131
135
end
132
- Cholesky (D, ' U' , convert (LinearAlgebra. BlasInt, info))
136
+ return Cholesky (D, ' U' , convert (LinearAlgebra. BlasInt, info))
133
137
end
134
138
else
135
139
function LinearAlgebra. cholesky! (D:: Diagonal{<:Any, <:AbstractGPUArray} ,
136
140
:: NoPivot = NoPivot (); check:: Bool = true )
137
- info = 0
138
- if mapreduce (x -> isreal (x) && isposdef (x), & , D . diag )
141
+ info = findfirst ( ! _isrealandpositive, D . diag)
142
+ if isnothing (info )
139
143
D. diag .= sqrt .(D. diag)
144
+ info = 0
145
+ elseif check
146
+ throw (PosDefException (info))
140
147
else
141
- info = findfirst (x -> ! isreal (x) || ! isposdef (x), collect (D. diag))
142
- check && throw (PosDefException (info))
148
+ D. diag[begin : info- 1 ] .= sqrt .(D. diag[begin : info- 1 ])
143
149
end
144
- Cholesky (D, ' U' , convert (LinearAlgebra. BlasInt, info))
150
+ return Cholesky (D, ' U' , convert (LinearAlgebra. BlasInt, info))
145
151
end
146
152
end
147
153
0 commit comments