Skip to content

Commit

Permalink
Merge pull request #1005 from sys-bio/fix-stoich
Browse files Browse the repository at this point in the history
Fix the getStoichiometryMatrix function from the C API.
  • Loading branch information
luciansmith committed May 17, 2022
2 parents f0340e3 + f73581e commit 65e6322
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
18 changes: 18 additions & 0 deletions test/c_api_core/CAPICoreTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,5 +427,23 @@ TEST_F(CAPICoreTest, CheckSetSteadyStateSelectionListEx) {
}


delete rrH;
}

TEST_F(CAPICoreTest, CheckGetStoichiometryMatrix) {

RRHandle rrH = createRRInstance();
EXPECT_TRUE(loadSBMLFromFileE(rrH, (cAPICoreModelsDir / path("steadystate.xml")).string().c_str(), true));

RRDoubleMatrixPtr stoichs = getStoichiometryMatrix(rrH);
ASSERT_EQ(stoichs->CSize, 2);
ASSERT_EQ(stoichs->RSize, 2);
stoichs->Data;
EXPECT_EQ(stoichs->Data[0], -1.0);
EXPECT_EQ(stoichs->Data[1], 1.0);
EXPECT_EQ(stoichs->Data[2], 1.0);
EXPECT_EQ(stoichs->Data[3], -1.0);


delete rrH;
}
24 changes: 2 additions & 22 deletions wrappers/C/rrc_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -859,28 +859,8 @@ RRDoubleMatrixPtr rrcCallConv getStoichiometryMatrix(RRHandle handle)
{
start_try
RoadRunner* rri = castToRoadRunner(handle);
ExecutableModel* model = rri->getModel();

if(model)
{
int rows = 0;
int cols = 0;

RRDoubleMatrixPtr matrix = new RRDoubleMatrix;
DoubleMatrix full_stoich = rri->getFullStoichiometryMatrix();

matrix->RSize = full_stoich.numRows();
matrix->CSize = full_stoich.numCols();
matrix->Data = new double[rows*cols];

memcpy(matrix->Data, full_stoich.GetPointer(), rows*cols*sizeof(double));

return matrix;
}
else
{
return 0;
}
DoubleMatrix tempMat = rri->getFullStoichiometryMatrix();
return createMatrix(&tempMat);
catch_ptr_macro
}

Expand Down

0 comments on commit 65e6322

Please sign in to comment.