@@ -130,14 +130,14 @@ function bidiagzero(A::Bidiagonal{<:AbstractMatrix}, i, j)
130
130
end
131
131
end
132
132
133
+ _offdiagind (uplo) = uplo == ' U' ? 1 : - 1
134
+
133
135
@inline function Base. isassigned (A:: Bidiagonal , i:: Int , j:: Int )
134
136
@boundscheck checkbounds (Bool, A, i, j) || return false
135
137
if i == j
136
138
return @inbounds isassigned (A. dv, i)
137
- elseif A. uplo == ' U' && (i == j - 1 )
138
- return @inbounds isassigned (A. ev, i)
139
- elseif A. uplo == ' L' && (i == j + 1 )
140
- return @inbounds isassigned (A. ev, j)
139
+ elseif i == j - _offdiagind (A. uplo)
140
+ return @inbounds isassigned (A. ev, A. uplo == ' U' ? i : j)
141
141
else
142
142
return true
143
143
end
147
147
@boundscheck checkbounds (A, i, j)
148
148
if i == j
149
149
return @inbounds Base. isstored (A. dv, i)
150
- elseif A. uplo == ' U' && (i == j - 1 )
151
- return @inbounds Base. isstored (A. ev, i)
152
- elseif A. uplo == ' L' && (i == j + 1 )
153
- return @inbounds Base. isstored (A. ev, j)
150
+ elseif i == j - _offdiagind (A. uplo)
151
+ return @inbounds Base. isstored (A. ev, A. uplo == ' U' ? i : j)
154
152
else
155
153
return false
156
154
end
160
158
@boundscheck checkbounds (A, i, j)
161
159
if i == j
162
160
return @inbounds A. dv[i]
163
- elseif A. uplo == ' U' && (i == j - 1 )
164
- return @inbounds A. ev[i]
165
- elseif A. uplo == ' L' && (i == j + 1 )
166
- return @inbounds A. ev[j]
161
+ elseif i == j - _offdiagind (A. uplo)
162
+ return @inbounds A. ev[A. uplo == ' U' ? i : j]
167
163
else
168
164
return bidiagzero (A, i, j)
169
165
end
173
169
@boundscheck checkbounds (A, _cartinds (b))
174
170
if b. band == 0
175
171
return @inbounds A. dv[b. index]
176
- elseif A. uplo == ' U' && b. band == 1
177
- return @inbounds A. ev[b. index]
178
- elseif A. uplo == ' L' && b. band == - 1
172
+ elseif b. band == _offdiagind (A. uplo)
179
173
return @inbounds A. ev[b. index]
180
174
else
181
175
return bidiagzero (A, Tuple (_cartinds (b))... )
186
180
@boundscheck checkbounds (A, i, j)
187
181
if i == j
188
182
@inbounds A. dv[i] = x
189
- elseif A. uplo == ' U' && (i == j - 1 )
190
- @inbounds A. ev[i] = x
191
- elseif A. uplo == ' L' && (i == j + 1 )
192
- @inbounds A. ev[j] = x
183
+ elseif i == j - _offdiagind (A. uplo)
184
+ @inbounds A. ev[A. uplo == ' U' ? i : j] = x
193
185
elseif ! iszero (x)
194
186
throw (ArgumentError (LazyString (lazy " cannot set entry ($i, $j) off the " ,
195
187
istriu (A) ? " upper" : " lower" , " bidiagonal band to a nonzero value " , x)))
@@ -202,11 +194,7 @@ Base._reverse(A::Bidiagonal, ::Colon) = Bidiagonal(reverse(A.dv), reverse(A.ev),
202
194
203
195
# # structured matrix methods ##
204
196
function Base. replace_in_print_matrix (A:: Bidiagonal ,i:: Integer ,j:: Integer ,s:: AbstractString )
205
- if A. uplo == ' U'
206
- i== j || i== j- 1 ? s : Base. replace_with_centered_mark (s)
207
- else
208
- i== j || i== j+ 1 ? s : Base. replace_with_centered_mark (s)
209
- end
197
+ i== j || i== j- _offdiagind (A. uplo) ? s : Base. replace_with_centered_mark (s)
210
198
end
211
199
212
200
# Converting from Bidiagonal to dense Matrix
@@ -215,7 +203,7 @@ function Matrix{T}(A::Bidiagonal) where T
215
203
if haszero (T) # optimized path for types with zero(T) defined
216
204
size (B,1 ) > 1 && fill! (B, zero (T))
217
205
copyto! (view (B, diagind (B)), A. dv)
218
- copyto! (view (B, diagind (B, A. uplo == ' U ' ? 1 : - 1 )), A. ev)
206
+ copyto! (view (B, diagind (B, _offdiagind ( A. uplo) )), A. ev)
219
207
else
220
208
copyto! (B, A)
221
209
end
@@ -558,7 +546,7 @@ _diag(A::SymTridiagonal, k) = k == 0 ? A.dv : A.ev
558
546
function _diag (A:: Bidiagonal , k)
559
547
if k == 0
560
548
return A. dv
561
- elseif (A . uplo == ' L ' && k == - 1 ) || (A. uplo == ' U ' && k == 1 )
549
+ elseif k == _offdiagind (A. uplo)
562
550
return A. ev
563
551
else
564
552
return diag (A, k)
0 commit comments