njpipeorgan / wll-interface Goto Github PK
View Code? Open in Web Editor NEWHeader only C++ library simplifying Wolfram LibraryLink code
License: MIT License
Header only C++ library simplifying Wolfram LibraryLink code
License: MIT License
First of all, thanks for sharing this amazing project! This project is not only very useful in practice to ease the interaction of C++ in Mathematica, it also demonstrates greate C++ programming skills of implementing the whole system compactly.
When running in ubuntu 18.04, the sum of an array example doesn't seem to work for me. It crashes the Mathematica kernel.
This is the process I used to build and load the library in Mathematica:
<<CCompilerDriver`
CCompilerDriver`$CCompiler={
"Compiler"->CCompilerDriver`GenericCCompiler`GenericCCompiler,
"CompilerInstallation"->"/usr/bin","CompilerName"->"g++-7"};
src="
#include <numeric>
#include \"wll_interface.h\"
double sum(const wll::list<double>& a)
{
return std::accumulate(a.begin(), a.end(), 0.0);
}
DEFINE_WLL_FUNCTION(sum)";
mylib=CreateLibrary[src,"wll_sum",
"IncludeDirectories"->{"/root/wll-interface/include"},
"CompileOptions"->"-std=c++17 -fPIC"]
mylib=CreateLibrary[src,"wll_sum",
"IncludeDirectories"->{"/root/wll-interface/include"},
"CompileOptions"->"-std=c++17 -fPIC"]
sum = LibraryFunctionLoad[mylib, "wll_sum", {{Real, 1, "Constant"}}, Real];
sum[{1,2,3}]
I'm using gcc 7.4 on ubuntu 18.04: g++-7 (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0
Do you have any ideas or suggestions for the potential cause?
Thanks.
It seems that calling an external library in a library function leads to crash of mathematica kernals.
These are the steps to reproduce the crash:
File /tmp/external_lib/addone.c
:
int addone(int x){
return x+1;
}
Compile to dynamic library
gcc -Wall -fpic -shared -o libaddone.so addone.c
which generate file /tmp/external_lib/libaddone.so
Load into Mathematica
src = "
#include <wll_interface.h>
int addone(int x);
int test(int x)
{
return addone(x);
}
DEFINE_WLL_FUNCTION(test)";
CCompilerDriver`$CCompiler = {"Compiler" ->
CCompilerDriver`GenericCCompiler`GenericCCompiler,
"CompilerInstallation" -> "/usr/bin", "CompilerName" -> "g++-7"}
mylib = CreateLibrary[src, "wll_test",
"IncludeDirectories" -> {"/home/mengxiwu/.Mathematica/include"},
"LibraryDirectories" -> {"/tmp/external_lib/"},
"CompileOptions" -> "-std=c++17 -fPIC",
"LinkerOptions" -> "-laddone"]
test = LibraryFunctionLoad[mylib, "wll_test", {Integer}, Integer]
test[3]
Any ideas for the crash? Thanks.
Thank you for developing wll-interface, it's been incredibly useful in my personal projects. My question is:
Is there a way to return a wll::tensor
by-reference if the dimensions are not known a priori?
Right now, I'm splitting up any C++ routines that have multiple returns into:
Returning multiple things by-reference would be cleaner and thread-safe, but when I tried it, my C++ functions that resized the by-reference output wll::tensor
s caused the kernel to crash.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.