numo-narray icon indicating copy to clipboard operation
numo-narray copied to clipboard

Using narray with C extension

Open ghost opened this issue 2 years ago • 2 comments

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?

ghost avatar Jan 20 '22 16:01 ghost

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 avatar Jan 22 '22 00:01 kojix2

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.

kojix2 avatar Jan 22 '22 01:01 kojix2