Skip to main content
53 votes
Accepted

Why does Mathematica results differ from C++ results within machine precision?

Something important to keep in mind is that Mathematica parses x / y as Times[x, Power[y, -1]] For actual floating point ...
ilian's user avatar
  • 25.5k
23 votes
Accepted

Fast Hankel Function in Mathematica

This is LibraryLink code with compiler and linker options specifically for macos on Apple Silicon. These are the prerequisites to compile and run this successfully: XCode installed along with the ...
Henrik Schumacher's user avatar
19 votes

Minimal effort method for integrating C++ functions into Mathematica

In terms of loading C++ functions, I would strongly suggest LibraryLink. It is a great tool except that it requires you to write sometimes intimidating C code. To make LibraryLink easier to use, I ...
njpipeorgan's user avatar
  • 1,176
16 votes

Why does Mathematica results differ from C++ results within machine precision?

Without code and your actual results, this question cannot be answered. Here is one thing that might help: We have a compiler that can compile to C it can show you the code it creates. So why don't ...
halirutan's user avatar
  • 113k
14 votes
Accepted

C++ interface to large project

This cannot be answered very well without knowing your C++ library much better. As you said, you have a choice between MathLink and LibraryLink. Generally, I recommend LibraryLink because: It runs ...
Szabolcs's user avatar
  • 236k
14 votes
Accepted

WXF encoder library for C++

We have developed a C library to support BinarySerialize/BinaryDeserialize. I confirm that we plan to open-source it as well. ...
Dorian B.'s user avatar
  • 381
14 votes

How to call the C++ by the new LibraryFunctionDeclaration?

This post is written with Mathematica version 13.1 and is subject to change in the future. Mathematica's C Types does not include vector type but includes ...
Ben Izd's user avatar
  • 9,319
13 votes
Accepted

Mathematica call C++ Eigen to calculate sparsematrix multiplication

Even if Eigen is probably not the solution for you problem at hand, it contains a couple of other interesting features that one might want to use from within Mathematica. So here a minimal example ...
Henrik Schumacher's user avatar
9 votes

Link server WSTP API feature not receiving incoming connections

You are missing just one bit of secret sauce to get this to work. When you connect to a LinkServer link directly using WSTP/MathLink functionality, you need to use "-linkoptions 4" in the arguments to ...
Todd Gayley's user avatar
  • 4,208
9 votes
Accepted

How to call the librarylink api in 13.1

You are simply misinterpreting the examples I think: Example 1: Reading the error message (please post them directly in the question in future) ...
Lukas Lang's user avatar
  • 34.1k
9 votes

c++ or Mathematica for large eigenvalue problem

Mathematica's Eigensystem takes a special code branch when you call it on a self-adjoint, sparse matrix A. You should get the $k$...
Henrik Schumacher's user avatar
8 votes
Accepted

How to call the C++ by the new LibraryFunctionDeclaration?

This is my program, in fact most of it comes from an unknown author. And it exactly is what I'm after. For more details you need to see follow this article for updates ...
yode's user avatar
  • 26.8k
6 votes

Using Mathematica wlnet model in C++

In Mathematica 11.2, which will be released in the next month or so, it is as simple as writing Export["mynet.json", net, "MXNet"]. This will also produce a "params"...
Taliesin Beynon's user avatar
6 votes
Accepted

Default compiler optimization flag used by LibraryLink (CreateLibrary)?

This depends on the specific compiler driver that is being used. The easiest way to get not only the compiler options, but the entire compilation command is to add ...
Szabolcs's user avatar
  • 236k
6 votes

How to get a MTensor variable by a vector object

Here's one way that works, although I am not sure it is the intended way: ...
Lukas Lang's user avatar
  • 34.1k
5 votes

Link server WSTP API feature not receiving incoming connections

This is unfortunately not a solution to the main problem yet, but I spent way to much time to not share the information. I tried several different ways and finally gave up. I created a public ...
halirutan's user avatar
  • 113k
5 votes
Accepted

Hide WSTP application from taskbar

Turns out it was really simple and Szabolcs was right - removing the line if (!WSInitializeIcon(hinstCurrent, nCmdShow)) return 1; from the ...
mjayvizzle's user avatar
5 votes
Accepted

Using Mathematica wlnet model in C++

I will use two cases to make example: First,Seq2Seq model RandomSeed[1234]; net = NetInitialize@NetChain[{5, 3}, "Input" -> 2]; net[{1,2}] {1.27735, -1....
partida's user avatar
  • 6,836
5 votes

Defining general type of functions

There is a significant semantic argument as to whether what you're asking for is appropriately termed a "function". What you're requesting is, in C++ terms, a function of type ...
eyorble's user avatar
  • 9,488
4 votes

Write Power in CForm[] as multiplication instead

You can override the default CForm handling of Power as follows: ...
Carl Woll's user avatar
  • 131k
4 votes
Accepted

Importing floating-point numbers in scientific notation generated by a C++ program

I recommend that you write your data into the JSON format instead of Mathematica syntax. If you already have C++ code to generate the output you show, it will be easier to modify this code to produce ...
Szabolcs's user avatar
  • 236k
4 votes
Accepted

Why the Debug .dll is work normall but the Release .dll is crash in librarylink?

When I use WolframLibraryData to initialize the MTensor now, I have solved the crash bug. And don't leak memory anymore´╝Ü ...
yode's user avatar
  • 26.8k
3 votes
Accepted

cannot launch the Visual Studio C++ Mathematica program on debug mode, only on release mode!

Do not link against wstp64i4s.lib. wstp64i4.lib is the only version you should use.
ihojnicki's user avatar
  • 3,181
3 votes
Accepted

Meson build system + C/C++ LibraryLink, help needed for portability check/fix (Windows &MacOs)

On Mac OS Mojave and Mathematica Version 11.3, the only modification required was to change find_program('wolfram') to ...
Rohit Namjoshi's user avatar
3 votes

Importing floating-point numbers in scientific notation generated by a C++ program

Actually there are some problems with importing FP numbers via string literal in Mathematica. I tested 11 different methods against the specialized test collection and every single one of them failed. ...
ahrvoje's user avatar
  • 153
3 votes

Write Power in CForm[] as multiplication instead

If the symbol you are using is known in advance, you can useTagSetDelayed and associate an UpValue with that symbol inside the <...
Stitch's user avatar
  • 4,225
2 votes

Restricting the evaluation of variables

Use SetDelayed (:=) a = x^2; b := a^2 ?b b:=a^2 As you can see, b is still ...
Chris Degnen's user avatar
2 votes

Importing binary structured C++ data file

As per the comment, the third syntax format of BinaryReadList does what is required: BinaryReadList["file",{type1,type2,...}]

Only top scored, non community-wiki answers of a minimum length are eligible