Trying to compile C++ Source Code for Matlab. Issue with name function definition/modification.

Hi,
I use Matlab2019b. I've been trying to compile on Windows an optimization toolbox called SPAMS http://spams-devel.gforge.inria.fr/index.html. The source code is in c++.
A compile.m file is provided, which helps the compilation procedure. An example command produced by the script is the following:
mex -IC:\Users\spams-matlab-v2.6\linalg -IC:\Users\spams-matlab-v2.6\decomp decomp\mex\mexLasso.cpp -outdir ./build/ -DUSE_BLAS_LIB -DNEW_MATLAB_BLAS -DINT_64BITS -largeArrayDims -DNDEBUG -DWINDOWS -DREMOVE_ -LC:\"Program Files"\MATLAB\R2019b\extern\lib\win64\microsoft\libmwblas.lib -LC:\"Program Files"\MATLAB\R2019b\extern\lib\win64\microsoft\libmwlapack.lib OPTIMFLAGS=" -O"
This is repeated for the different .cpp files in the toolbox.
However the commands work only for some of the libraries.
For some others I get errors similar to this:
Error using mex
In file included from C:\Users\ucacmgu\Documents\spams-matlab-v2.6\decomp\mex\mexLasso.cpp:34:0:
C:\Users\spams-matlab-v2.6\decomp/decomp.h: In instantiation of 'void coreLARS(Vector<T>&,
Vector<T>&, Vector<T>&, Vector<T>&, Vector<T>&, Vector<T>&, Vector<T>&, Matrix<T>&, Matrix<T>&, Matrix<T>&,
Matrix<T>&, Matrix<T>&, Matrix<T>&, const AbstractMatrix<T>&, T&, Vector<long long int>&, Vector<T>&, T, bool,
bool, constraint_type, T*, int) [with T = double]':
C:\Users\spams-matlab-v2.6\decomp/decomp.h:819:15: required from 'void lasso(const
Data<T>&, const AbstractMatrix<T>&, const AbstractMatrix<T>&, SpMatrix<T>&, int, T, constraint_type, bool,
bool, int, Matrix<T>*, int) [with T = double]'
C:\Users\spams-matlab-v2.6\decomp\mex\mexLasso.cpp:179:21: required from 'void
callFunction(mxArray**, const mxArray**, int, int) [with T = double; mxArray = mxArray_tag]'
C:\Users\spams-matlab-v2.6\decomp\mex\mexLasso.cpp:216:50: required from here
C:\Users\spams-matlab-v2.6\decomp/decomp.h:1026:28: error: 'isnan_' was not declared in this
scope
if (t > 0 || isnan(t) || isinf(t)) {
C:\Users\ucacmgu\Documents\spams-matlab-v2.6\decomp/decomp.h:1026:40: error: 'finite_' was not declared in
this scope
if (t > 0 || isnan(t) || isinf(t)) {
I found that the isnan and isinf functions in the error are defined in a header file included in the .cpp files. This is the initial part of the header (misc.h):
#ifndef MISC_H
#define MISC_H
#include <stdlib.h>
#include <stdio.h>
#include <cmath>
#include "utils.h"
#if defined(_MSC_VER) || defined(_WIN32) || defined(WINDOWS)
#define isnan _isnan
#define isinf !_finite
#endif
using namespace std;
Really don't know where the error is.
Please help me!
Michele

4 Commenti

My understanding is that decomp includes neasted headers which get to "misc.h" file (showed above).
Here the first few lines of code from decomp.h
#ifndef DECOMP_H
#define DECOMP_H
#include "utils.h"
static char low='l';
static char nonUnit='n';
/* **************************
* Greedy Forward Selection
* **************************/
/// Forward Selection (or Orthogonal matching pursuit)
/// Address the problem of:
/// \forall i, \min_{\alpha_i} ||X_i-D\alpha_i||_2^2
/// s.t. ||\alphai||_0 <= L or
/// \forall i, \min_{\alpha_i} ||\alpha_i||_0
/// s.t. ||\X_i-D\alpha_i||_2^2 <= epsilon
/// This function is
/// * based on Cholesky decompositions
/// * parallel
/// * optimized for a large number of signals (precompute the Gramm matrix
template <typename T>
void omp(const Matrix<T>& X, const Matrix<T>& D, SpMatrix<T>& spalpha,
const int *L, const T* eps, const T* lambda, const bool vecL = false,
const bool vecEps = false, const bool Lambda=false, const int numThreads=-1,
Matrix<T>* path = NULL);
But where in decomp.h is the isnan and isinf stuff?
Here is the specific part of the code:
if (ols == 0) {
const T t = gamma*gamma - 2*gamma*potentNorm;
if (t > 0 || isnan(t) || isinf(t)) {
// cerr << "bad bad exit" << endl;
// cerr << t << endl;
ind[j]=-1;
break;
}
normX += t;
} else {
// plan the last orthogonal projection
if (newAtom) {
RUn[j]=0.0;
for (int k = 0; k<=j; ++k) RUn[j] += Xdn[ind[k]]*
Un[j*L+k];
normX -= RUn[j]*RUn[j];
}
}
decomp.h is 3000+ lines of code. I've attached the file here for complitness.

Accedi per commentare.

Risposte (0)

Categorie

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by