Skip to content

Commit f5e185b

Browse files
committed
update
1 parent 9afb581 commit f5e185b

2 files changed

Lines changed: 24 additions & 6 deletions

File tree

src/specialmatrices/stdlib_specialmatrices_tridiagonal.fypp

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -286,14 +286,16 @@ submodule (stdlib_specialmatrices) tridiagonal_matrices
286286
${t1}$, intent(in) :: alpha
287287
type(tridiagonal_${s1}$_type), intent(in) :: A
288288
type(tridiagonal_${s1}$_type) :: B
289-
B = tridiagonal(alpha*A%dl, alpha*A%dv, alpha*A%du)
289+
B = tridiagonal(A%dl, A%dv, A%du)
290+
B%dl = alpha*B%dl; B%dv = alpha*B%dv; B%du = alpha*B%du
290291
end function
291292

292293
pure module function scalar_multiplication_bis_tridiagonal_${s1}$(A, alpha) result(B)
293294
type(tridiagonal_${s1}$_type), intent(in) :: A
294295
${t1}$, intent(in) :: alpha
295296
type(tridiagonal_${s1}$_type) :: B
296-
B = tridiagonal(alpha*A%dl, alpha*A%dv, alpha*A%du)
297+
B = tridiagonal(A%dl, A%dv, A%du)
298+
B%dl = alpha*B%dl; B%dv = alpha*B%dv; B%du = alpha*B%du
297299
end function
298300
#:endfor
299301

@@ -303,19 +305,33 @@ submodule (stdlib_specialmatrices) tridiagonal_matrices
303305
type(tridiagonal_${s1}$_type), intent(in) :: B
304306
type(tridiagonal_${s1}$_type) :: C
305307

306-
if (A%n /= B%n) error stop "ValueError: tridiagonal matrices must have the same dimension to be added"
308+
! Internal variables.
309+
type(linalg_state_type) :: err0
310+
311+
if (A%n /= B%n) then
312+
err0 = linalg_state_type(this, LINALG_VALUE_ERROR, "tridiagonal matrices must have the same dimension to be added")
313+
call linalg_error_handling(err0)
314+
end if
307315

308-
C = tridiagonal(A%dl + B%dl, A%dv + B%dv, A%du + B%du)
316+
C = tridiagonal(A%dl, A%dv, A%du)
317+
C%dl = C%dl + B%dl; C%dv = C%dv + B%dv; C%du = C%du + B%du
309318
end function
310319

311320
pure module function matrix_sub_tridiagonal_${s1}$(A, B) result(C)
312321
type(tridiagonal_${s1}$_type), intent(in) :: A
313322
type(tridiagonal_${s1}$_type), intent(in) :: B
314323
type(tridiagonal_${s1}$_type) :: C
315324

316-
if (A%n /= B%n) error stop "ValueError: tridiagonal matrices must have the same dimension to be subtracted"
325+
! Internal variables.
326+
type(linalg_state_type) :: err0
327+
328+
if (A%n /= B%n) then
329+
err0 = linalg_state_type(this, LINALG_VALUE_ERROR, "tridiagonal matrices must have the same dimension to be subtracted")
330+
call linalg_error_handling(err0)
331+
end if
317332

318-
C = tridiagonal(A%dl - B%dl, A%dv - B%dv, A%du - B%du)
333+
C = tridiagonal(A%dl, A%dv, A%du)
334+
C%dl = C%dl - B%dl; C%dv = C%dv - B%dv; C%du = C%du - B%du
319335
end function
320336
#:endfor
321337

test/linalg/test_linalg_specialmatrices.fypp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ contains
165165
! Check if it compiled and converted properly without segfaulting
166166
call check(error, size(Amat, 1) == 1, .true.)
167167
if (allocated(error)) return
168+
call check(error, size(Amat, 2) == 1, .true.)
169+
if (allocated(error)) return
168170
call check(error, is_close(Amat(1,1), 5.0_wp), .true.)
169171
if (allocated(error)) return
170172
end block

0 commit comments

Comments
 (0)