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

Add support for complex numbers #117

Open
zoharl3 opened this issue Jun 3, 2020 · 4 comments
Open

Add support for complex numbers #117

zoharl3 opened this issue Jun 3, 2020 · 4 comments

Comments

@zoharl3
Copy link

zoharl3 commented Jun 3, 2020

Something like:

VectorXcd b;
b << 1, 2;
typedef Matrix<forward::Dual<complex<double>, complex<double>>, -1, 1, 0> VectorXcdual;
VectorXcdual f;
auto r = b.transpose() * f;
@allanleal
Copy link
Member

Hi @zoharl3 - sorry for the delay.

Have you tried instead using std::complex<dual>?

@zoharl3
Copy link
Author

zoharl3 commented Jun 11, 2020

Looks like it's working. Not sure if perfectly, e.g. I can assign (or multiply) VectorXd to (by) VectorXdual, but not VectorXcd to (by) VectorXcdual. Maybe it needs casting or something; but I'll look into it more closely when I need it. For now, I just used real implementation.

If you think that it works smoothly, then you may want to consider adding an example to the tutorial, which others may find useful.

@petar-andrejic
Copy link

It would be nice if rather than being distributed across a few tutorials and GitHub issues, that the complex support was folded into the library itself. As it stands I'm having a hard time getting it working properly. For example, using std::complex refuses to compile if the code uses derivative(...), while using Dual<std::complex, std::complex> like the tutorial suggests is also somewhat problematic. For example, it doesn't have real() or imag() methods like std::complex does, and things like Eigen want it to. Furthermore, some things seem to be hardcoded in a problematic way, for example, while almost every operator is made generic using UnaryExpr, for conj, real and imag the methods are hardcoded to return the number itself, and 0 respectively i.e. the Dual class will only work correctly for real types. As such, it seems that there need to be some fixes internally before complex numbers work properly

@allanleal
Copy link
Member

Hi @petar-andrejic , thanks for your investigation. As discussed in #297, if you work on that Pull Request, I'll be happy to merge.

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

No branches or pull requests

3 participants