Skip to content

Commit

Permalink
Add .getrow() and .getcolumn() to expression object
Browse files Browse the repository at this point in the history
  • Loading branch information
halbux committed Mar 2, 2019
1 parent 55291cc commit aababef
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/expression/expression.cpp
Expand Up @@ -206,6 +206,44 @@ expression::expression(expression condexpr, expression exprtrue, expression expr
}
}

expression expression::getrow(int rownum)
{
if (rownum < 0 || rownum >= mynumrows)
{
std::cout << "Error in 'expression object': cannot get row " << rownum << " in a " << mynumrows << "x" << mynumcols << " expression" << std::endl;
abort();
}

expression output;
output.mynumrows = 1;
output.mynumcols = mynumcols;
output.myoperations.resize(mynumcols);

for (int i = 0; i < mynumcols; i++)
output.myoperations[i] = myoperations[rownum*mynumcols+i];

return output;
}

expression expression::getcolumn(int colnum)
{
if (colnum < 0 || colnum >= mynumcols)
{
std::cout << "Error in 'expression object': cannot get column " << colnum << " in a " << mynumrows << "x" << mynumcols << " expression" << std::endl;
abort();
}

expression output;
output.mynumrows = mynumrows;
output.mynumcols = 1;
output.myoperations.resize(mynumrows);

for (int i = 0; i < mynumrows; i++)
output.myoperations[i] = myoperations[i*mynumcols+colnum];

return output;
}

void expression::reorderrows(std::vector<int> neworder)
{
if (mynumrows != neworder.size())
Expand Down
4 changes: 4 additions & 0 deletions src/expression/expression.h
Expand Up @@ -83,6 +83,10 @@ class expression
int countrows(void) { return mynumrows; };
int countcolumns(void) { return mynumcols; };

// Get a given row/column in a matrix expression:
expression getrow(int rownum);
expression getcolumn(int colnum);

void reorderrows(std::vector<int> neworder);
void reordercolumns(std::vector<int> neworder);

Expand Down

0 comments on commit aababef

Please sign in to comment.