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

Using narray with C extension #202

Open
ghost opened this issue Jan 20, 2022 · 2 comments
Open

Using narray with C extension #202

ghost opened this issue Jan 20, 2022 · 2 comments

Comments

@ghost
Copy link

ghost commented Jan 20, 2022

Is it possible to use the custom data structure of numo-narray with my own C extension? Or do I have to re-implement some of the code again?

@kojix2
Copy link
Contributor

kojix2 commented Jan 22, 2022

I think this is a very important point.

Documentation on the internal structure of numo-narray is lacking, and I think it would be a hard task to create a C extension. I am not a C professional, so I cannot answer this issue directly. However, I can help a little by writing some helpful information.

Here are three notable people who have created a number of C extensions using numo-narray.I think their code is the best documentation currently available for creating C extensions with numo-narray.

@yoshoku mainly uses numo-narray as a machine learning library, but he has also created a library for reading and exporting images like magro. @ankane has created many famous libraries, and some of his gems use C++ and numo-narray for data processing. @Himeyama has recently uploaded a number of interesting C extension libraries to github that use numo-narray and CUDA.

I think reading their code is a shortcut to building C extensions.

(With the help of DeepL)

@kojix2
Copy link
Contributor

kojix2 commented Jan 22, 2022

For a more short answer, it is possible to use the numo-narray data structure in your own C extension.
Add the code to look for narray.h in extconf.rb, and then include it in your C source.

#include <numo/narray.h>

There are many ways to write extconf.rb to search narray.h, but ankane's is concise.

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

1 participant