Skip to content

Commit 42182b0

Browse files
authored
Fix: copy_a deallocation in determinant (#815)
2 parents 206f84a + 32f9a24 commit 42182b0

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/stdlib_linalg_determinant.fypp

+1-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ submodule (stdlib_linalg) stdlib_linalg_determinant
224224
err0 = linalg_state_type(this,LINALG_INTERNAL_ERROR,'catastrophic error')
225225
end select
226226

227-
if (.not.copy_a) deallocate(amat)
227+
if (copy_a) deallocate(amat)
228228

229229
end select
230230

test/linalg/test_linalg_determinant.fypp

+12-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ module test_linalg_determinant
4747
integer(ilp), parameter :: n = 128_ilp
4848

4949
${rt}$ :: a(n,n),deta
50+
${rt}$, allocatable :: aalloc(:,:)
5051

5152
a = eye(n)
5253

@@ -55,8 +56,18 @@ module test_linalg_determinant
5556

5657
call check(error,state%ok(),state%print())
5758
if (allocated(error)) return
58-
5959
call check(error, abs(deta-1.0_${rk}$)<epsilon(0.0_${rk}$), 'det(eye(n))==1')
60+
if (allocated(error)) return
61+
62+
!> Test with allocatable matrix
63+
aalloc = eye(n)
64+
deta = det(aalloc,overwrite_a=.false.,err=state)
65+
call check(error,state%ok(),state%print()//' (allocatable a)')
66+
if (allocated(error)) return
67+
call check(error,allocated(aalloc),'a is still allocated')
68+
if (allocated(error)) return
69+
call check(error, abs(deta-1.0_${rk}$)<epsilon(0.0_${rk}$), 'det(eye(n))==1 (allocatable a))')
70+
if (allocated(error)) return
6071

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

0 commit comments

Comments
 (0)