Skip to content
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

Added implementations of continous test functions #67

Merged
merged 7 commits into from
Nov 10, 2022

Conversation

Garion9
Copy link
Collaborator

@Garion9 Garion9 commented Nov 10, 2022

Description

Added implementations of continous test functions

Linked issues

closes #17

Copy link
Collaborator

@co012 co012 left a comment

Choose a reason for hiding this comment

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

LGTM, maybe next time import f64::consts::PI etc. and skip the namespace

src/test_functions/test_functions.rs Outdated Show resolved Hide resolved
src/test_functions/test_functions.rs Outdated Show resolved Hide resolved
Garion9 and others added 2 commits November 10, 2022 21:42
Co-authored-by: Kacper Ślusarczyk <co123@interia.eu>
Co-authored-by: Kacper Ślusarczyk <co123@interia.eu>
@Garion9 Garion9 merged commit 9e5ccc3 into master Nov 10, 2022
@Garion9 Garion9 deleted the test_functions_refactor branch November 10, 2022 20:47
Copy link
Collaborator

@kkafar kkafar left a comment

Choose a reason for hiding this comment

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

Good job 👍🏻
I've left some comments below, would be nice if they could be addressed in some followup PR.

@@ -0,0 +1 @@
pub mod test_functions;
Copy link
Collaborator

@kkafar kkafar Nov 11, 2022

Choose a reason for hiding this comment

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

Missing new line at the file end.
For some reason I do not have option to "suggest changes" (I don't see such button :D), so I'm just leaving descriptions.

Comment on lines +9 to +11
if x.len() < 1 {
panic!("Rastrigin function takes an at least one dimensional vector as a parameter.");
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be more clear to just use assert! macro here.
This can be applied to parameter validation you did in every of the implemented functions.

panic!("Rastrigin function takes an at least one dimensional vector as a parameter.");
}
let mut result: f64 = 0.0;
for x_curr in x.iter() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe using .iter() explicitly here is not necessary. Compiler will deduce this on its own.
This can be applied in few more places.

Comment on lines +465 to +473
let x1 = x[0];
let x2 = x[1];
let mut result: f64 = 0.0;
result += f64::sin(x1 + x2);
result += f64::powi(x1 - x2, 2);
result += -1.5 * x1;
result += 2.5 * x2;
result += 1.0;
return result;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe we can omit creating result variable completely here.

Comment on lines +452 to +454
let mut result: f64;
result = -1.0 * f64::abs(f64::sin(x1) * f64::cos(x2) * f64::exp(f64::abs(1.0 - f64::sqrt(f64::powi(x1, 2) + f64::powi(x2, 2)) / f64::consts::PI)));
return result;
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can omit creating result variable here, and in few more places.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Implement continuous benchmarking problems
4 participants