Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
dynare
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Johannes Pfeifer
dynare
Commits
331a2739
Verified
Commit
331a2739
authored
Nov 08, 2018
by
Sébastien Villemot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix another memory leak in k-order DLL
Re
#1490
.
parent
50a09a68
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
18 deletions
+18
-18
mex/sources/k_order_perturbation/dynamic_abstract_class.cc
mex/sources/k_order_perturbation/dynamic_abstract_class.cc
+15
-15
mex/sources/k_order_perturbation/dynamic_abstract_class.hh
mex/sources/k_order_perturbation/dynamic_abstract_class.hh
+1
-1
mex/sources/k_order_perturbation/dynamic_m.cc
mex/sources/k_order_perturbation/dynamic_m.cc
+2
-2
No files found.
mex/sources/k_order_perturbation/dynamic_abstract_class.cc
View file @
331a2739
...
@@ -33,40 +33,40 @@ DynamicModelAC::copyDoubleIntoTwoDMatData(double *dm, TwoDMatrix *tdm, int rows,
...
@@ -33,40 +33,40 @@ DynamicModelAC::copyDoubleIntoTwoDMatData(double *dm, TwoDMatrix *tdm, int rows,
tdm
->
get
(
i
,
j
)
=
dm
[
dmIdx
++
];
tdm
->
get
(
i
,
j
)
=
dm
[
dmIdx
++
];
}
}
double
*
void
DynamicModelAC
::
unpackSparseMatrix
(
mxArray
*
sparseMat
)
DynamicModelAC
::
unpackSparseMatrix
AndCopyIntoTwoDMatData
(
mxArray
*
sparseMat
,
TwoDMatrix
*
tdm
)
{
{
int
totalCols
=
mxGetN
(
sparseMat
);
int
totalCols
=
mxGetN
(
sparseMat
);
mwIndex
*
rowIdxVector
=
mxGetIr
(
sparseMat
);
mwIndex
*
rowIdxVector
=
mxGetIr
(
sparseMat
);
mwSize
sizeRowIdxVector
=
mxGetNzmax
(
sparseMat
);
mwSize
sizeRowIdxVector
=
mxGetNzmax
(
sparseMat
);
mwIndex
*
colIdxVector
=
mxGetJc
(
sparseMat
);
mwIndex
*
colIdxVector
=
mxGetJc
(
sparseMat
);
assert
(
tdm
->
ncols
()
==
3
);
assert
(
tdm
->
nrows
()
==
sizeRowIdxVector
);
double
*
ptr
=
mxGetPr
(
sparseMat
);
double
*
ptr
=
mxGetPr
(
sparseMat
);
double
*
newMat
=
(
double
*
)
malloc
(
sizeRowIdxVector
*
3
*
sizeof
(
double
));
int
rind
=
0
;
int
rind
=
0
;
int
retvalind0
=
0
;
int
output_row
=
0
;
int
retvalind1
=
sizeRowIdxVector
;
int
retvalind2
=
sizeRowIdxVector
*
2
;
for
(
int
i
=
0
;
i
<
totalCols
;
i
++
)
for
(
int
i
=
0
;
i
<
totalCols
;
i
++
)
for
(
int
j
=
0
;
j
<
(
int
)
(
colIdxVector
[
i
+
1
]
-
colIdxVector
[
i
]);
j
++
,
rind
++
)
for
(
int
j
=
0
;
j
<
(
int
)
(
colIdxVector
[
i
+
1
]
-
colIdxVector
[
i
]);
j
++
,
rind
++
)
{
{
newMat
[
retvalind0
++
]
=
rowIdxVector
[
rind
]
+
1
;
tdm
->
get
(
output_row
,
0
)
=
rowIdxVector
[
rind
]
+
1
;
newMat
[
retvalind1
++
]
=
i
+
1
;
tdm
->
get
(
output_row
,
1
)
=
i
+
1
;
newMat
[
retvalind2
++
]
=
ptr
[
rind
];
tdm
->
get
(
output_row
,
2
)
=
ptr
[
rind
];
output_row
++
;
}
}
/* If there are less elements than Nzmax (that might happen if some
/* If there are less elements than Nzmax (that might happen if some
derivative is symbolically not zero but numerically zero at the evaluation
derivative is symbolically not zero but numerically zero at the evaluation
point), then fill in the matrix with empty entries, that will be
point), then fill in the matrix with empty entries, that will be
recognized as such by KordpDynare::populateDerivativesContainer() */
recognized as such by KordpDynare::populateDerivativesContainer() */
while
(
retvalind0
<
(
int
)
sizeRowIdxVector
)
while
(
output_row
<
(
int
)
sizeRowIdxVector
)
{
{
newMat
[
retvalind0
++
]
=
0
;
tdm
->
get
(
output_row
,
0
)
=
0
;
newMat
[
retvalind1
++
]
=
0
;
tdm
->
get
(
output_row
,
1
)
=
0
;
newMat
[
retvalind2
++
]
=
0
;
tdm
->
get
(
output_row
,
2
)
=
0
;
output_row
++
;
}
}
return
newMat
;
}
}
mex/sources/k_order_perturbation/dynamic_abstract_class.hh
View file @
331a2739
...
@@ -26,7 +26,7 @@ class DynamicModelAC
...
@@ -26,7 +26,7 @@ class DynamicModelAC
{
{
public:
public:
virtual
~
DynamicModelAC
()
=
default
;
virtual
~
DynamicModelAC
()
=
default
;
static
double
*
unpackSparseMatrix
(
mxArray
*
sparseMatrix
);
static
void
unpackSparseMatrixAndCopyIntoTwoDMatData
(
mxArray
*
sparseMat
,
TwoDMatrix
*
tdm
);
static
void
copyDoubleIntoTwoDMatData
(
double
*
dm
,
TwoDMatrix
*
tdm
,
int
rows
,
int
cols
);
static
void
copyDoubleIntoTwoDMatData
(
double
*
dm
,
TwoDMatrix
*
tdm
,
int
rows
,
int
cols
);
virtual
void
eval
(
const
Vector
&
y
,
const
Vector
&
x
,
const
Vector
&
params
,
const
Vector
&
ySteady
,
virtual
void
eval
(
const
Vector
&
y
,
const
Vector
&
x
,
const
Vector
&
params
,
const
Vector
&
ySteady
,
Vector
&
residual
,
TwoDMatrix
*
g1
,
TwoDMatrix
*
g2
,
TwoDMatrix
*
g3
)
noexcept
(
false
)
=
0
;
Vector
&
residual
,
TwoDMatrix
*
g1
,
TwoDMatrix
*
g2
,
TwoDMatrix
*
g3
)
noexcept
(
false
)
=
0
;
...
...
mex/sources/k_order_perturbation/dynamic_m.cc
View file @
331a2739
...
@@ -48,9 +48,9 @@ DynamicModelMFile::eval(const Vector &y, const Vector &x, const Vector &modParam
...
@@ -48,9 +48,9 @@ DynamicModelMFile::eval(const Vector &y, const Vector &x, const Vector &modParam
residual
=
Vector
(
mxGetPr
(
plhs
[
0
]),
residual
.
skip
(),
(
int
)
mxGetM
(
plhs
[
0
]));
residual
=
Vector
(
mxGetPr
(
plhs
[
0
]),
residual
.
skip
(),
(
int
)
mxGetM
(
plhs
[
0
]));
copyDoubleIntoTwoDMatData
(
mxGetPr
(
plhs
[
1
]),
g1
,
(
int
)
mxGetM
(
plhs
[
1
]),
(
int
)
mxGetN
(
plhs
[
1
]));
copyDoubleIntoTwoDMatData
(
mxGetPr
(
plhs
[
1
]),
g1
,
(
int
)
mxGetM
(
plhs
[
1
]),
(
int
)
mxGetN
(
plhs
[
1
]));
if
(
g2
!=
nullptr
)
if
(
g2
!=
nullptr
)
copyDoubleIntoTwoDMatData
(
unpackSparseMatrix
(
plhs
[
2
]),
g2
,
(
int
)
mxGetNzmax
(
plhs
[
2
]),
3
);
unpackSparseMatrixAndCopyIntoTwoDMatData
(
plhs
[
2
],
g2
);
if
(
g3
!=
nullptr
)
if
(
g3
!=
nullptr
)
copyDoubleIntoTwoDMatData
(
unpackSparseMatrix
(
plhs
[
3
]),
g3
,
(
int
)
mxGetNzmax
(
plhs
[
3
]),
3
);
unpackSparseMatrixAndCopyIntoTwoDMatData
(
plhs
[
3
],
g
3
);
for
(
int
i
=
0
;
i
<
nrhs_dynamic
;
i
++
)
for
(
int
i
=
0
;
i
<
nrhs_dynamic
;
i
++
)
mxDestroyArray
(
prhs
[
i
]);
mxDestroyArray
(
prhs
[
i
]);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment