From a66594caedf0672ba81f4a19887aefc6f635eb88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Mon, 9 Jan 2012 12:37:55 +0100 Subject: [PATCH] Add MEXEXT define to build system, adapt relevant DLL and Windows packaging Closes: #235 --- matlab/dynare_config.m | 9 ++++-- matlab/k_order_pert.m | 11 +++----- mex/build/matlab/mex.am | 1 + mex/build/octave/mex.am | 1 + mex/sources/estimation/logMHMCMCposterior.cc | 28 ++++++++----------- mex/sources/estimation/logposterior.cc | 24 ++++++---------- .../k_order_perturbation/dynamic_dll.cc | 6 ++-- .../k_order_perturbation/dynamic_dll.hh | 4 +-- .../k_order_perturbation.cc | 11 +++----- windows/dynare.nsi | 11 ++++++-- 10 files changed, 49 insertions(+), 57 deletions(-) diff --git a/matlab/dynare_config.m b/matlab/dynare_config.m index 90958fd00..97b18745d 100644 --- a/matlab/dynare_config.m +++ b/matlab/dynare_config.m @@ -111,8 +111,13 @@ if exist('OCTAVE_VERSION') else % Add win32 specific paths for Dynare Windows package if strcmp(computer, 'PCWIN') - if matlab_ver_less_than('7.5') - mexpath = [dynareroot '../mex/matlab/win32-7.0-7.4']; + if matlab_ver_less_than('7.1') + mexpath = [dynareroot '../mex/matlab/win32-7.0-7.0.4']; + if exist(mexpath, 'dir') + addpath(mexpath) + end + elseif matlab_ver_less_than('7.5') + mexpath = [dynareroot '../mex/matlab/win32-7.1-7.4']; if exist(mexpath, 'dir') addpath(mexpath) end diff --git a/matlab/k_order_pert.m b/matlab/k_order_pert.m index 777e5d253..09eeb955b 100644 --- a/matlab/k_order_pert.m +++ b/matlab/k_order_pert.m @@ -1,7 +1,7 @@ function [dr,info] = k_order_pert(dr,M,options,oo) % Compute decision rules using the k-order DLL from Dynare++ -% Copyright (C) 2009-2010 Dynare Team +% Copyright (C) 2009-2012 Dynare Team % % This file is part of Dynare. % @@ -26,20 +26,17 @@ order = options.order; switch(order) case 1 - [err, g_1] = k_order_perturbation(dr,M,options, ['.' ... - mexext]); + [err, g_1] = k_order_perturbation(dr,M,options); mexErrCheck('k_order_perturbation', err); dr.g_1 = g_1; case 2 - [err, g_0, g_1, g_2] = k_order_perturbation(dr,M,options, ['.' ... - mexext]); + [err, g_0, g_1, g_2] = k_order_perturbation(dr,M,options); mexErrCheck('k_order_perturbation', err); dr.g_0 = g_0; dr.g_1 = g_1; dr.g_2 = g_2; case 3 - [err, g_0, g_1, g_2, g_3] = k_order_perturbation(dr,M,options, ['.' ... - mexext]); + [err, g_0, g_1, g_2, g_3] = k_order_perturbation(dr,M,options); mexErrCheck('k_order_perturbation', err); dr.g_0 = g_0; dr.g_1 = g_1; diff --git a/mex/build/matlab/mex.am b/mex/build/matlab/mex.am index 6bc9a4308..cfeabedcd 100644 --- a/mex/build/matlab/mex.am +++ b/mex/build/matlab/mex.am @@ -5,6 +5,7 @@ CPPFLAGS += -I$(top_srcdir)/../../sources DEFS += $(MATLAB_DEFS) DEFS += -DMATLAB_MEX_FILE +DEFS += -DMEXEXT=\"$(MEXEXT)\" LDFLAGS += $(MATLAB_LDFLAGS) LIBS += $(MATLAB_LIBS) diff --git a/mex/build/octave/mex.am b/mex/build/octave/mex.am index f11827ec6..20fefd2cc 100644 --- a/mex/build/octave/mex.am +++ b/mex/build/octave/mex.am @@ -3,6 +3,7 @@ CPPFLAGS += $(shell $(MKOCTFILE) -p INCFLAGS) CPPFLAGS += -I$(top_srcdir)/../../sources DEFS += -DOCTAVE_MEX_FILE +DEFS += -DMEXEXT=\".mex\" CFLAGS += $(shell $(MKOCTFILE) -p CPICFLAG) FFLAGS += $(shell $(MKOCTFILE) -p FPICFLAG) diff --git a/mex/sources/estimation/logMHMCMCposterior.cc b/mex/sources/estimation/logMHMCMCposterior.cc index f9600ed4d..a77e55c77 100644 --- a/mex/sources/estimation/logMHMCMCposterior.cc +++ b/mex/sources/estimation/logMHMCMCposterior.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2011 Dynare Team + * Copyright (C) 2010-2012 Dynare Team * * This file is part of Dynare. * @@ -624,7 +624,7 @@ sampleMHMC(LogPosteriorDensity &lpd, RandomWalkMetropolisHastings &rwmh, } int -logMCMCposterior(const VectorConstView &estParams, const MatrixConstView &data, const std::string &mexext, +logMCMCposterior(const VectorConstView &estParams, const MatrixConstView &data, const size_t fblock, const size_t nBlocks, const VectorConstView &nMHruns, const MatrixConstView &D) { // Retrieve pointers to global variables @@ -638,7 +638,8 @@ logMCMCposterior(const VectorConstView &estParams, const MatrixConstView &data, std::string resultsFileStem(fName); std::string dynamicDllFile(fName); mxFree(fName); - dynamicDllFile += "_dynamic." + mexext; + dynamicDllFile += "_dynamic"; + dynamicDllFile += MEXEXT; size_t n_endo = (size_t) *mxGetPr(mxGetField(M_, 0, "endo_nbr")); size_t n_exo = (size_t) *mxGetPr(mxGetField(M_, 0, "exo_nbr")); @@ -745,8 +746,8 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { - if (nrhs != 7) - DYN_MEX_FUNC_ERR_MSG_TXT("logposterior: exactly seven arguments are required."); + if (nrhs != 6) + DYN_MEX_FUNC_ERR_MSG_TXT("logposterior: exactly six arguments are required."); if (nlhs != 2) DYN_MEX_FUNC_ERR_MSG_TXT("logposterior: exactly two return arguments are required."); @@ -762,23 +763,16 @@ mexFunction(int nlhs, mxArray *plhs[], MatrixConstView data(mxGetPr(prhs[1]), mxGetM(prhs[1]), mxGetN(prhs[1]), mxGetM(prhs[1])); - if (!mxIsChar(prhs[2])) - DYN_MEX_FUNC_ERR_MSG_TXT("logposterior: Third argument must be a character string"); - - char *mexext_mx = mxArrayToString(prhs[2]); - std::string mexext(mexext_mx); - mxFree(mexext_mx); - - size_t fblock = (size_t) mxGetScalar(prhs[3]); - size_t nBlocks = (size_t) mxGetScalar(prhs[4]); - VectorConstView nMHruns(mxGetPr(prhs[5]), mxGetM(prhs[5]), 1); + size_t fblock = (size_t) mxGetScalar(prhs[2]); + size_t nBlocks = (size_t) mxGetScalar(prhs[3]); + VectorConstView nMHruns(mxGetPr(prhs[4]), mxGetM(prhs[4]), 1); assert(nMHruns.getSize() == nBlocks); - MatrixConstView D(mxGetPr(prhs[6]), mxGetM(prhs[6]), mxGetN(prhs[6]), mxGetM(prhs[6])); + MatrixConstView D(mxGetPr(prhs[5]), mxGetM(prhs[5]), mxGetN(prhs[5]), mxGetM(prhs[5])); //calculate MHMCMC draws and get get last line run in the last MH block sub-array try { - int lastMHblockArrayLine = logMCMCposterior(estParams, data, mexext, fblock, nBlocks, nMHruns, D); + int lastMHblockArrayLine = logMCMCposterior(estParams, data, fblock, nBlocks, nMHruns, D); plhs[1] = mxCreateDoubleMatrix(1, 1, mxREAL); *mxGetPr(plhs[1]) = (double) lastMHblockArrayLine; } diff --git a/mex/sources/estimation/logposterior.cc b/mex/sources/estimation/logposterior.cc index 7205e0692..2f5307647 100644 --- a/mex/sources/estimation/logposterior.cc +++ b/mex/sources/estimation/logposterior.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2011 Dynare Team + * Copyright (C) 2010-2012 Dynare Team * * This file is part of Dynare. * @@ -101,8 +101,7 @@ fillEstParamsInfo(const mxArray *estim_params_info, EstimatedParameter::pType ty } double -logposterior(const VectorConstView &estParams, const MatrixConstView &data, - const std::string &mexext) +logposterior(const VectorConstView &estParams, const MatrixConstView &data) { // Retrieve pointers to global variables const mxArray *M_ = mexGetVariablePtr("global", "M_"); @@ -114,7 +113,8 @@ logposterior(const VectorConstView &estParams, const MatrixConstView &data, char *fName = mxArrayToString(mxGetField(M_, 0, "fname")); std::string dynamicDllFile(fName); mxFree(fName); - dynamicDllFile += "_dynamic." + mexext; + dynamicDllFile += "_dynamic"; + dynamicDllFile += MEXEXT; size_t n_endo = (size_t) *mxGetPr(mxGetField(M_, 0, "endo_nbr")); size_t n_exo = (size_t) *mxGetPr(mxGetField(M_, 0, "exo_nbr")); @@ -211,8 +211,8 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { - if (nrhs != 3 || nlhs != 2) - DYN_MEX_FUNC_ERR_MSG_TXT("logposterior: exactly three input arguments and two output arguments are required."); + if (nrhs != 2 || nlhs != 2) + DYN_MEX_FUNC_ERR_MSG_TXT("logposterior: exactly two input arguments and two output arguments are required."); // Check and retrieve the arguments @@ -225,19 +225,11 @@ mexFunction(int nlhs, mxArray *plhs[], DYN_MEX_FUNC_ERR_MSG_TXT("logposterior: Second argument must be a matrix of double-precision numbers"); MatrixConstView data(mxGetPr(prhs[1]), mxGetM(prhs[1]), mxGetN(prhs[1]), mxGetM(prhs[1])); - - if (!mxIsChar(prhs[2])) - DYN_MEX_FUNC_ERR_MSG_TXT("logposterior: Third argument must be a character string"); - - char *mexext_mx = mxArrayToString(prhs[2]); - std::string - mexext(mexext_mx); - mxFree(mexext_mx); - + // Compute and return the value try { - double lik = logposterior(estParams, data, mexext); + double lik = logposterior(estParams, data); plhs[1] = mxCreateDoubleMatrix(1, 1, mxREAL); *mxGetPr(plhs[1]) = lik; } diff --git a/mex/sources/k_order_perturbation/dynamic_dll.cc b/mex/sources/k_order_perturbation/dynamic_dll.cc index 64f3b0aba..bd816262e 100644 --- a/mex/sources/k_order_perturbation/dynamic_dll.cc +++ b/mex/sources/k_order_perturbation/dynamic_dll.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008-2010 Dynare Team + * Copyright (C) 2008-2012 Dynare Team * * This file is part of Dynare. * @@ -21,13 +21,13 @@ #include -DynamicModelDLL::DynamicModelDLL(const string &modName, const string &sExt) throw (DynareException) +DynamicModelDLL::DynamicModelDLL(const string &modName) throw (DynareException) { string fName; #if !defined(__CYGWIN32__) && !defined(_WIN32) fName = "./"; #endif - fName += modName + "_dynamic" + sExt; + fName += modName + "_dynamic" + MEXEXT; try { diff --git a/mex/sources/k_order_perturbation/dynamic_dll.hh b/mex/sources/k_order_perturbation/dynamic_dll.hh index 1629205e1..cf3755058 100644 --- a/mex/sources/k_order_perturbation/dynamic_dll.hh +++ b/mex/sources/k_order_perturbation/dynamic_dll.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008-2011 Dynare Team + * Copyright (C) 2008-2012 Dynare Team * * This file is part of Dynare. * @@ -55,7 +55,7 @@ private: public: // construct and load Dynamic model DLL - DynamicModelDLL(const string &fname, const string &sExt) throw (DynareException); + DynamicModelDLL(const string &fname) throw (DynareException); virtual ~DynamicModelDLL(); void eval(const Vector &y, const Vector &x, const Vector ¶ms, const Vector &ySteady, diff --git a/mex/sources/k_order_perturbation/k_order_perturbation.cc b/mex/sources/k_order_perturbation/k_order_perturbation.cc index b53e8bb97..86a98209b 100644 --- a/mex/sources/k_order_perturbation/k_order_perturbation.cc +++ b/mex/sources/k_order_perturbation/k_order_perturbation.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008-2011 Dynare Team + * Copyright (C) 2008-2012 Dynare Team * * This file is part of Dynare. * @@ -24,7 +24,6 @@ 1) dr 2) M_ 3) options - 4) string containing the MEX extension (with a dot at the beginning) Outputs: - if order == 1: only g_1 @@ -69,8 +68,8 @@ extern "C" { mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { - if (nrhs != 4 || nlhs < 2) - DYN_MEX_FUNC_ERR_MSG_TXT("Must have exactly 4 input parameters and take at least 2 output parameters."); + if (nrhs != 3 || nlhs < 2) + DYN_MEX_FUNC_ERR_MSG_TXT("Must have exactly 3 input parameters and take at least 2 output parameters."); const mxArray *dr = prhs[0]; const mxArray *M_ = prhs[1]; @@ -82,8 +81,6 @@ extern "C" { DYN_MEX_FUNC_ERR_MSG_TXT("Input must be of type char."); string fName = mxArrayToString(mFname); - const mxArray *mexExt = prhs[3]; - string dfExt = mxArrayToString(mexExt); // Dynamic file extension, e.g. ".dll" or ".mexw32" int kOrder; mxArray *mxFldp = mxGetField(options_, 0, "order"); @@ -208,7 +205,7 @@ extern "C" { DynamicModelAC *dynamicModelFile; if (use_dll == 1) - dynamicModelFile = new DynamicModelDLL(fName, dfExt); + dynamicModelFile = new DynamicModelDLL(fName); else dynamicModelFile = new DynamicModelMFile(fName); diff --git a/windows/dynare.nsi b/windows/dynare.nsi index 2168c5248..8d1f3ed71 100644 --- a/windows/dynare.nsi +++ b/windows/dynare.nsi @@ -75,9 +75,14 @@ SectionEnd SectionGroup "MEX files for MATLAB" -Section "MEX files for MATLAB 32-bit, version 7.0 to 7.4 (R14 to R2007a)" - SetOutPath $INSTDIR\mex\matlab\win32-7.0-7.4 - File ..\mex\matlab\win32-7.0-7.4\*.dll +Section "MEX files for MATLAB 32-bit, version 7.0 to 7.0.4 (R14 to R14SP2)" + SetOutPath $INSTDIR\mex\matlab\win32-7.0-7.0.4 + File ..\mex\matlab\win32-7.0-7.0.4\*.dll +SectionEnd + +Section "MEX files for MATLAB 32-bit, version 7.1 to 7.4 (R14SP3 to R2007a)" + SetOutPath $INSTDIR\mex\matlab\win32-7.1-7.4 + File ..\mex\matlab\win32-7.1-7.4\*.mexw32 SectionEnd Section "MEX files for MATLAB 32-bit, version 7.5 to 7.13 (R2007b to R2011b)"