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

example: custom numeric type #370

Draft
wants to merge 14 commits into
base: devel
Choose a base branch
from

Conversation

ofloveandhate
Copy link

This pull request is an example of building against EigenPy to expose Eigen objects with custom numeric types from C++. This is in response to #365.

This example at time of PR builds and installs, but not fully correctly. It doesn't install usable Python bindings, so the example Python code is not runnable. Maybe you could do that last step? So that the built bindings can actually be used in Python?

Copy link
Contributor

@jcarpent jcarpent left a comment

Choose a reason for hiding this comment

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

Thanks @ofloveandhate for the PR. I will make a pass on it when I have time in order to align it with the rest of the project. Is it fine for you?

@jcarpent jcarpent force-pushed the feature/example_custom_numeric_type branch from 765d4be to 284a5f8 Compare May 19, 2023 09:17
@jcarpent
Copy link
Contributor

TODO:

  • Remove useless files
  • SImplify cmake usage
  • Extend Python test with the creation of Numpy arrays used by a C++ program

@jcarpent jcarpent marked this pull request as draft May 19, 2023 09:22
@ofloveandhate
Copy link
Author

I tried to use the code in this PR, and it doesn't install correctly on my Mac. I observe the following issues:

  • I needed to change line 3 in CMakeLists.txt to cmake_minimum_required(VERSION 3.10)
  • The built library, when installed, has extension .dylib instead of .so
  • The build library's name starts with lib, but it needs to just start with the actual name of the library.
  • If imported, I get missing symbols:
import libeigenpy_example_custom_numeric_type

ImportError: dlopen(/usr/local/lib/libeigenpy_example_custom_numeric_type.so, 0x0002): symbol not found in flat namespace '_EIGENPY_ARRAY_API'

I think all of these are issues with the CMakeLists.txt file.

@ofloveandhate
Copy link
Author

I would love to be able to build upon this to work on some problems I'm seeing with custom numeric types in EigenPy, and make this example more complete, but I am finding the setup stuff is a barrier. Thanks!

@jcarpent jcarpent force-pushed the feature/example_custom_numeric_type branch from 284a5f8 to 6566e87 Compare December 12, 2023 14:41
ofloveandhate and others added 7 commits February 6, 2024 17:29
now makes a library without `lib` at front, and with `.so` at the end.  I was able to get this to compile and import using libraries installed via `conda`.
* brought in the real visitor from stack-of-tasks#365 (from which I had previously derived the complex visitor).
* provided the `real` and `imag` properties

the code could be cleaner, but now I can actually import the built library, make a complex, get its real/imag parts, do arithmetic, and use dot-tab completion in ipython without crashes.

(motivation: i'm working towards a MWE for the alignment issues I get in Bertini 2.  either I can replicate it using this code, in which case we can find the bug / whatever in eigenpy, or I fail, and I reveal the bug in MY code.)
`np.zeros()` crashes with my custom data type.

I also added a function that tries to modify an existing eigen array, through the eigenpy interface, but my python script doesn't get that far.
@ofloveandhate
Copy link
Author

I'm back for more help, and to help this example of using Eigenpy with a custom numeric type become fully functional.

I just added some code that makes EigenPy / the example library crash. I think my code is missing something simple. The failing code in Python is merely this:

import eigenpy_example_custom_numeric_type as example
import numpy as np

M = np.zeros((3,4),dtype=example.MpfrComplex)  # make an array of the custom numeric type

The problem is clearly uninitialized data, as per the assertion fail from MPC:

Assertion failed: (m_data[0].re[0]._mpfr_d), function data, file mpc.hpp, line 346.

(This is a step towards another problem I have with alignment)


I would love some help so that I can make arrays with my custom type in Numpy, and then feed them to C++ routines. I think this PR is a good place to do it, so that the resulting example code is contributed directly to EigenPy. (I am sorry it took me so long to follow up -- I switched jobs, moved continents, and am now in a full time research position 🥳)

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