Skip to content

Commit 4dfb3b0

Browse files
committed
mask_mean_dev: changes suggested by @certik
1 parent 625fad1 commit 4dfb3b0

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/tests/stats/test_mean.f90

+14-14
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ program test_mean
4444
call assert( any(isnan(mean(d, 2, .false.))))
4545

4646
! check mask of the same shape as input
47-
call assert( abs(mean(d, d > 0._dp) - sum(d, d > 0._dp)/real(count(d > 0._dp), dp)) < dptol)
48-
call assert( sum(abs(mean(d, 1, d > 0._dp) - sum(d, 1, d > 0._dp)/real(count(d > 0._dp, 1), dp))) < dptol)
49-
call assert( sum(abs(mean(d, 2, d > 0._dp) - sum(d, 2, d > 0._dp)/real(count(d > 0._dp, 2), dp))) < dptol)
47+
call assert( abs(mean(d, d > 0) - sum(d, d > 0)/real(count(d > 0), dp)) < dptol)
48+
call assert( sum(abs(mean(d, 1, d > 0) - sum(d, 1, d > 0)/real(count(d > 0, 1), dp))) < dptol)
49+
call assert( sum(abs(mean(d, 2, d > 0) - sum(d, 2, d > 0)/real(count(d > 0, 2), dp))) < dptol)
5050

5151
!int32
5252
call loadtxt("array3.dat", d)
@@ -67,8 +67,8 @@ program test_mean
6767
!dp rank 3
6868
allocate(d3(size(d,1),size(d,2),3))
6969
d3(:,:,1)=d;
70-
d3(:,:,2)=d*1.5_dp;
71-
d3(:,:,3)=d*4._dp;
70+
d3(:,:,2)=d*1.5;
71+
d3(:,:,3)=d*4;
7272

7373
call assert( abs(mean(d3) - sum(d3)/real(size(d3), dp)) < dptol)
7474
call assert( sum( abs( mean(d3,1) - sum(d3,1)/real(size(d3,1), dp) )) < dptol)
@@ -78,11 +78,11 @@ program test_mean
7878

7979
!dp rank 4
8080
allocate(d4(size(d,1),size(d,2),3,9))
81-
d4 = -1._dp
81+
d4 = -1
8282
d4(:,:,1,1)=d;
83-
d4(:,:,2,1)=d*1.5_dp;
84-
d4(:,:,3,1)=d*4._dp;
85-
d4(:,:,3,9)=d*4._dp;
83+
d4(:,:,2,1)=d*1.5;
84+
d4(:,:,3,1)=d*4;
85+
d4(:,:,3,9)=d*4;
8686

8787
call assert( abs(mean(d4) - sum(d4)/real(size(d4), dp)) < dptol)
8888
call assert( sum( abs( mean(d4,1) - sum(d4,1)/real(size(d4,1), dp) )) < dptol)
@@ -100,10 +100,10 @@ program test_mean
100100

101101

102102
! check mask of the same shape as input
103-
call assert( abs(mean(d4, d4 > 0._dp) - sum(d4, d4 > 0._dp)/real(count(d4 > 0._dp), dp)) < dptol)
104-
call assert( any(isnan(mean(d4, 1, d4 > 0._dp))) )
105-
call assert( any(isnan(mean(d4, 2, d4 > 0._dp))) )
106-
call assert( any(isnan(mean(d4, 3, d4 > 0._dp))) )
107-
call assert( sum(abs(mean(d4, 4, d4 > 0._dp) - sum(d4, 4, d4 > 0._dp)/real(count(d4 > 0._dp, 4), dp))) < dptol)
103+
call assert( abs(mean(d4, d4 > 0) - sum(d4, d4 > 0)/real(count(d4 > 0), dp)) < dptol)
104+
call assert( any(isnan(mean(d4, 1, d4 > 0))) )
105+
call assert( any(isnan(mean(d4, 2, d4 > 0))) )
106+
call assert( any(isnan(mean(d4, 3, d4 > 0))) )
107+
call assert( sum(abs(mean(d4, 4, d4 > 0) - sum(d4, 4, d4 > 0)/real(count(d4 > 0, 4), dp))) < dptol)
108108

109109
end program

0 commit comments

Comments
 (0)