Skip to content

Added support and test for mean of complex arrays #140

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

Merged
merged 4 commits into from
Feb 5, 2020

Conversation

fiolj
Copy link
Contributor

@fiolj fiolj commented Feb 4, 2020

Added support and tests for complex types.
I changed the names of the specific functions, following the convention used in optval.

@fiolj fiolj requested review from jvdp1 and aradi February 4, 2020 14:06
Copy link
Member

@jvdp1 jvdp1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @fiolj for adding complex numbers to this function. I also like the idea of macros for the names of the functions. I have some questions/suggestions regarding those.

Comment on lines 34 to 50
call assert( sum( abs( mean(d8,7) - sum(d8,7)/real(size(d8,7), dp) )) == 0.0_dp)
call assert( sum( abs( mean(d8,8) - sum(d8,8)/real(size(d8,8), dp) )) == 0.0_dp)

!cdp rank 8
allocate(cd8(size(d,1), size(d,2), 3, 4, 5, 6, 7, 8))
cd8 = cmplx(1._dp, 1._dp, kind=dp)*d8

call assert( mean(cd8) - sum(cd8)/real(size(cd8), dp) == 0.0_dp)

call assert( sum( abs( mean(cd8,1) - sum(cd8,1)/real(size(cd8,1), dp) )) == 0.0_dp)
call assert( sum( abs( mean(cd8,2) - sum(cd8,2)/real(size(cd8,2), dp) )) == 0.0_dp)
call assert( sum( abs( mean(cd8,3) - sum(cd8,3)/real(size(cd8,3), dp) )) == 0.0_dp)
call assert( sum( abs( mean(cd8,4) - sum(cd8,4)/real(size(cd8,4), dp) )) == 0.0_dp)
call assert( sum( abs( mean(cd8,5) - sum(cd8,5)/real(size(cd8,5), dp) )) == 0.0_dp)
call assert( sum( abs( mean(cd8,6) - sum(cd8,6)/real(size(cd8,6), dp) )) == 0.0_dp)
call assert( sum( abs( mean(cd8,7) - sum(cd8,7)/real(size(cd8,7), dp) )) == 0.0_dp)
call assert( sum( abs( mean(cd8,8) - sum(cd8,8)/real(size(cd8,8), dp) )) == 0.0_dp)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that the == 0.0_dp have not been changed to < dptol as in test_mean.f90. Could you do it, please?

Comment on lines 13 to 15
#:def name(Rank, Type, Kind)
$:"mean_{0}_all_{1}{2}_{1}{2}".format(Rank, Type[0], Kind)
#:enddef
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like idea to use a preprocessing macro for the names of functions, especially if we will other functions with the same API (e.g., variance, median,...)

So, to make these macros more general, would it be possible to pass the name of the function, e.g.,:
#:def name(Varname, Rank, Type, Kind)
where Varname would be equal to mean, variance, median,....?

Also, would it be possible to add these macros in common.fypp, since these will be used for other functions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I'll do. I started that way but because the original routine names were complex, I decided for hard-code the names in order not to change too much the code. I'll amend and send a new request.

Also @jvdp1, could we make the functions pure? (I've not used much of submodules before, so I don't know if there is restrictions there)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functions in the submodule can be pure. However, it seems that the minimum required CMake does not support that (I am not sure if the last version of CMake supports it either; @zbeekma @certik @milancurcic ?).
Also the checks on the dimensions inside the functions may prohibit pure for some of them.

@fiolj
Copy link
Contributor Author

fiolj commented Feb 4, 2020

Ok, @jvdp1 @aradi What do you think of using a macro for names like the following?

#:def rname(gname, rank, type, kind, suffix='')
  $:"{0}_{1}_{2}{3}_{2}{3}".format(gname, rank, type[0], kind) if suffix == '' else "{0}_{1}_{2}{3}_{4}".format(gname, rank, type[0], kind, suffix)
#:enddef

Assuming that t1='real', k1='sp', rank=1,
${rname("mean_all",rank, t1, k1)}$
will give:
mean_all_1_rsp_rsp

Copy link
Member

@certik certik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks good to me.

Copy link
Member

@jvdp1 jvdp1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pending my minor comment, I think these changes are good. Having the macro in common.fypp clarifies the other .fypp files. Thank you.

@fiolj
Copy link
Contributor Author

fiolj commented Feb 4, 2020 via email

@jvdp1
Copy link
Member

jvdp1 commented Feb 4, 2020

I was getting an error for complex numbers. I am not sure but it seems that it is not defined for complex numbers.

It seems that you are right: it is not defined for complex (at least in gfortran)

So it can be merged from my side.

@certik
Copy link
Member

certik commented Feb 5, 2020

I resolved conflicts and tests seem to pass. We got two approvals, so I am going to merge it now.

@certik certik merged commit 71c30d1 into fortran-lang:master Feb 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants