Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: copy_a deallocation in determinant #815

Merged
merged 2 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading