Hot answers tagged

6

a bit of an extended comment, Note there is no need for a delayed defintion of your pdf: pdf[r_] = Simplify[2 (Piecewise[{{0, r <= 0.59}, {1.36814, Inequality[0.59, Less, r, LessEqual, 0.7]}, {0, r > 0.7}}, Indeterminate] + Piecewise[{{0, r <= 0.7}, {1.99139, Inequality[0.7, Less, r, LessEqual, 0.85]}, {0, r > 0.85}}, ...


5

LibraryLink's complex type, mcomplex, is defined as two contiguous double values. In C++, std::complex<double> has exactly the same layout. This is guaranteed since C++11, but should hold in most other cases too in practice. This means that if you get a complex array from Mathematica, mcomplex *arr = MTensor_getComplexData(t); then you can ...


5

This can be done without using any Mathematica features. You can keep the matrix as a global variable on the C++ side. You will have a function for initializing it, a function for destroying it, and a function for the distance calculation. Then just call the initializer and cleanup function manually from Mathematica when you need to. Note: Storing a ...


4

tl; dr Report errors through return values. MathLink programs can return any Mathematica expression they like which makes structured error handling possible. It looks like you have a function that returns integers with a template like :Begin: :Function: get_number :Pattern: getNumber[x_Integer] :Arguments: {x} :ArgumentTypes: {Integer32} ...


2

Based on Todd Gayley's response here and trying it out, it can be done using MLTransferExpression(NULL, link) This will remove one complete (sub)expression form the link. The code for the example from the question would be int argc = 2; if (! MLTestHeadWithArgCount(link, "f", &argc)) { // fail } MLTransferExpression(NULL, link); int i; ...


2

You are inconsistent with the number of entries in your arrays. You seem to want 5. mymatrix = Table[RandomInteger[1], {5}, {5}]; hub = {1, 1, 1, 1, 1}; auth = {0, 0, 0, 0, 0}; Table[If[mymatrix[[i, j]] == 1, auth[[i]] = auth[[i]] + hub[[j]]], {i, 5}, {j, 5}]; auth or mymatrix = Table[RandomInteger[1], {5}, {5}]; hub = {1, 1, 1, 1, 1}; auth = {0, 0, ...


2

Yes: Just use return MLPutFunction(mlp, "EvaluatePacket", 1L) && MLPutFunction(mlp, "ToString", 1L) // <<<--- ! && MLPutFunction(mlp, "ToExpression", 1L) /* ... */


1

Thanks to Szabolcs for pointing out the right way. So I rewrite the real Inverse version into complex version, and pasted here for reference. libnewsource="#include<complex> #include<Eigen/Dense> #include<Eigen/LU> #include \"WolframLibrary.h\" DLLEXPORT mint WolframLibrary_getVersion(){return WolframLibraryVersion;} DLLEXPORT int ...



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