Skip to content

Commit 79facfd

Browse files
committed
corr: correction for dot_product complex
1 parent c50faef commit 79facfd

File tree

2 files changed

+55
-6
lines changed

2 files changed

+55
-6
lines changed

src/stdlib_experimental_stats_corr.fypp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ contains
243243
#:endif
244244
mask_)
245245

246-
res(j, i) = dot_product( centerj_, centeri_)&
246+
res(j, i) = dot_product( centeri_, centerj_)&
247247
/sqrt(dot_product( centeri_, centeri_)*&
248248
dot_product( centerj_, centerj_))
249249
end do
@@ -295,7 +295,7 @@ contains
295295
centerj_ = merge( x(j, :) - mean(x(j, :), mask = mask_),&
296296
0._dp, mask_)
297297

298-
res(j, i) = dot_product( centerj_, centeri_)&
298+
res(j, i) = dot_product( centeri_, centerj_)&
299299
/sqrt(dot_product( centeri_, centeri_)*&
300300
dot_product( centerj_, centerj_))
301301
end do

src/tests/stats/test_corr.f90

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,15 @@ subroutine test_sp(x, x2)
9292
) < sptol)&
9393
, 'sp check 12')
9494

95+
96+
call check( all(abs(corr(x2, 1, mask = x2 < 1000) - corr(x2, 1))&
97+
< sptol)&
98+
, 'sp check 13')
99+
100+
call check( all(abs(corr(x2, 2, mask = x2 < 1000) - corr(x2, 2))&
101+
< sptol)&
102+
, 'sp check 14')
103+
95104
end subroutine test_sp
96105

97106
subroutine test_dp(x, x2)
@@ -145,6 +154,14 @@ subroutine test_dp(x, x2)
145154
) < dptol)&
146155
, 'dp check 12')
147156

157+
call check( all(abs(corr(x2, 1, mask = x2 < 1000) - corr(x2, 1))&
158+
< dptol)&
159+
, 'dp check 13')
160+
161+
call check( all(abs(corr(x2, 2, mask = x2 < 1000) - corr(x2, 2))&
162+
< dptol)&
163+
, 'dp check 14')
164+
148165
end subroutine test_dp
149166

150167
subroutine test_int32(x, x2)
@@ -198,6 +215,14 @@ subroutine test_int32(x, x2)
198215
) < dptol)&
199216
, 'int32 check 12')
200217

218+
call check( all(abs(corr(x2, 1, mask = x2 < 1000) - corr(x2, 1))&
219+
< dptol)&
220+
, 'int32 check 13')
221+
222+
call check( all(abs(corr(x2, 2, mask = x2 < 1000) - corr(x2, 2))&
223+
< dptol)&
224+
, 'int32 check 14')
225+
201226
end subroutine test_int32
202227

203228
subroutine test_int64(x, x2)
@@ -251,6 +276,14 @@ subroutine test_int64(x, x2)
251276
) < dptol)&
252277
, 'int64 check 12')
253278

279+
call check( all(abs(corr(x2, 1, mask = x2 < 1000) - corr(x2, 1))&
280+
< dptol)&
281+
, 'int64 check 13')
282+
283+
call check( all(abs(corr(x2, 2, mask = x2 < 1000) - corr(x2, 2))&
284+
< dptol)&
285+
, 'int64 check 14')
286+
254287
end subroutine test_int64
255288

256289
subroutine test_csp(x, x2)
@@ -286,12 +319,20 @@ subroutine test_csp(x, x2)
286319
, 'csp check 7')
287320

288321
call check( all( abs( corr(x2, 2, mask = aimag(x2) < 6) - reshape([&
289-
(1._sp,0._sp), (0._sp,-1._sp)&
290-
,(0._sp,1._sp), (1._sp,0._sp)]&
322+
(1._sp,0._sp), (0._sp,1._sp)&
323+
,(0._sp,-1._sp), (1._sp,0._sp)]&
291324
,[ size(x2, 1), size(x2, 1)])&
292325
) < sptol)&
293326
, 'csp check 8')
294327

328+
call check( all(abs(corr(x2, 1, mask = aimag(x2) < 1000) - corr(x2, 1))&
329+
< sptol)&
330+
, 'csp check 9')
331+
332+
call check( all(abs(corr(x2, 2, mask = aimag(x2) < 1000) - corr(x2, 2))&
333+
< sptol)&
334+
, 'csp check 10')
335+
295336
end subroutine test_csp
296337

297338
subroutine test_cdp(x, x2)
@@ -327,12 +368,20 @@ subroutine test_cdp(x, x2)
327368
, 'cdp check 7')
328369

329370
call check( all( abs( corr(x2, 2, mask = aimag(x2) < 6) - reshape([&
330-
(1._dp,0._dp), (0._dp,-1._dp)&
331-
,(0._dp,1._dp), (1._dp,0._dp)]&
371+
(1._dp,0._dp), (0._dp,1._dp)&
372+
,(0._dp,-1._dp), (1._dp,0._dp)]&
332373
,[ size(x2, 1), size(x2, 1)])&
333374
) < dptol)&
334375
, 'cdp check 8')
335376

377+
call check( all(abs(corr(x2, 1, mask = aimag(x2) < 1000) - corr(x2, 1))&
378+
< sptol)&
379+
, 'csp check 9')
380+
381+
call check( all(abs(corr(x2, 2, mask = aimag(x2) < 1000) - corr(x2, 2))&
382+
< sptol)&
383+
, 'csp check 10')
384+
336385
end subroutine test_cdp
337386

338387
end program test_corr

0 commit comments

Comments
 (0)