Commit 2493322c authored by george's avatar george
Browse files

Update: Compiles and links but does not work yet

git-svn-id: https://www.dynare.org/svn/dynare/dynare_v4@2285 ac1d8469-bf42-47a9-8791-bf33cf982152
parent 9961492f
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#if !defined(AFX_STDAFX_H__6D080F4C_4FEB_4290_90B5_6943DFBBE92A__INCLUDED_)
#define AFX_STDAFX_H__6D080F4C_4FEB_4290_90B5_6943DFBBE92A__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// Insert your headers here
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <windows.h>
#endif // _MSC_VER > 1000
// TODO: reference additional headers your program requires here
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
//#endif // !defined(AFX_STDAFX_H__6D080F4C_4FEB_4290_90B5_6943DFBBE92A__INCLUDED_)
......@@ -213,6 +213,37 @@ void KordpDynare::calcDerivatives(const Vector& yy, const Vector& xx)
md.clear();
md.insert(&mdTi);
}
void KordpDynare::calcDerivatives(const Vector& yy, ogu::Jacobian& jacob)
{
// ConstVector yym(yy, nstat(), nys());
// ConstVector yyp(yy, nstat()+npred(), nyss());
// Vector yyp(yy, nstat()+npred(), nyss());
//double *g1, *g2;
TwoDMatrix * jj= &jacob;
Vector& out= *(new Vector(nY));
Vector& xx= *(new Vector(nExog));
dynamicDLL.eval( yy, xx, //int nb_row_x,
params, //int it_,
out, jj, NULL);
// model derivatives FSSparseTensor instance
FSSparseTensor mdTi=*(new FSSparseTensor (1, jj->ncols(),jj->nrows()));
for (int i = 0; i<jj->ncols(); i++){
for (int j = 0; j<jj->nrows(); j++){
if (jj->get(i,j)!=0.0) // populate sparse if not zero
mdTi.insert(i, j, jj->get(i,j));
}
}
// md container
// md=*(new TensorContainer<FSSparseTensor>(1));
md.clear();
md.insert(&mdTi);
delete &out;
delete &xx;
}
void KordpDynare::calcDerivativesAtSteady()
{
Vector xx(nexog());
......
......@@ -190,7 +190,8 @@ public:
void evaluateSystem(Vector& out, const Vector& yym, const Vector& yy,
const Vector& yyp, const Vector& xx);
void calcDerivatives(const Vector& yy, const Vector& xx);
void calcDerivatives(const Vector& yy, const TwoDMatrix& xx);
//void calcDerivatives(const Vector& yy, TwoDMatrix& jj);
void calcDerivatives(const Vector& yy, ogu::Jacobian& jacob);
void calcDerivativesAtSteady();
DynamicModelDLL& dynamicDLL;
/// void writeMat4(FILE* fd, const char* prefix) const;
......
......@@ -358,7 +358,7 @@ DynamicModelDLL::DynamicModelDLL(const char * modName, const int jcols,
mexPrintf("MexPrintf: Call GetProcAddress %s .\n", fName);
Dynamic = (DynamicFn *) ::GetProcAddress(dynamicHinstance,"Dynamic");
# else // linux
# else // __linux__
void *dynamicHinstance = dlopen(strcat(fNname,"_dynamic.so"), RTLD_NOW);
if((dynamicHinstance == NULL) || dlerr()){
......@@ -440,7 +440,6 @@ void DynamicModelDLL::eval(const Vector&y, const TwoDMatrix&x, const Vector* mo
double *dresidual, *dg1=NULL, *dg2=NULL;
int length=y.length();
const TwoDMatrix&mx = *(new const TwoDMatrix(it_+1, nExog));
if (residual.length()<length){ // dummy or insufficient
Vector*tempv= new Vector(length );
residual=*tempv;
......@@ -463,7 +462,7 @@ void DynamicModelDLL::eval(const Vector&y, const TwoDMatrix&x, const Vector* mo
dresidual=const_cast<double*>(residual.base());
double *dy=const_cast<double*>(y.base());
double *dx=const_cast<double*>(mx.base());
double *dx=const_cast<double*>(x.base());
double *dbParams=const_cast<double*>(modParams->base());
try{
......@@ -484,3 +483,14 @@ void DynamicModelDLL::eval(const Vector&y, const TwoDMatrix&x, const Vector * mo
eval(y, x, modParams, nMax_lag, residual, g1, g2);
};
void DynamicModelDLL::eval(const Vector&y, const Vector&x, const Vector * modParams,
Vector&residual, TwoDMatrix*g1, TwoDMatrix*g2){
/** ignore given exogens and create new 2D x matrix since
* when calling <model>_dynamic(z,x,params,it_) x must be equal to
* zeros(M_.maximum_lag+1,M_.exo_nbr)
**/
const TwoDMatrix&mx = *(new const TwoDMatrix(nMax_lag+1, nExog));
eval(y, mx, modParams, nMax_lag, residual, g1, g2);
};
......@@ -93,14 +93,12 @@ public:
};
void eval(const Vector&y, const Vector&x, const Vector* params,
Vector&residual, TwoDMatrix*g1, TwoDMatrix*g2);
void eval(const Vector&y, const Vector&x, Vector* params,
Vector&residual, TwoDMatrix*g1, TwoDMatrix*g2);
void eval(const Vector&y, const TwoDMatrix&x, const Vector* params,
int it_, Vector&residual, TwoDMatrix*g1, TwoDMatrix*g2);
void eval(const Vector&y, const TwoDMatrix&x, const Vector* params,
Vector& residual, TwoDMatrix *g1, TwoDMatrix *g2);
void eval(const Vector&y, const TwoDMatrix&x, const Vector* params,
Vector& residual, double *g1, double *g2);
// void eval(const Vector&y, const TwoDMatrix&x, const Vector* params,
// Vector& residual, double *g1, double *g2);
// close DLL: If the referenced object was successfully closed,
// close() returns 0, non 0 otherwise
int close();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment