<commit_before>// Begin CVS Header
//   $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/elementaryFluxModes/CStepMatrix.cpp,v $
//   $Revision: 1.7 $
//   $Name:  $
//   $Author: shoops $
//   $Date: 2009/09/29 16:33:48 $
// End CVS Header

// Copyright (C) 2008 by <NAME>, Virginia Tech Intellectual
// Properties, Inc., EML Research, gGmbH, University of Heidelberg,
// and The University of Manchester.
// All rights reserved.

#include "copasi.h"

#include "CStepMatrix.h"
#include "CStepMatrixColumn.h"

#include "utilities/CMatrix.h"

CStepMatrix::CStepMatrix():
    std::list< CStepMatrixColumn * >(),
    mRows(0),
    mPivot(0),
    mFirstUnconvertedRow(0)
{}

CStepMatrix::CStepMatrix(CMatrix< C_INT32 > & nullspaceMatrix):
    std::list< CStepMatrixColumn * >(),
    mRows(nullspaceMatrix.numRows()),
    mPivot(nullspaceMatrix.numRows()),
    mFirstUnconvertedRow(0)
{
  size_t Cols = nullspaceMatrix.numCols();

  CVector< CStepMatrixColumn * > Columns(Cols);
  CStepMatrixColumn ** pColumn = Columns.array();
  CStepMatrixColumn ** pColumnEnd = pColumn + Cols;

  for (; pColumn != pColumnEnd; ++pColumn)
    {
      *pColumn = new CStepMatrixColumn(mRows);
      push_back(*pColumn);
    }

  size_t i;
  size_t j;
  const C_INT32 * pValue = nullspaceMatrix.array();
  size_t * pPivot = mPivot.array();

  std::vector< size_t > NegativeRows;
  bool hasNegative;
  bool hasPositive;

  for (i = 0; i < mRows; ++i, ++pPivot)
    {
      *pPivot = i;

      hasNegative = false;
      hasPositive = false;

      for (j = 0; j < Cols; ++j, ++pValue)
        {
          if (*pValue > 0.0)
            {
              hasPositive = true;
            }
          else if (*pValue < 0.0)
            {
              hasNegative = true;
            }
        }

      if ((hasNegative && !hasPositive) ||
          (!hasNegative && hasPositive))
        {
          convertRow(i, nullspaceMatrix);
        }
    }

  // We need to add the information of the unconverted rows of nullspace matrix
  // to the columns

  if (nullspaceMatrix.size() != 0)
    {
      pValue = & nullspaceMatrix(mFirstUnconvertedRow, 0);
    }
  else
    {
      pValue = NULL;
    }

  for (i = mFirstUnconvertedRow; i < mRows; ++i)
    {
      pColumn = Columns.array();<commit_msg>Fixed Bug 1322. Fixed crash occuring when the initial step matrix was already completely converted.<commit_after>// Begin CVS Header
//   $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/elementaryFluxModes/CStepMatrix.cpp,v $
//   $Revision: 1.8 $
//   $Name:  $
//   $Author: shoops $
//   $Date: 2009/11/09 16:37:28 $
// End CVS Header

// Copyright (C) 2008 by <NAME>, Virginia Tech Intellectual
// Properties, Inc., EML Research, gGmbH, University of Heidelberg,
// and The University of Manchester.
// All rights reserved.

#include "copasi.h"

#include "CStepMatrix.h"
#include "CStepMatrixColumn.h"

#include "utilities/CMatrix.h"

CStepMatrix::CStepMatrix():
    std::list< CStepMatrixColumn * >(),
    mRows(0),
    mPivot(0),
    mFirstUnconvertedRow(0)
{}

CStepMatrix::CStepMatrix(CMatrix< C_INT32 > & nullspaceMatrix):
    std::list< CStepMatrixColumn * >(),
    mRows(nullspaceMatrix.numRows()),
    mPivot(nullspaceMatrix.numRows()),
    mFirstUnconvertedRow(0)
{
  size_t Cols = nullspaceMatrix.numCols();

  CVector< CStepMatrixColumn * > Columns(Cols);
  CStepMatrixColumn ** pColumn = Columns.array();
  CStepMatrixColumn ** pColumnEnd = pColumn + Cols;

  for (; pColumn != pColumnEnd; ++pColumn)
    {
      *pColumn = new CStepMatrixColumn(mRows);
      push_back(*pColumn);
    }

  size_t i;
  size_t j;
  const C_INT32 * pValue = nullspaceMatrix.array();
  size_t * pPivot = mPivot.array();

  std::vector< size_t > NegativeRows;
  bool hasNegative;
  bool hasPositive;

  for (i = 0; i < mRows; ++i, ++pPivot)
    {
      *pPivot = i;

      hasNegative = false;
      hasPositive = false;

      for (j = 0; j < Cols; ++j, ++pValue)
        {
          if (*pValue > 0.0)
            {
              hasPositive = true;
            }
          else if (*pValue < 0.0)
            {
              hasNegative = true;
            }
        }

      if ((hasNegative && !hasPositive) ||
          (!hasNegative && hasPositive))
        {
          convertRow(i, nullspaceMatrix);
        }
    }

  // We need to add the information of the unconverted rows of nullspace matrix
  // to the columns

  if (nullspaceMatrix.size() != 0 &&
      mFirstUnconvertedRow < mRows)
    {
      pValue = & nullspaceMatrix(mFirstUnconvertedRow, 0);
    }
  else
    {
      pValue = NULL;
    }

  for (i = mFirstUnconvertedRow; i < mRows; ++i)
    {
      pColumn = Columns.array();
{'fraction_non_alphanumeric': 0.1338599487617421, 'fraction_numerical': 0.016225448334756618, 'mean_word_length': 2.5411942554799696, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2754641', 'n_tokens_mistral': 1718, 'n_tokens_neox': 1615, 'n_words': 361}