Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upFix implementation of fonesca fleming problem function f1 and f2 type usage and negative signs. #223
Conversation
- Improves the mathematical description of the problem - Fixes the implementation of f1 and f2 - Ensure use of `pow()` and `sqrt()` return double
| - pow(coords[1] - 1.0f / sqrt(3), 2) | ||
| - pow(coords[2] - 1.0f / sqrt(3), 2)); | ||
| return 1.0 - exp( | ||
| -pow(static_cast<double>(coords[0]) - 1.0 / sqrt(3.0), 2.0) |
zoq
Aug 27, 2020
Member
Looking at the error message: ‘sqrt(int)’ is ambiguous I think the static_cast is not necessary?
Looking at the error message: ‘sqrt(int)’ is ambiguous I think the static_cast is not necessary?
coatless
Aug 27, 2020
Author
Contributor
It's probably overkill, I can remove if need be.
It's probably overkill, I can remove if need be.
rcurtin
Aug 27, 2020
Member
We don't actually know what coords[0] is, so I might suggest using MatType::elem_type maybe like this:
typedef MatType::elem_type T;
return T(1) - exp(-pow(coords[0] - T(1) / sqrt(T(3)), T(2))
- pow(coords[1] - T(1) / sqrt(T(3)), T(2))
- pow(coords[2] - T(1) / sqrt(T(3)), T(2)));
Or, something like that could work. Basically the idea is to force every internal type inside the expression to be the same as MatType::elem_type.
We don't actually know what coords[0] is, so I might suggest using MatType::elem_type maybe like this:
typedef MatType::elem_type T;
return T(1) - exp(-pow(coords[0] - T(1) / sqrt(T(3)), T(2))
- pow(coords[1] - T(1) / sqrt(T(3)), T(2))
- pow(coords[2] - T(1) / sqrt(T(3)), T(2)));
Or, something like that could work. Basically the idea is to force every internal type inside the expression to be the same as MatType::elem_type.
coatless
Aug 27, 2020
Author
Contributor
@rcurtin I agree with a type cast. That said, we input into pow() and sqrt() may be either float, double, or long double per their function definitions.
So, MatType::elem_type includes unsigned int and int.
short
long
mat
=
Mat<double>
dmat
=
Mat<double>
fmat
=
Mat<float>
cx_mat
=
Mat<cx_double>
cx_dmat
=
Mat<cx_double>
cx_fmat
=
Mat<cx_float>
umat
=
Mat<uword>
imat
=
Mat<sword>
@rcurtin I agree with a type cast. That said, we input into pow() and sqrt() may be either float, double, or long double per their function definitions.
So, MatType::elem_type includes unsigned int and int.
| short | long | |
|---|---|---|
| mat | = | Mat<double> |
| dmat | = | Mat<double> |
| fmat | = | Mat<float> |
| cx_mat | = | Mat<cx_double> |
| cx_dmat | = | Mat<cx_double> |
| cx_fmat | = | Mat<cx_float> |
| umat | = | Mat<uword> |
| imat | = | Mat<sword> |
rcurtin
Aug 27, 2020
Member
Ah, good point! In this case, I'd be fine forcing to double like you suggested.
Ah, good point! In this case, I'd be fine forcing to double like you suggested.
|
Ready from my side, thanks. |
|
Second approval provided automatically after 24 hours. |
|
@rcurtin after updating my fork, I'm getting: (base) ➜ ensmallen git:(master) ./scripts/ensmallen-release.sh coatless 2 14 2
git diff returned a nonzero result! |
|
Hmm, is it a pristine copy of |
|
Thank you for helping play with this script, by the way. The more people use it, the more robust it gets. :) |
|
@coatless I just went ahead and ran the script. I think in a future release I'll document that |
|
@rcurtin sorry for the delay, start of new semester. RE: |
Fixes the type issues that came up during a CRAN check submission on Solaris.
https://www.r-project.org/nosvn/R.check/r-patched-solaris-x86/RcppEnsmallen-00install.html
Also, removes an extra negative sign between x1 and x2 addition.