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

Matrix multiplication instead of element-wise multiplication in raw_to_polyvector #69

Open
segaviv opened this issue Dec 18, 2023 · 3 comments
Assignees
Labels

Comments

@segaviv
Copy link

segaviv commented Dec 18, 2023

Hi,

In raw_to_polyvector with sign symmetry, I think that line 41 does a matrix multiplication that fails an assertion in Debug due to incompatible dimensions and leads to some undefined behavior in a Release build.

I think the line can be changed to something like actualRoots = actualRoots.array().square() to calculate the element-wise square of the roots (if I understand the logic correctly...).

Thanks in advance for looking into it,
Aviv

@segaviv
Copy link
Author

segaviv commented Dec 19, 2023

I think that there might also be an issue with the calculation of the polyvector coefficients later in this function:

  1. I think that the "root polynomials" should be initialized to -actualRoots.col(i) (since they correspond to (z - u_i)) instead of actualRoots.col(i) in lines 52 & 54.

  2. I think the code for multiplying polynomials doesn't consider the biggets power of the polynomials (which is omitted from the representation since the coefficients is always 1).
    I think adding something like:

for (int i =0; i < p1.cols(); i++) {
newp.col(i + p2.cols()) += p1.col(i);
}
for (int i =0; i < p2.cols(); i++) {
newp.col(i + p1.cols()) += p2.col(i);
}

after the nested loop here could solve it.

@avaxman avaxman self-assigned this Dec 24, 2023
@avaxman avaxman added the bug label Dec 24, 2023
@avaxman
Copy link
Owner

avaxman commented Dec 24, 2023

Yep both comments are true, thanks. It currently doesn't reproduce a polyvector_to_raw(raw_to_polyvector()) test.

Honestly, I don't think this function is actually being used within Directional tutorial. I think I translated it from another project, but I see the code there is very different from this one, so I might have stopped before finishing the entire work. It also doesn't have the new Directional class wrapper of directional::CartesianField like polyvector_to_raw() does, so I'm guessing I just haven't been there yet.

Do you want to try and fix it and submit a pull request? should test the above polyvector_to_raw(raw_to_polyvector()) to see it's an identity (up to small numerics).

@segaviv
Copy link
Author

segaviv commented Dec 26, 2023

Yes, I'll be glad to suggest a fix.
I'll prepare a fix with the test you suggested and submit a pull request.

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

No branches or pull requests

2 participants