Dynare++ and k_order_perturbation DLL:

* support Microsoft Visual C++ 2008 compiler (necessary for 64-bit 
platforms)
* use standard C++ headers for C Standard Library support


git-svn-id: https://www.dynare.org/svn/dynare/trunk@3121 ac1d8469-bf42-47a9-8791-bf33cf982152
time-shift
sebastien 2009-11-03 14:16:18 +00:00
parent 3a137c3eaa
commit 295f998503
53 changed files with 220 additions and 122 deletions

View File

@ -6,7 +6,7 @@
@c @c
#include "quasi_mcarlo.h" #include "quasi_mcarlo.h"
#include <math.h> #include <cmath>
@<|RadicalInverse| constructor code@>; @<|RadicalInverse| constructor code@>;
@<|RadicalInverse::eval| code@>; @<|RadicalInverse::eval| code@>;

View File

@ -9,9 +9,9 @@
#include <dynlapack.h> #include <dynlapack.h>
#include <math.h> #include <cmath>
#include <string.h> #include <cstring>
#include <algorithm> #include <algorithm>
@<|ParameterSignal| constructor code@>; @<|ParameterSignal| constructor code@>;
@ -155,7 +155,11 @@ void GaussConverterFunction::eval(const Vector& point, const ParameterSignal& si
@<|GaussConverterFunction::multiplier| code@>= @<|GaussConverterFunction::multiplier| code@>=
double GaussConverterFunction::calcMultiplier() const double GaussConverterFunction::calcMultiplier() const
{ {
#ifndef _MSC_VER
return sqrt(pow(M_PI, -1*indim())); return sqrt(pow(M_PI, -1*indim()));
#else
return sqrt(pow(3.14159265358979323846, -1*indim()));
#endif
} }
@ @

View File

@ -12,7 +12,7 @@
#include "integ/cc/product.h" #include "integ/cc/product.h"
#include <getopt.h> #include <getopt.h>
#include <stdio.h> #include <cstdio>
#include <cmath> #include <cmath>

View File

@ -14,10 +14,10 @@
#include "product.h" #include "product.h"
#include "quasi_mcarlo.h" #include "quasi_mcarlo.h"
#include <stdio.h> #include <cstdio>
#include <string.h> #include <cstring>
#include <sys/time.h> #include <sys/time.h>
#include <math.h> #include <cmath>
const int num_threads = 2; // does nothing if DEBUG defined const int num_threads = 2; // does nothing if DEBUG defined

View File

@ -683,7 +683,11 @@ void GenShockRealization::get(int n, Vector& out)
Vector r(numShocks()); Vector r(numShocks());
RandomShockRealization::get(n, r); RandomShockRealization::get(n, r);
for (int j = 0; j < numShocks(); j++) for (int j = 0; j < numShocks(); j++)
#ifndef _MSC_VER
if (! isfinite(out[j])) if (! isfinite(out[j]))
#else
if (!_finite(out[j]))
#endif
out[j] = r[j]; out[j] = r[j];
} }

View File

@ -631,7 +631,13 @@ damp by one half.
if (fnorm <= flastnorm) if (fnorm <= flastnorm)
urelax_found = true; urelax_found = true;
else else
#ifndef _MSC_VER
urelax *= std::min(0.5, flastnorm/fnorm); urelax *= std::min(0.5, flastnorm/fnorm);
#else
/* MSVC doesn't define std::min() (should be in <algorithm>),
but instead has a macro in <windows.h> */
urelax *= min(0.5, flastnorm/fnorm);
#endif
} }

View File

@ -10,7 +10,7 @@
#include "faa_di_bruno.h" #include "faa_di_bruno.h"
#include "fine_container.h" #include "fine_container.h"
#include <math.h> #include <cmath>
double FaaDiBruno::magic_mult = 1.5; double FaaDiBruno::magic_mult = 1.5;
@<|FaaDiBruno::calculate| folded sparse code@>; @<|FaaDiBruno::calculate| folded sparse code@>;

View File

@ -295,7 +295,11 @@ void FirstOrder::journalEigs()
} }
JournalRecord jr(journal); JournalRecord jr(journal);
double mod = sqrt(alphar[i]*alphar[i]+alphai[i]*alphai[i]); double mod = sqrt(alphar[i]*alphar[i]+alphai[i]*alphai[i]);
#ifndef _MSC_VER
mod = mod/round(100000*std::abs(beta[i]))*100000; mod = mod/round(100000*std::abs(beta[i]))*100000;
#else // MSVC doesn't respect C99 standard and doesn't define round(); use floor(x+0.5) instead
mod = mod/floor(100000*std::abs(beta[i])+0.5)*100000;
#endif
jr << i << "\t(" << alphar[i] << "," << alphai[i] << ") / " << beta[i] jr << i << "\t(" << alphar[i] << "," << alphai[i] << ") / " << beta[i]
<< " \t" << mod << endrec; << " \t" << mod << endrec;
} }

View File

@ -373,7 +373,11 @@ f^i(x_1,\ldots,x_i) &=
for (qmcpit run = beg; run != end; ++run, icol++) { for (qmcpit run = beg; run != end; ++run, icol++) {
Vector ycol(ymat, icol); Vector ycol(ymat, icol);
Vector x(run.point()); Vector x(run.point());
#ifndef _MSC_VER
x.mult(2*M_PI); x.mult(2*M_PI);
#else
x.mult(2*3.14159265358979323846);
#endif
ycol[0] = 1; ycol[0] = 1;
for (int i = 0; i < d; i++) { for (int i = 0; i < d; i++) {
Vector subsphere(ycol, 0, i+1); Vector subsphere(ycol, 0, i+1);

View File

@ -7,19 +7,65 @@
#include "journal.h" #include "journal.h"
#include "kord_exception.h" #include "kord_exception.h"
#ifndef __MINGW32__ #if !defined(__MINGW32__) && !defined(_MSC_VER)
# include <sys/resource.h> # include <sys/resource.h>
# include <sys/utsname.h> # include <sys/utsname.h>
#endif #endif
#include <stdlib.h> #include <cstdlib>
#include <unistd.h> #ifndef _MSC_VER
#include <time.h> # include <unistd.h>
#endif
#include <ctime>
SystemResources _sysres; SystemResources _sysres;
#ifdef __MINGW32__ #if defined(__MINGW32__) || defined(_MSC_VER)
@<|sysconf| Win32 implementation@>; @<|sysconf| Win32 implementation@>;
#endif #endif
#ifdef _MSC_VER
struct timezone
{
int tz_minuteswest; /* minutes W of Greenwich */
int tz_dsttime; /* type of dst correction */
};
int gettimeofday(struct timeval *tv, struct timezone *tz)
{
FILETIME ft;
unsigned __int64 tmpres = 0;
static int tzflag = 0;
if (NULL != tv)
{
GetSystemTimeAsFileTime(&ft);
tmpres |= ft.dwHighDateTime;
tmpres <<= 32;
tmpres |= ft.dwLowDateTime;
tmpres /= 10; /*convert into microseconds*/
/*converting file time to unix epoch*/
tmpres -= 11644473600000000ULL;
tv->tv_sec = (long)(tmpres / 1000000UL);
tv->tv_usec = (long)(tmpres % 1000000UL);
}
if (NULL != tz)
{
if (!tzflag)
{
_tzset();
tzflag++;
}
tz->tz_minuteswest = _timezone / 60;
tz->tz_dsttime = _daylight;
}
return 0;
}
#endif
@<|SystemResources| constructor code@>; @<|SystemResources| constructor code@>;
@<|SystemResources::pageSize| code@>; @<|SystemResources::pageSize| code@>;
@<|SystemResources::physicalPages| code@>; @<|SystemResources::physicalPages| code@>;
@ -83,7 +129,7 @@ void SystemResources::getRUS(double& load_avg, long int& pg_avail,
gettimeofday(&now, NULL); gettimeofday(&now, NULL);
elapsed = now.tv_sec-start.tv_sec + (now.tv_usec-start.tv_usec)*1.0e-6; elapsed = now.tv_sec-start.tv_sec + (now.tv_usec-start.tv_usec)*1.0e-6;
#ifndef __MINGW32__ #if !defined(__MINGW32__) && !defined(_MSC_VER)
struct rusage rus; struct rusage rus;
getrusage(RUSAGE_SELF, &rus); getrusage(RUSAGE_SELF, &rus);
utime = rus.ru_utime.tv_sec+rus.ru_utime.tv_usec*1.0e-6; utime = rus.ru_utime.tv_sec+rus.ru_utime.tv_usec*1.0e-6;
@ -97,7 +143,7 @@ void SystemResources::getRUS(double& load_avg, long int& pg_avail,
majflt = -1; majflt = -1;
#endif #endif
#if !defined(__MINGW32__) && !defined(__CYGWIN32__) #if !defined(__MINGW32__) && !defined(_MSC_VER) && !defined(__CYGWIN32__)
getloadavg(&load_avg, 1); getloadavg(&load_avg, 1);
#else #else
load_avg = -1.0; load_avg = -1.0;
@ -209,7 +255,7 @@ void Journal::printHeader()
(*this)<< "General Public License, see http://www.gnu.org/license/gpl.html\n"; (*this)<< "General Public License, see http://www.gnu.org/license/gpl.html\n";
(*this)<< "\n\n"; (*this)<< "\n\n";
#if !defined(__MINGW32__) #if !defined(__MINGW32__) && !defined(_MSC_VER)
utsname info; utsname info;
uname(&info); uname(&info);
(*this)<< "System info: "; (*this)<< "System info: ";
@ -249,33 +295,13 @@ Number of online processors is not implemented and returns -1, since
Windows kernel32 |GetSystemInfo| call is too complicated. Windows kernel32 |GetSystemInfo| call is too complicated.
@<|sysconf| Win32 implementation@>= @<|sysconf| Win32 implementation@>=
#include <Windows.h>
#define _SC_PAGESIZE 1 #define _SC_PAGESIZE 1
#define _SC_PHYS_PAGES 2 #define _SC_PHYS_PAGES 2
#define _SC_AVPHYS_PAGES 3 #define _SC_AVPHYS_PAGES 3
#define _SC_NPROCESSORS_ONLN 4 #define _SC_NPROCESSORS_ONLN 4
@# @#
struct Win32MemoryStatus {
unsigned long dwLength;
unsigned long dwMemoryLoad;
unsigned int dwTotalPhys;
unsigned int dwAvailPhys;
unsigned int dwTotalPageFile;
unsigned int dwAvailPageFile;
unsigned int dwTotalVirtual;
unsigned int dwAvailVirtual;
Win32MemoryStatus();
};
@#
extern "C" {
void __stdcall GlobalMemoryStatus(Win32MemoryStatus *);
};
@#
Win32MemoryStatus::Win32MemoryStatus()
{
dwLength = sizeof(Win32MemoryStatus);
GlobalMemoryStatus(this);
}
@#
long sysconf(int name) long sysconf(int name)
{ {
switch (name) { switch (name) {
@ -283,12 +309,14 @@ long sysconf(int name)
return 1024; return 1024;
case _SC_PHYS_PAGES:@; case _SC_PHYS_PAGES:@;
{ {
Win32MemoryStatus memstat; MEMORYSTATUS memstat;
GlobalMemoryStatus(&memstat);
return memstat.dwTotalPhys/1024; return memstat.dwTotalPhys/1024;
} }
case _SC_AVPHYS_PAGES:@; case _SC_AVPHYS_PAGES:@;
{ {
Win32MemoryStatus memstat; MEMORYSTATUS memstat;
GlobalMemoryStatus(&memstat);
return memstat.dwAvailPhys/1024; return memstat.dwAvailPhys/1024;
} }
case _SC_NPROCESSORS_ONLN:@; case _SC_NPROCESSORS_ONLN:@;

View File

@ -17,8 +17,12 @@
#include "int_sequence.h" #include "int_sequence.h"
#include <sys/time.h> #ifdef _MSC_VER
#include <stdio.h> # include <Winsock2.h>
#else
# include <sys/time.h>
#endif
#include <cstdio>
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>

View File

@ -10,8 +10,8 @@ This is a simple code defining an exception and two convenience macros.
#ifndef KORD_EXCEPTION_H #ifndef KORD_EXCEPTION_H
#define KORD_EXCEPTION_H #define KORD_EXCEPTION_H
#include <string.h> #include <cstring>
#include <stdio.h> #include <cstdio>
#define KORD_RAISE(mes) \ #define KORD_RAISE(mes) \
throw KordException(__FILE__, __LINE__, mes); throw KordException(__FILE__, __LINE__, mes);

View File

@ -16,7 +16,7 @@ and Geoff Kuenning.
#define MERSENNE_TWISTER_H #define MERSENNE_TWISTER_H
#include "random.h" #include "random.h"
#include <string.h> #include <cstring>
@<|MersenneTwister| class declaration@>; @<|MersenneTwister| class declaration@>;
@<|MersenneTwister| inline method definitions@>; @<|MersenneTwister| inline method definitions@>;

View File

@ -6,7 +6,7 @@
#include "random.h" #include "random.h"
#include <stdlib.h> #include <cstdlib>
#include <limits> #include <limits>
#include <cmath> #include <cmath>
@ -42,7 +42,7 @@ double RandomGenerator::normal()
@<|SystemRandomGenerator::uniform| code@>= @<|SystemRandomGenerator::uniform| code@>=
double SystemRandomGenerator::uniform() double SystemRandomGenerator::uniform()
{ {
#ifndef __MINGW32__ #if !defined(__MINGW32__) && !defined(_MSC_VER)
return drand48(); return drand48();
#else #else
return ((double)rand())/RAND_MAX; return ((double)rand())/RAND_MAX;
@ -53,7 +53,7 @@ double SystemRandomGenerator::uniform()
@<|SystemRandomGenerator::initSeed| code@>= @<|SystemRandomGenerator::initSeed| code@>=
void SystemRandomGenerator::initSeed(int seed) void SystemRandomGenerator::initSeed(int seed)
{ {
#ifndef __MINGW32__ #if !defined(__MINGW32__) && !defined(_MSC_VER)
srand48(seed); srand48(seed);
#else #else
srand(seed); srand(seed);

View File

@ -5,8 +5,8 @@
#include "utils/cc/exception.h" #include "utils/cc/exception.h"
#include "dynamic_atoms.h" #include "dynamic_atoms.h"
#include <string.h> #include <cstring>
#include <limits.h> #include <climits>
using namespace ogp; using namespace ogp;

View File

@ -4,7 +4,7 @@
#include "namelist.h" #include "namelist.h"
#include <string.h> #include <cstring>
using namespace ogp; using namespace ogp;

View File

@ -6,8 +6,7 @@
#include "tree.h" #include "tree.h"
#include <stdlib.h> #include <cstdlib>
#include <math.h>
#include <cmath> #include <cmath>
#include <limits> #include <limits>

View File

@ -10,7 +10,7 @@
#include "planner_builder.h" #include "planner_builder.h"
#include "forw_subst_builder.h" #include "forw_subst_builder.h"
#include <stdlib.h> #include <cstdlib>
#include <string> #include <string>
#include <cmath> #include <cmath>

View File

@ -4,8 +4,8 @@
#include "dynare_params.h" #include "dynare_params.h"
#include <getopt.h> #include <getopt.h>
#include <stdio.h> #include <cstdio>
#include <string.h> #include <cstring>
const char* help_str = const char* help_str =
"usage: dynare++ [--help] [--version] [options] <model file>\n" "usage: dynare++ [--help] [--version] [options] <model file>\n"

View File

@ -7,6 +7,11 @@
#include <cmath> #include <cmath>
#ifdef _MSC_VER
// For _finite()
# include <cfloat>
#endif
using namespace ogu; using namespace ogu;
/** This should not be greater than DBL_EPSILON^(1/2). */ /** This should not be greater than DBL_EPSILON^(1/2). */
@ -32,7 +37,11 @@ double GoldenSectionSearch::search(OneDFunction& f, double x1, double x2)
else else
x = b + dx; x = b + dx;
double fx = f.eval(x); double fx = f.eval(x);
#ifndef _MSC_VER
if (! std::isfinite(fx)) if (! std::isfinite(fx))
#else
if (! _finite(fx))
#endif
return x1; return x1;
if (b-x1 > x2-b) { if (b-x1 > x2-b) {
// x is on the left from b // x is on the left from b
@ -69,7 +78,11 @@ double GoldenSectionSearch::search(OneDFunction& f, double x1, double x2)
bool GoldenSectionSearch::init_bracket(OneDFunction& f, double x1, double& x2, double& b) bool GoldenSectionSearch::init_bracket(OneDFunction& f, double x1, double& x2, double& b)
{ {
double f1 = f.eval(x1); double f1 = f.eval(x1);
#ifndef _MSC_VER
if (! std::isfinite(f1)) if (! std::isfinite(f1))
#else
if (! _finite(f1))
#endif
throw DynareException(__FILE__, __LINE__, throw DynareException(__FILE__, __LINE__,
"Safer point not finite in GoldenSectionSearch::init_bracket"); "Safer point not finite in GoldenSectionSearch::init_bracket");
@ -86,7 +99,11 @@ bool GoldenSectionSearch::init_bracket(OneDFunction& f, double x1, double& x2, d
double bsym = 2*x2 - b; double bsym = 2*x2 - b;
double fbsym = f.eval(bsym); double fbsym = f.eval(bsym);
// now we know that f1, f2, and fb are finite // now we know that f1, f2, and fb are finite
#ifndef _MSC_VER
if (std::isfinite(fbsym)) { if (std::isfinite(fbsym)) {
#else
if (_finite(fbsym)) {
#endif
// we have four numbers f1, fb, f2, fbsym, we test for the // we have four numbers f1, fb, f2, fbsym, we test for the
// following combinations to find the bracket: // following combinations to find the bracket:
// [f1,f2,fbsym], [f1,fb,fbsym] and [f1,fb,fbsym] // [f1,f2,fbsym], [f1,fb,fbsym] and [f1,fb,fbsym]
@ -145,7 +162,11 @@ bool GoldenSectionSearch::search_for_finite(OneDFunction& f, double x1, double&
double f2 = f.eval(x2); double f2 = f.eval(x2);
b = (1-golden)*x1 + golden*x2; b = (1-golden)*x1 + golden*x2;
double fb = f.eval(b); double fb = f.eval(b);
#ifndef _MSC_VER
found = std::isfinite(f2) && std::isfinite(fb); found = std::isfinite(f2) && std::isfinite(fb);
#else
found = _finite(f2) && _finite(fb);
#endif
if (! found) if (! found)
x2 = b; x2 = b;
cnt++; cnt++;

View File

@ -4,8 +4,8 @@
#include "BlockDiagonal.h" #include "BlockDiagonal.h"
#include <stdio.h> #include <cstdio>
#include <string.h> #include <cstring>
BlockDiagonal::BlockDiagonal(const double* d, int d_size) BlockDiagonal::BlockDiagonal(const double* d, int d_size)
: QuasiTriangular(d, d_size), : QuasiTriangular(d, d_size),

View File

@ -9,9 +9,9 @@
#include <dynblas.h> #include <dynblas.h>
#include <dynlapack.h> #include <dynlapack.h>
#include <stdio.h> #include <cstdio>
#include <string.h> #include <cstring>
#include <stdlib.h> #include <cstdlib>
#include <cmath> #include <cmath>
#include <limits> #include <limits>

View File

@ -8,7 +8,7 @@
#include "TriangularSylvester.h" #include "TriangularSylvester.h"
#include "IterativeSylvester.h" #include "IterativeSylvester.h"
#include <time.h> #include <ctime>
GeneralSylvester::GeneralSylvester(int ord, int n, int m, int zero_cols, GeneralSylvester::GeneralSylvester(int ord, int n, int m, int zero_cols,
const double* da, const double* db, const double* da, const double* db,

View File

@ -8,7 +8,7 @@
#include <dynblas.h> #include <dynblas.h>
#include <stdio.h> #include <cstdio>
#include <cmath> #include <cmath>
using namespace std; using namespace std;

View File

@ -7,7 +7,7 @@
#include "SylvMatrix.h" #include "SylvMatrix.h"
#include "SylvException.h" #include "SylvException.h"
#include <stdio.h> #include <cstdio>
QuasiTriangularZero::QuasiTriangularZero(int num_zeros, const double* d, QuasiTriangularZero::QuasiTriangularZero(int num_zeros, const double* d,
int d_size) int d_size)

View File

@ -4,8 +4,8 @@
#include "SylvException.h" #include "SylvException.h"
#include <string.h> #include <cstring>
#include <stdio.h> #include <cstdio>
SylvException::SylvException(const char* f, int l, const SylvException* s) SylvException::SylvException(const char* f, int l, const SylvException* s)
{ {

View File

@ -8,8 +8,8 @@
#include <dynblas.h> #include <dynblas.h>
#include <dynlapack.h> #include <dynlapack.h>
#include <stdio.h> #include <cstdio>
#include <string.h> #include <cstring>
#include <cmath> #include <cmath>
void SylvMatrix::multLeftI(const SqSylvMatrix& m) void SylvMatrix::multLeftI(const SqSylvMatrix& m)

View File

@ -10,9 +10,9 @@
# include <dynmex.h> # include <dynmex.h>
#endif #endif
#include <math.h> #include <cmath>
#include <stdio.h> #include <cstdio>
#include <stdlib.h> #include <cstdlib>
/**********************************************************/ /**********************************************************/
/* SylvMemoryPool */ /* SylvMemoryPool */

View File

@ -5,8 +5,8 @@
#ifndef SYLV_PARAMS_H #ifndef SYLV_PARAMS_H
#define SYLV_PARAMS_H #define SYLV_PARAMS_H
#include <stdio.h> #include <cstdio>
#include <string.h> #include <cstring>
#if defined(MATLAB_MEX_FILE) || defined(OCTAVE_MEX_FILE) #if defined(MATLAB_MEX_FILE) || defined(OCTAVE_MEX_FILE)
# include <dynmex.h> # include <dynmex.h>

View File

@ -7,7 +7,7 @@
#include "KronUtils.h" #include "KronUtils.h"
#include "BlockDiagonal.h" #include "BlockDiagonal.h"
#include <stdio.h> #include <cstdio>
#include <cmath> #include <cmath>
double TriangularSylvester::diag_zero = 1.e-15; double TriangularSylvester::diag_zero = 1.e-15;

View File

@ -9,9 +9,9 @@
#include <dynblas.h> #include <dynblas.h>
#include <stdio.h> #include <cstdio>
#include <string.h> #include <cstring>
#include <stdlib.h> #include <cstdlib>
#include <cmath> #include <cmath>
#include <algorithm> #include <algorithm>
#include <limits> #include <limits>

View File

@ -9,7 +9,7 @@
* to avoid running virtual method invokation mechanism. Some * to avoid running virtual method invokation mechanism. Some
* members, and methods are thus duplicated */ * members, and methods are thus duplicated */
#include <stdio.h> #include <cstdio>
class GeneralMatrix; class GeneralMatrix;
class ConstVector; class ConstVector;

View File

@ -4,8 +4,8 @@
#include "MMMatrix.h" #include "MMMatrix.h"
#include <stdio.h> #include <cstdio>
#include <string.h> #include <cstring>
MMMatrixIn::MMMatrixIn(const char* fname) MMMatrixIn::MMMatrixIn(const char* fname)
{ {

View File

@ -18,9 +18,9 @@
#include "MMMatrix.h" #include "MMMatrix.h"
#include <stdio.h> #include <cstdio>
#include <string.h> #include <cstring>
#include <time.h> #include <ctime>
#include <cmath> #include <cmath>

View File

@ -8,7 +8,7 @@
#include "permutation.h" #include "permutation.h"
#include "tl_exception.h" #include "tl_exception.h"
#include <string.h> #include <cstring>
@<|OrdSequence| method codes@>; @<|OrdSequence| method codes@>;
@<|Equivalence| method codes@>; @<|Equivalence| method codes@>;

View File

@ -6,7 +6,7 @@
@c @c
#include "fine_container.h" #include "fine_container.h"
#include <math.h> #include <cmath>
@<|SizeRefinement| constructor code@>; @<|SizeRefinement| constructor code@>;
@ -21,7 +21,11 @@ SizeRefinement::SizeRefinement(const IntSequence& s, int nc, int max)
int nr = s[i]/max; int nr = s[i]/max;
if (s[i] % max != 0) if (s[i] % max != 0)
nr++; nr++;
#ifndef _MSC_VER
int ss = (nr>0) ? (int)round(((double)s[i])/nr) : 0; int ss = (nr>0) ? (int)round(((double)s[i])/nr) : 0;
#else // MSVC doesn't respect C99 standard and doesn't define round(); use floor(x+0.5) instead
int ss = (nr>0) ? (int)floor((((double)s[i])/nr) + 0.5) : 0;
#endif
for (int j = 0; j < nr - 1; j++) { for (int j = 0; j < nr - 1; j++) {
rsizes.push_back(ss); rsizes.push_back(ss);
ind_map.push_back(i); ind_map.push_back(i);

View File

@ -8,8 +8,8 @@
#include "symmetry.h" #include "symmetry.h"
#include "tl_exception.h" #include "tl_exception.h"
#include <stdio.h> #include <cstdio>
#include <limits.h> #include <climits>
@<|IntSequence| constructor code 1@>; @<|IntSequence| constructor code 1@>;
@<|IntSequence| constructor code 2@>; @<|IntSequence| constructor code 2@>;

View File

@ -30,7 +30,7 @@ some instances do destroy the underlying data, and some not.
#define INT_SEQUENCE_H #define INT_SEQUENCE_H
#include <string.h> #include <cstring>
#include <vector> #include <vector>
using namespace std; using namespace std;

View File

@ -6,7 +6,7 @@
#include "kron_prod.h" #include "kron_prod.h"
#include "tl_exception.h" #include "tl_exception.h"
#include <stdio.h> #include <cstdio>
@<|KronProdDimens| constructor code@>; @<|KronProdDimens| constructor code@>;
@<|KronProd::checkDimForMult| code@>; @<|KronProd::checkDimForMult| code@>;

View File

@ -10,6 +10,11 @@
#include <cmath> #include <cmath>
#ifdef _MSC_VER
// For _finite()
# include <cfloat>
#endif
@<|SparseTensor::insert| code@>; @<|SparseTensor::insert| code@>;
@<|SparseTensor::isFinite| code@>; @<|SparseTensor::isFinite| code@>;
@<|SparseTensor::getFoldIndexFillFactor| code@>; @<|SparseTensor::getFoldIndexFillFactor| code@>;
@ -34,8 +39,13 @@ void SparseTensor::insert(const IntSequence& key, int r, double c)
"Row number out of dimension of tensor in SparseTensor::insert"); "Row number out of dimension of tensor in SparseTensor::insert");
TL_RAISE_IF(key.size() != dimen(), TL_RAISE_IF(key.size() != dimen(),
"Wrong length of key in SparseTensor::insert"); "Wrong length of key in SparseTensor::insert");
#ifndef _MSC_VER
TL_RAISE_IF(! std::isfinite(c), TL_RAISE_IF(! std::isfinite(c),
"Insertion of non-finite value in SparseTensor::insert"); "Insertion of non-finite value in SparseTensor::insert");
#else
TL_RAISE_IF(! _finite(c),
"Insertion of non-finite value in SparseTensor::insert");
#endif
iterator first_pos = m.lower_bound(key); iterator first_pos = m.lower_bound(key);
@<check that pair |key| and |r| is unique@>; @<check that pair |key| and |r| is unique@>;
@ -62,7 +72,11 @@ bool SparseTensor::isFinite() const
bool res = true; bool res = true;
const_iterator run = m.begin(); const_iterator run = m.begin();
while (res && run != m.end()) { while (res && run != m.end()) {
#ifndef _MSC_VER
if (! std::isfinite((*run).second.second)) if (! std::isfinite((*run).second.second))
#else
if (! _finite((*run).second.second))
#endif
res = false; res = false;
++run; ++run;
} }

View File

@ -89,7 +89,7 @@ member of |thread_group| and |detach_thread_group| classes.
# define pthread_cond_t void * # define pthread_cond_t void *
#endif #endif
#include <stdio.h> #include <cstdio>
#include <list> #include <list>
#include <map> #include <map>

View File

@ -7,7 +7,7 @@
#include "symmetry.h" #include "symmetry.h"
#include "permutation.h" #include "permutation.h"
#include <stdio.h> #include <cstdio>
@<|Symmetry| constructor code@>; @<|Symmetry| constructor code@>;
@<|Symmetry::findClass| code@>; @<|Symmetry::findClass| code@>;

View File

@ -15,8 +15,8 @@ for this.
#ifndef TL_EXCEPTION_H #ifndef TL_EXCEPTION_H
#define TL_EXCEPTION_H #define TL_EXCEPTION_H
#include <string.h> #include <cstring>
#include <stdio.h> #include <cstdio>
@<body of tl\_exception header@>; @<body of tl\_exception header@>;

View File

@ -26,7 +26,7 @@ to allow submatrix construction from const reference arguments.
#include "GeneralMatrix.h" #include "GeneralMatrix.h"
#include <stdio.h> #include <cstdio>
class TwoDMatrix; class TwoDMatrix;
@<|ConstTwoDMatrix| class declaration@>; @<|ConstTwoDMatrix| class declaration@>;

View File

@ -4,7 +4,7 @@
#include "factory.h" #include "factory.h"
#include <cstdlib> #include <cstdlib>
#include <math.h> #include <cmath>
void Factory::init(const Symmetry& s, const IntSequence& nvs) void Factory::init(const Symmetry& s, const IntSequence& nvs)
{ {

View File

@ -6,8 +6,8 @@
#include "fs_tensor.h" #include "fs_tensor.h"
#include <cstdlib> #include <cstdlib>
#include <math.h> #include <cmath>
#include <stdio.h> #include <cstdio>
IntGenerator intgen; IntGenerator intgen;

View File

@ -13,9 +13,9 @@
#include "ps_tensor.h" #include "ps_tensor.h"
#include "tl_static.h" #include "tl_static.h"
#include <stdio.h> #include <cstdio>
#include <string.h> #include <cstring>
#include <time.h> #include <ctime>
class TestRunnable { class TestRunnable {

View File

@ -5,8 +5,8 @@
#ifndef OGU_EXCEPTION_H #ifndef OGU_EXCEPTION_H
#define OGU_EXCEPTION_H #define OGU_EXCEPTION_H
#include <stdio.h> #include <cstdio>
#include <string.h> #include <cstring>
#include <string> #include <string>
#include <algorithm> #include <algorithm>
@ -27,7 +27,13 @@ namespace ogu {
strncpy(file, f, file_length-1); strncpy(file, f, file_length-1);
file[file_length-1] = '\0'; file[file_length-1] = '\0';
line = l; line = l;
#ifndef _MSC_VER
strncpy(mes, m, std::min(mes_length-1,(int)strlen(m))); strncpy(mes, m, std::min(mes_length-1,(int)strlen(m)));
#else
/* MSVC doesn't define std::min() (should be in <algorithm>),
but instead has a macro in <windows.h> */
strncpy(mes, m, min(mes_length-1,(int)strlen(m)));
#endif
mes[mes_length-1] = '\0'; mes[mes_length-1] = '\0';
} }
Exception(const char* f, int l, const std::string& m) Exception(const char* f, int l, const std::string& m)
@ -35,7 +41,13 @@ namespace ogu {
strncpy(file, f, file_length-1); strncpy(file, f, file_length-1);
file[file_length-1] = '\0'; file[file_length-1] = '\0';
line = l; line = l;
#ifndef _MSC_VER
strncpy(mes, m.c_str(), std::min(mes_length-1,(int)m.length())); strncpy(mes, m.c_str(), std::min(mes_length-1,(int)m.length()));
#else
/* MSVC doesn't define std::min() (should be in <algorithm>),
but instead has a macro in <windows.h> */
strncpy(mes, m.c_str(), min(mes_length-1,(int)m.length()));
#endif
mes[mes_length-1] = '\0'; mes[mes_length-1] = '\0';
} }
virtual ~Exception() {} virtual ~Exception() {}

View File

@ -4,7 +4,7 @@
#include "memory_file.h" #include "memory_file.h"
#include <stdio.h> #include <cstdio>
using namespace ogu; using namespace ogu;

View File

@ -39,7 +39,11 @@ DynareMxArrayToString(const mxArray *mxFldp, const int len, const int width)
const char ** const char **
DynareMxArrayToString(const char *cNamesCharStr, const int len, const int width) DynareMxArrayToString(const char *cNamesCharStr, const int len, const int width)
{ {
char cNamesMX[len][width+1]; // char **cNamesMX;
cNamesMX = (char **) mxCalloc(len, sizeof(char *));
for(int i = 0; i < len; i++)
cNamesMX[i] = (char *) mxCalloc(width+1, sizeof(char));
#ifdef DEBUG #ifdef DEBUG
mexPrintf("loop DynareMxArrayToString cNamesCharStr = %s \n", cNamesCharStr); mexPrintf("loop DynareMxArrayToString cNamesCharStr = %s \n", cNamesCharStr);
#endif #endif
@ -69,6 +73,7 @@ DynareMxArrayToString(const char *cNamesCharStr, const int len, const int width)
mexPrintf("ret [%d]= %s \n", j, ret[j]); mexPrintf("ret [%d]= %s \n", j, ret[j]);
#endif #endif
} }
mxFree(cNamesMX);
return ret; return ret;
} }

View File

@ -26,10 +26,8 @@
#ifdef _WIN32 #ifdef _WIN32
# include <windows.h> # include <windows.h>
# ifdef K_ORDER_PERTURBATION_EXPORTS # ifdef _MSC_VER
# define K_ORDER_PERTURBATION_API __declspec(dllexport) # define K_ORDER_PERTURBATION_API __declspec(dllexport)
# else
# define K_ORDER_PERTURBATION_API __declspec(dllimport)
# endif # endif
#else #else
# include <dlfcn.h> // unix/linux DLL (.so) handling routines # include <dlfcn.h> // unix/linux DLL (.so) handling routines

View File

@ -24,15 +24,12 @@
#include "k_ord_dynare.h" #include "k_ord_dynare.h"
#include "dynamic_dll.h" #include "dynamic_dll.h"
#include <cmath>
#include <dynmex.h> #include <dynmex.h>
#include "memory_file.h" #include "memory_file.h"
//#include "k_order_perturbation.h"
#ifndef DYNVERSION
# define DYNVERSION "unknown"
#endif
/**************************************************************************************/ /**************************************************************************************/
/* Dynare DynamicModel class */ /* Dynare DynamicModel class */
/**************************************************************************************/ /**************************************************************************************/
@ -345,7 +342,7 @@ KordpDynare::populateDerivativesContainer(TwoDMatrix *g, int ord, const vector<i
{ {
int j = (int)g->get(i,0)-1; // hessian indices start with 1 int j = (int)g->get(i,0)-1; // hessian indices start with 1
int i1 = (int)g->get(i,1) -1; int i1 = (int)g->get(i,1) -1;
int s0 = (int)floor(i1/nJcols); int s0 = (int)floor(((double) i1)/((double) nJcols));
int s1 = i1- (nJcols*s0); int s1 = i1- (nJcols*s0);
if (s0 < nJcols1) if (s0 < nJcols1)
s[0] = revOrder[s0]; s[0] = revOrder[s0];
@ -609,7 +606,7 @@ KordpDynare::ReorderBlocks(TwoDMatrix *tdx, const vector<int> *vOrder)
{ {
// determine order of the matrix // determine order of the matrix
double dbOrder = log(tdx->ncols())/log(nJcols); double dbOrder = log((double) tdx->ncols())/log((double) nJcols);
int ibOrder = (int) dbOrder; int ibOrder = (int) dbOrder;
if ((double) ibOrder != dbOrder || ibOrder > nOrder) if ((double) ibOrder != dbOrder || ibOrder > nOrder)
{ {

View File

@ -45,7 +45,7 @@
#include <cctype> #include <cctype>
#ifdef _MSC_VER //&&WINDOWS #ifdef _MSC_VER
BOOL APIENTRY BOOL APIENTRY
DllMain(HANDLE hModule, DllMain(HANDLE hModule,
@ -74,14 +74,8 @@ fnK_order_perturbation(void)
{ {
return 42; return 42;
} }
// This is the constructor of a class that has been exported.
// see k_order_perturbation.h for the class definition
CK_order_perturbation::CK_order_perturbation()
{
return;
}
#endif // _MSC_VER && WINDOWS #endif // _MSC_VER
#if defined(MATLAB_MEX_FILE) || defined(OCTAVE_MEX_FILE) // exclude mexFunction for other applications #if defined(MATLAB_MEX_FILE) || defined(OCTAVE_MEX_FILE) // exclude mexFunction for other applications
extern "C" { extern "C" {