<commit_before>/* Begin CVS Header
   $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/utilities/CAnnotatedMatrix.cpp,v $
   $Revision: 1.5 $
   $Name:  $
   $Author: ssahle $ 
   $Date: 2005/11/09 16:23:12 $
   End CVS Header */

#include "CAnnotatedMatrix.h"
#include "report/CKeyFactory.h"

CCopasiArray::CCopasiArray()
    : mDim(0) {}

CCopasiArray::CCopasiArray(const index_type & sizes)
{
  resize(sizes);
}

void CCopasiArray::resize(const index_type & sizes)
{
  mDim = sizes.size();
  mSizes = sizes;
  mFactors.resize(mDim);

  unsigned int tmpDataSize = 1;
  index_type::const_reverse_iterator it, itEnd = sizes.rend();
  index_type::reverse_iterator itFaktor;
  for (it = sizes.rbegin(), itFaktor = mFactors.rbegin(); it != itEnd; ++it, ++itFaktor)
    {
      *itFaktor = tmpDataSize;
      tmpDataSize *= *it;
    }
  mData.resize(tmpDataSize);
}

CCopasiArray::data_type & CCopasiArray::operator[] (const index_type & index)
{
#ifdef COPASI_DEBUG
  assert(index.size() == mDim);
#endif

  unsigned int tmpindex = 0;
  index_type::const_iterator itIndex, it, itEnd = mFactors.end();
  for (itIndex = index.begin(), it = mFactors.begin(); it != itEnd; ++it, ++itIndex)
    tmpindex += *itIndex * *it;

  return mData[tmpindex];
}

const CCopasiArray::data_type & CCopasiArray::operator[] (const index_type & index) const
  {
#ifdef COPASI_DEBUG
    assert(index.size() == mDim);
#endif

    unsigned int tmpindex = 0;
    index_type::const_iterator itIndex, it, itEnd = mFactors.end();
    for (itIndex = index.begin(), it = mFactors.begin(); it != itEnd; ++it, ++itIndex)
      tmpindex += *itIndex * *it;

    return mData[tmpindex];
  }

//
//*******************************************************

CCopasiMatrixInterface::CCopasiMatrixInterface(CMatrix<C_FLOAT64> * matrix)
    : mMatrix(matrix)
{
  assert(mMatrix);
  mSizes.resize(2);
  mSizes[0] = mMatrix->numRows();
  mSizes[1] = mMatrix->numCols();
}

void CCopasiMatrixInterface::resize(const index_type & sizes)
{
  assert(sizes.size() == 2);
  mSizes = sizes;
  mMatrix->resize(mSizes[0], mSizes[1]);
}

CCopasiArray::data_type & CCopasiMatrixInterface::operator[] (const index_type & index)
{
#ifdef COPASI_DEBUG
  assert(index.size() == 2);
#endif
  return (*mMatrix)(index[0], index[1]);
}

const CCopasiArray::data_type & CCopasiMatrixInterface::operator[] (const index_type & index) const
  {
#ifdef COPASI_DEBUG
    assert(index.size() == 2);
#endif
    return (*mMatrix)(index[0], index[1]);
  }

//
//*******************************************************

CArrayAnnotation::CArrayAnnotation(const std::string & name,
                                   const CCopasiContainer * pParent,
                                   CCopasiAbstractArray * array)
    : CCopasiContainer(name, pParent, "Array" /*, flags */),   //TODO: flags
    mArray(array)
{
  assert(mArray);

  resizeAnnotations();
}

unsigned int CArrayAnnotation::dimensionality() const
  {
    if (mOnTheFly)
      return mArray->dimensionality();
    else
      return mAnnotations.size();
  }

const std::vector<CRegisteredObjectName> & CArrayAnnotation::getAnnotations(unsigned int d)
{
  if (mOnTheFly)
    updateAnnotations();

  return mAnnotations[d];
}

void CArrayAnnotation::setAnnotation(unsigned int d, unsigned int i, const std::string cn)
{
  assert(d < mAnnotations.size());
  assert(i < mAnnotations[d].size());

  mAnnotations[d][i] = s;
}

const std::string & CArrayAnnotation::getDimensionDescription(unsigned int d)
{
  if (mOnTheFly)<commit_msg>fixed typo<commit_after>/* Begin CVS Header
   $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/utilities/CAnnotatedMatrix.cpp,v $
   $Revision: 1.6 $
   $Name:  $
   $Author: ssahle $ 
   $Date: 2005/11/09 16:27:43 $
   End CVS Header */

#include "CAnnotatedMatrix.h"
#include "report/CKeyFactory.h"

CCopasiArray::CCopasiArray()
    : mDim(0) {}

CCopasiArray::CCopasiArray(const index_type & sizes)
{
  resize(sizes);
}

void CCopasiArray::resize(const index_type & sizes)
{
  mDim = sizes.size();
  mSizes = sizes;
  mFactors.resize(mDim);

  unsigned int tmpDataSize = 1;
  index_type::const_reverse_iterator it, itEnd = sizes.rend();
  index_type::reverse_iterator itFaktor;
  for (it = sizes.rbegin(), itFaktor = mFactors.rbegin(); it != itEnd; ++it, ++itFaktor)
    {
      *itFaktor = tmpDataSize;
      tmpDataSize *= *it;
    }
  mData.resize(tmpDataSize);
}

CCopasiArray::data_type & CCopasiArray::operator[] (const index_type & index)
{
#ifdef COPASI_DEBUG
  assert(index.size() == mDim);
#endif

  unsigned int tmpindex = 0;
  index_type::const_iterator itIndex, it, itEnd = mFactors.end();
  for (itIndex = index.begin(), it = mFactors.begin(); it != itEnd; ++it, ++itIndex)
    tmpindex += *itIndex * *it;

  return mData[tmpindex];
}

const CCopasiArray::data_type & CCopasiArray::operator[] (const index_type & index) const
  {
#ifdef COPASI_DEBUG
    assert(index.size() == mDim);
#endif

    unsigned int tmpindex = 0;
    index_type::const_iterator itIndex, it, itEnd = mFactors.end();
    for (itIndex = index.begin(), it = mFactors.begin(); it != itEnd; ++it, ++itIndex)
      tmpindex += *itIndex * *it;

    return mData[tmpindex];
  }

//
//*******************************************************

CCopasiMatrixInterface::CCopasiMatrixInterface(CMatrix<C_FLOAT64> * matrix)
    : mMatrix(matrix)
{
  assert(mMatrix);
  mSizes.resize(2);
  mSizes[0] = mMatrix->numRows();
  mSizes[1] = mMatrix->numCols();
}

void CCopasiMatrixInterface::resize(const index_type & sizes)
{
  assert(sizes.size() == 2);
  mSizes = sizes;
  mMatrix->resize(mSizes[0], mSizes[1]);
}

CCopasiArray::data_type & CCopasiMatrixInterface::operator[] (const index_type & index)
{
#ifdef COPASI_DEBUG
  assert(index.size() == 2);
#endif
  return (*mMatrix)(index[0], index[1]);
}

const CCopasiArray::data_type & CCopasiMatrixInterface::operator[] (const index_type & index) const
  {
#ifdef COPASI_DEBUG
    assert(index.size() == 2);
#endif
    return (*mMatrix)(index[0], index[1]);
  }

//
//*******************************************************

CArrayAnnotation::CArrayAnnotation(const std::string & name,
                                   const CCopasiContainer * pParent,
                                   CCopasiAbstractArray * array)
    : CCopasiContainer(name, pParent, "Array" /*, flags */),    //TODO: flags
    mArray(array)
{
  assert(mArray);

  resizeAnnotations();
}

unsigned int CArrayAnnotation::dimensionality() const
  {
    if (mOnTheFly)
      return mArray->dimensionality();
    else
      return mAnnotations.size();
  }

const std::vector<CRegisteredObjectName> & CArrayAnnotation::getAnnotations(unsigned int d)
{
  if (mOnTheFly)
    updateAnnotations();

  return mAnnotations[d];
}

void CArrayAnnotation::setAnnotation(unsigned int d, unsigned int i, const std::string cn)
{
  assert(d < mAnnotations.size());
  assert(i < mAnnotations[d].size());

  mAnnotations[d][i] = cn;
}

const std::string & CArrayAnnotation::getDimensionDescription(unsigned int d)
{
  if (mOnTheFly)
{'fraction_non_alphanumeric': 0.17454235845040442, 'fraction_numerical': 0.009649496239534554, 'mean_word_length': 4.224610822831727, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1196918', 'n_tokens_mistral': 2502, 'n_tokens_neox': 2442, 'n_words': 472}