Questions tagged [librarylink]
Wolfram LibraryLink provides a powerful way to connect external code to Mathematica, enabling high-speed and memory-efficient execution.
170 questions
2
votes
0
answers
71
views
RemoteRunProcess failing to establish an SSH connection
I have a notebook with a workflow that I use to update several servers. I have used it many times and I know it works. Until today. For some reason the ...
1
vote
0
answers
94
views
A strange problem with GeoElevationData
I encountered an issue with the GeoElevationData function (version 14.2.1, Windows 10 Pro version 2009). In a fresh instance of Mathematica, the example
...
8
votes
1
answer
569
views
Pure C++ code vs LibraryLink
Suppose we have two implementations of the same algorithm:
A standalone C++ program, compiled into an executable.
A C++ library, which is loaded and invoked from within Mathematica.
In practice, ...
0
votes
1
answer
208
views
Internal error thrown by some functions in Mathematica on Windows
I have been using Mathematica For Desktop v14.2 since its release on several machines running Windows 10 and several running Windows 11. Everything works absolutely fine except for one PC running ...
3
votes
1
answer
201
views
Making faster extraction of table elements in Mathematica or beyond
Consider the following code:
...
2
votes
0
answers
80
views
Is it possible to use external functions in CompiledLayer?
I am trying to build a custom layer for my neural network that can perform its computation on the GPU. The function is to be written in C and loaded in Mathematica via the LibraryLink. Is it possible ...
2
votes
0
answers
137
views
A question about using .dll in Mathematica with LibraryFunctionLoad
I am trying to use a custom trilinear interpolation written in C in Mathematica (Windows).
This is the code I start with:
...
14
votes
3
answers
518
views
ForeignFunctionLoad / RawMemoryAllocate and c-struct that includes an array
I have an external c-function I need to call, and I wish to use ForeignFunctionLoad.
The c-function, foo, takes as an argument a reference to a struct, for example:
...
0
votes
0
answers
94
views
Qualitative question: can the code matching the given patterns be made significantly faster if being written in pure C?
I made some code in Mathematica that I compiled in C. It involves operations such as looping inside While, custom random sampling from particular distributions, and ...
5
votes
0
answers
157
views
Are ForeignFunction and its friends the next generation of LibraryLink?
It's a bit surprising to me that no one asks about this so far, so let me step up :) .
In version 13.3, an EXPERIMENTAL Foreign Function Interface has been introduced. I'm by no means a C expert, but ...
2
votes
0
answers
78
views
Why I can't install this package [closed]
I am trying to run C++ in Mathematica. I got a package "LTemplate" from the answer from Szabolcs in this post: How to simplify writing LibraryLink code?. However I can't install it.
This is ...
3
votes
0
answers
121
views
GSL multiroot finding mode Hybrid function load with Mathematica : Crash
Hi everyone
I work on a Mac M1 Sonoma 14.3 with Mathematica 12.3.1 and 14.0
I have an issue when using a C++ multiroot finding from GSL library.
I used this example : https://www.gnu.org/software/gsl/...
2
votes
0
answers
163
views
How to load a .dylib library (C++ not compile with Mathematica library) on Mac with Mathematica?
I work on a mac M1 with MacOS Sonoma and i use Mathematica 12.3.1 and 14.0
I wanted to ask if there is a way to load a .dylib library on Mac with Mathematica, which was compiled without using the ...
2
votes
0
answers
62
views
Checking debug mode in C-code when call CreateLibrary with Debug -> True
I create a C-library and compile it using the tools in LibraryLink. When I create a code binary like this
...
2
votes
1
answer
137
views
Exported function discovery with LibraryFunction
Many internal calls boil down to invocations like
LibraryFunction["path/to/library", "funcName" , ...]
I'm on a mac, so I can use the ...
2
votes
0
answers
102
views
How do I identify which external routine is potentially internally used when executing some built-in function?
Wolfram's website declares that "a large fraction of Mathematica's numerical algorithms are based on original research at Wolfram Research" (cf. So Many Original Wolfram Algorithms). So, ...
1
vote
1
answer
212
views
LMDB Library cannot be loaded by `LibraryLoad`, how to compile properly
I cloned LMDB* from https://github.com/LMDB/lmdb and compiled on a Mac M1 with
make -e clean liblmdb.so CC="cc -target aarch64-macos-none"
which produced ...
18
votes
1
answer
871
views
Fast Hankel Function in Mathematica
I am working on a project that requires repeated calls to HankelH1[0, r] for $r$ spanning the full real axis. When I use the mathematica routine, it can be as much ...
5
votes
1
answer
212
views
Third party libraries in LibraryLink
I am trying to use third-party libraries in LibraryLink, but the kernel crashes when I call their functions.
In particular, I want to make available some functions of SuiteSparse to manipulate ...
2
votes
0
answers
90
views
Bug: managed library expressions are freed prematurely during evaluation
I believe I have run into a bug with managed library expressions and garbage collection behavior. In the example below, adapted from the documentation for ...
3
votes
1
answer
174
views
Can I efficiently use a compiled function as an input to another compiled function?
I have a compiled function(such as $f\left(z,c\right)=z^2+c$) which will get replaced by different equations as the code runs. I'm using this compiled function(#1) inside another compiled function(#2)....
5
votes
1
answer
253
views
How to assign pointer to a rank 2 MTensor in Mathematica C code?
I've the following code
...
0
votes
0
answers
70
views
How can we change the EoS (to PR using the Flags function) for REFPROP used within Mathematica?
I would like to change the EoS used by REFPROP to the PR EoS for several calculations.
It's stated that the Flags function must be used.
"
Peng-Robinson or PR 0: Turn off the Peng-Robinson ...
3
votes
1
answer
153
views
How to call the librarylink api in 13.1
Local file demo.c have some library link API example, such as:
example 1:
...
4
votes
2
answers
281
views
How to get a MTensor variable by a vector object
librarylink have a dirty signature such as:
EXTERN_C DLLEXPORT int fun(WolframLibraryData libData,mint Argc, MArgument* Args, MArgument Res)
But when we are in ...
25
votes
2
answers
771
views
How to call the C++ by the new LibraryFunctionDeclaration?
When we arrive at V13.1, we have a great LibraryFunctionDeclaration now, which can call C function in MMA as this article:
...
1
vote
0
answers
149
views
It is possible to call C functions with pointers as arguments in Mathematica?
Here is my goal: I want to call external library functions, written in C (not by me), in Mathematica.
I may have found a way to do it using LibraryLink by following this scheme:
First, for each ...
20
votes
1
answer
1k
views
Is it possible to use the DGEEV and DSYEV LAPACK subroutines in Mathematica?
Here is my problem: I'm diagonalizing some matrices using Eigensystem[] to obtain eigenvalues and eigenvectors and I'm diagonalizing the same matrices using a ...
30
votes
2
answers
603
views
Which Mathematica versions have changed WolframLibraryVersion?
A LibraryLink library compiled with headers having a certain WolframLibraryVersion will not work with Mathematica versions that support only earlier ...
0
votes
0
answers
79
views
Is it possible to run kernel in address space of another process?
Kernel executables seem to be relatively small wrappers around "dynamic link library" that contains all the functionality of the kernel.
Is it possible to load the kernel (as a dynamic link ...
2
votes
0
answers
172
views
LibraryFunctionLoad with swift library
I'm trying to figure out if there is any sane way to call a swift function using the LibraryLoadFunction.
In Swift it seems possible to use @_cdecl to get a c callable dynamic library.
When I test ...
6
votes
2
answers
580
views
Speedup the production of a sparse symmetric matrix with a dense vector
The optimization of the production of a sparse symmetric matrix with a dense vector has existed for a long time. Someone once compared the matrix operations of Mathematica with MATLAB, and then came ...
6
votes
1
answer
726
views
Mathematica call C++ Eigen to calculate sparsematrix multiplication
I want to use the C++ Eigen library in Mathematica's LibraryLink function.
In the past, matheorem called C++ Eigen in Mathematica successfully. However, I am not ...
4
votes
0
answers
109
views
Should I worry about concurrent access to LibraryLinked code?
According to these answers, when several heterogeneous results (say {MTensor, mint, double}) are needed to be returned from a LibraryLink ...
8
votes
3
answers
361
views
Can LibraryLink receive and output a list of strings?
I need to use libraryLink to process a list of strings, I haven't found a suitable example, confused about the types of the arguments and return types. Does libraryLink directly support it, which one ...
1
vote
0
answers
94
views
Substitute for MathLink to integrate PARI with Mathematica?
How does one access MathLink with current version of Mathematica?
I'm trying to integrate the "computer algebra system" PARI with Mathematica, as documented at https://pari.math.u-bordeaux....
3
votes
2
answers
183
views
MTensor of MTensor (aka List of List)
In C++ I have a vector of 2D points :
typedef std::array<double, 2> Point;
std::vector<Point> samples;
Now, I'm in LibraryLink and I'd want to pass a ...
5
votes
1
answer
205
views
Difference between MTensor and MNumericArray in Mathematica
Since I'm starting to look into C-programming using LibraryLink to connect Mathematica to computational expensive calculations, I was wondering about the two available options within LibraryLink for ...
2
votes
0
answers
169
views
LTemplate and external library Armadillo
As a great fan of the simplicity of the LTemplate library for the end user I am now faced with a problem when apparently everything compiles correctly but the functions are not loaded from the library....
6
votes
1
answer
136
views
Default compiler optimization flag used by LibraryLink (CreateLibrary)?
What's the default optimization level (e.g. -O2, -O3) used by the function CreateLibrary, which invokes the system compiler to compile C/C++ code for use in LibraryLink?
3
votes
0
answers
274
views
Using MinGW-w64 from MSYS2 with LibraryLink
I am looking to use the MinGW-w64 version of gcc, as bundled with msys2, with LibraryLink.
It was communicated to me that in recent versions of Mathematica, one may use the MinGWCompiler compiler ...
3
votes
1
answer
338
views
How to get information from all built-in Mathematica functions in order to create a Kotlin library like the Wolfram Client Library for Python?
I'd like to use (if this already exists) or create a library to use Mathematica together with Kotlin (or Java) (not JLink, please see below).
We already have this very useful implementation for ...
5
votes
2
answers
357
views
Using WSTP with LibraryLink
I'm building an interface for a Fortran library. I would like to use LibraryLink and Mathematica to do the compilation (via CreateLibrary), Visual Studio is ...
2
votes
1
answer
125
views
ParallelTable does not evaluate DLL functions
I have a function programed in C which I load in MMA with
...
1
vote
1
answer
222
views
LibraryFunctionLoad with Cool Prop documentation
I use the following command
...
0
votes
0
answers
60
views
Improving performance of LibraryLink evaluation
I have a large function that I want to integrate with an integration routine.
The function is supposed to be built out of LibraryLink functions, but I find evaluating the function to be very slow, and ...
2
votes
2
answers
956
views
Couldn't load OpenSSL library in 12.1 (Windows)
Update:
Finally I found a clumsy way to solve this bug by myself: I created an alternate local kernel to run the code, and it surprisingly works out!
It is ridiculous that two local kernels contain ...
0
votes
0
answers
124
views
NestList with LibraryFunction
Edit
Same behavior without FORTRAN and undocumented part. What can be wrong in this case? LibraryFunction below is supposed to be just an identity function.
...
5
votes
1
answer
166
views
MathLink: How do I send a bigint?
Suppose I have a big integer from some library such as GMP. I need to return this from a LibraryLink function. What is the most efficient way to do it?
The simplest way is to convert it to a string <...
3
votes
1
answer
381
views
Meson build system + C/C++ LibraryLink, help needed for portability check/fix (Windows &MacOs)
As a proof of concept I have created a github repository that shows how to:
use the Meson build system to create a Mathematica package using LibraryLink functions
The goal is to provide an easy to ...