franko / gsl-shell

GSL library shell based on LuaJIT2
http://franko.github.io/gsl-shell/
GNU General Public License v3.0
93 stars 12 forks source link

GDT as a lua library #31

Open ketigid opened 8 years ago

ketigid commented 8 years ago

Hi,

I have only recently discovered GSL-Shell. Thank you for your great work.

I'm very interested in the GDT module in GSL-Shell as I work with tabular data quite frequently.

Currently, I have LuaJIT embedded in my workflow. I have a configuration lua script that parses and pre-processes the input tabular data before passing it to the C++ program.

How can I use GDT module in this case? I hope to be able to use gdt = require('gdt').

franko commented 8 years ago

Hello,

I am glad you are interested in the GSL Shell and the GDT module. This latter has not been thought as a stand-alone Lua module but it can be easily adapted to this purpose.

Inside the gdt directory there are a few C files that should be compiled into a small DLL. Then the Lua counterpart gdt.lua call the functions in the DLL with the FFI module to implement the gdt functions and that's all! So technically it wouldn't be a Lua module but a LuaJIT module since it needs the FFI capabilities of LuaJIT.

In addition some other functions are implemented in the other gdt-*.lua file but these are easy to gather together.

I am wondering now if you could be interested to create the gdt module by yourself and to publish it on github. Of course I would participate and the amount of work required is quite limited.

Otherwise I'm curious about the usage you make of the GDT module. Which functions do you actually use ?

ketigid commented 8 years ago

Hi,

Thank you for your quick reply.

I have no experience in C and building DLL, but I will try. I have created a repository for this experiment at gsl-shell-gdt.

I have changed the gdt_table.h file to support DLL export. Also, commented the register_ffi_type lines in gdt.lua. And added ffi.load('libgdt') to cgdt.lua.

Now, the following command works: gdt = require('gdt') require('gdt-parse-csv') data = gdt.read_csv('examples/exam.csv)

But I can't access data. How do I proceed from here?

Many thanks.

As to your question, I am using read_csv and plot.

franko commented 8 years ago

Hi,

I have checkout out the gsl-shell-gdt repository and everything seems right. So I have made the test and I was able to read a CSV file as you did. Once you obtain the data table (the "data" variable in the code above) you can use the methods "get" or "set" on it to extract or set values. Otherwise you can write

= data:show()

to print the data in a readable, tabular form. LuaJIT will not pretty-print the tables, only GSL Shell do so by default.

Otherwise I am quite pleased of what you did, thank you! :-) I think I'm going to contribute to your repository by providing a Makefile and some improvements.

franko commented 8 years ago

I've seen your comments about the need of copying the libgcc and winpthreads DLLs. I recommend to use TDM-GCC to get rid of these annoyances, it is an excellent project and they are improving these kind of things.

I don't use any longer MSYS. I'm very happy using the binary git distribution for windows + tdm-gcc. They works well together the git on windows comes with a lot of goodies that can replace MSYS. They provides out-of-the-box many of the utilities one is used to have on Linux :-)

ketigid commented 8 years ago

I've tested building with TDM-GCC, it works great.

You mentioned about other gdt-*.lua files, I tried integrating them, but they seem to have many other dependencies. What do you recommend?

franko commented 8 years ago

As you want to use the module as a standalone you should probably exclude the gdt functions that requires matrix computations (because the GSL library is needed) or plotting (because the graphics subsystem is needed).

So I guess that you should leave out the « lm » module (linear regression) and everything that is related to « plotting ». You can probably include the « reduce » function which is implemented in the gdt-plot.lua file. It is a function that does not require the graphics module. I may be interesting to include this function but it is up to you to decide, it does require some code « surgery » to separate it from the gdt’s plotting functions.

If you decide to leave out the "reduce" function from gdt-plot.lua the number of required files should be very limited.