Skip to content

Commit

Permalink
Fix: copy_a deallocation in determinant (#815)
Browse files Browse the repository at this point in the history
  • Loading branch information
perazz authored May 16, 2024
2 parents 206f84a + 32f9a24 commit 42182b0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/stdlib_linalg_determinant.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ submodule (stdlib_linalg) stdlib_linalg_determinant
err0 = linalg_state_type(this,LINALG_INTERNAL_ERROR,'catastrophic error')
end select

if (.not.copy_a) deallocate(amat)
if (copy_a) deallocate(amat)

end select

Expand Down
13 changes: 12 additions & 1 deletion test/linalg/test_linalg_determinant.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ module test_linalg_determinant
integer(ilp), parameter :: n = 128_ilp

${rt}$ :: a(n,n),deta
${rt}$, allocatable :: aalloc(:,:)

a = eye(n)

Expand All @@ -55,8 +56,18 @@ module test_linalg_determinant

call check(error,state%ok(),state%print())
if (allocated(error)) return

call check(error, abs(deta-1.0_${rk}$)<epsilon(0.0_${rk}$), 'det(eye(n))==1')
if (allocated(error)) return

!> Test with allocatable matrix
aalloc = eye(n)
deta = det(aalloc,overwrite_a=.false.,err=state)
call check(error,state%ok(),state%print()//' (allocatable a)')
if (allocated(error)) return
call check(error,allocated(aalloc),'a is still allocated')
if (allocated(error)) return
call check(error, abs(deta-1.0_${rk}$)<epsilon(0.0_${rk}$), 'det(eye(n))==1 (allocatable a))')
if (allocated(error)) return

end subroutine test_${rt[0]}$${rk}$_eye_determinant

Expand Down

0 comments on commit 42182b0

Please sign in to comment.