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

Adding support for faer #12

Merged
merged 28 commits into from
Mar 28, 2024
Merged

Adding support for faer #12

merged 28 commits into from
Mar 28, 2024

Conversation

Siel
Copy link
Contributor

@Siel Siel commented Mar 26, 2024

This PR aims to add support for faer into diffsol.

To do this I created a Scale structure to be used as an interface between nalgebra and faer when working with scalar operations.

I replaced all the scalar operations to use Scale and implemented all the traits needed to have it to work with nalgebra.

All tests are passing.

The faer traits are still under development but the initial integration is already in place. All the faer integration code is commented to guarantee that the package compiles. My plan is to put the respective implementations behind their specific faer and nalgebra features.

Copy link
Owner

@martinjrobins martinjrobins left a comment

Choose a reason for hiding this comment

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

thanks for adding this @Siel, really great work! I've made a few suggestions/questions below.

@Siel
Copy link
Contributor Author

Siel commented Mar 27, 2024

I think I made al the changes requested.

@Siel
Copy link
Contributor Author

Siel commented Mar 27, 2024

I did rebase the branch to include the current changes on main

Copy link
Owner

@martinjrobins martinjrobins left a comment

Choose a reason for hiding this comment

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

Thanks @Siel! few more minor points below

}

//TODO: Not sure why it is now working
// impl<'a, E, V> Mul<Scale<E>> for V
Copy link
Owner

Choose a reason for hiding this comment

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

this comment can be removed now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll give it a shot at implementing the other side of Mul tomorrow. After that I'll remove that comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nop, I wanted to allow Scale to be on the Lhs of * but I was not able to. I might revisit this later.

Copy link
Owner

Choose a reason for hiding this comment

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

ok, for now just create an issue for this as a reminder

}
}

impl<'a, T: Scalar> Div<crate::scalar::Scale<T>> for faer::Col<f64> {
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
impl<'a, T: Scalar> Div<crate::scalar::Scale<T>> for faer::Col<f64> {
impl<'a, T: Scalar> Div<Scale<T>> for faer::Col<f64> {


impl<'a, T: Scalar> Div<crate::scalar::Scale<T>> for faer::Col<f64> {
type Output = faer::Col<f64>;
fn div(self, rhs: crate::scalar::Scale<T>) -> Self::Output {
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
fn div(self, rhs: crate::scalar::Scale<T>) -> Self::Output {
fn div(self, rhs: Scale<T>) -> Self::Output {

use super::{Vector, VectorCommon, VectorIndex, VectorView, VectorViewMut};
impl<'a, T: Scalar> Mul<Scale<T>> for ColRef<'a, f64> {
type Output = Col<f64>;
fn mul(self, rhs: Scale<T>) -> Self::Output {
Copy link
Owner

Choose a reason for hiding this comment

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

these three mul's can be combined into a single macro

Copy link
Owner

Choose a reason for hiding this comment

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

and the div below

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think only the two first Mul's can be combined here. The third one is not expecting a lifetime. and for the Div one the function implementation is too different, I should be able to pass an anonymous function to the macro but that seems too convoluted, no?

Copy link
Owner

Choose a reason for hiding this comment

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

ok, I don't want to make it too convoluted, so feel free to leave as is

}
impl<'a, T: Scalar> MulAssign<Scale<T>> for ColMut<'a, f64> {
fn mul_assign(&mut self, rhs: Scale<T>) {
let scale = faer::scale(rhs.value().into());
Copy link
Owner

Choose a reason for hiding this comment

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

same with the mul_assigns. Do the two bodies need to be different?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They have to, since faer implements the multiplication for some types and not for others

self * rhs
}
}
impl<'a, T: Scalar> Mul<Scale<T>> for DVectorView<'a, T> {
Copy link
Owner

Choose a reason for hiding this comment

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

same with faer_serial, use macros to reduce the repeated code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The same here, I managed to create one macro, the other functions are different enough.

Copy link
Owner

Choose a reason for hiding this comment

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

ok, if a macro doesn't work here then don't worry about it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I might be able to create a more generic macro but it will take me some more time, I'll create a reminder to come back here later. I want to implement Matrix first

Copy link
Owner

@martinjrobins martinjrobins left a comment

Choose a reason for hiding this comment

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

looks good now. Assuming tests pass did you want me to merge this in before you start on the faer matrix?

@Siel
Copy link
Contributor Author

Siel commented Mar 28, 2024

looks good now. Assuming tests pass did you want me to merge this in before you start on the faer matrix?

I'd like so, if other people is going to work on different parts of the library would be better to have the Scale struct on the main branch so rebasing does not become a nightmare

@martinjrobins martinjrobins merged commit 40904d6 into martinjrobins:main Mar 28, 2024
6 checks passed
@martinjrobins martinjrobins deleted the faer branch March 28, 2024 13:53
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.

2 participants