Ejemplo n.º 1
0
CDataArray::name_index_type CDataArray::displayNamesToCN(const std::vector< std::string > & DisplayNames) const
{
  assert(DisplayNames.size() == dimensionality()
         || dimensionality() == 0);

  name_index_type CNIndex(dimensionality());
  name_index_type::iterator to = CNIndex.begin();
  std::vector< std::string >::const_iterator it = DisplayNames.begin();
  std::vector< std::string >::const_iterator end = DisplayNames.end();
  std::vector< std::vector<CRegisteredCommonName> >::const_iterator itCNs = mAnnotationsCN.begin();
  size_t dimension = 0;

  for (; it != end && dimension < dimensionality(); ++it, ++itCNs, ++dimension, ++to)
    {
      std::vector<CRegisteredCommonName>::const_iterator itCN = itCNs->begin();
      std::vector<CRegisteredCommonName>::const_iterator endCN = itCNs->end();

      for (; itCN != endCN; ++itCN)
        {
          if (CCommonName::unescape(*it) == createDisplayName(*itCN))
            {
              *to = *itCN;
              break;
            }
        }

      if (itCN == endCN)
        {
          size_t index = C_INVALID_INDEX;
          bool ValidIndex = strToIndex(*it, index);

          if (ValidIndex)
            {
              if (itCNs->empty())
                {
                  *to = *it;
                }
              else
                {
                  *to = itCNs->operator [](index);
                }
            }
          else
            {
              *to = std::string("not found");
            }
        }
    }

  return CNIndex;
}
Ejemplo n.º 2
0
CArrayAnnotation::index_type CArrayAnnotation::cnToIndex(const CArrayAnnotation::name_index_type & cnIndex) const
{
  index_type Index(dimensionality(), C_INVALID_INDEX);

  if (cnIndex.size() != Index.size())
    {
      return Index;
    }

  index_type::iterator to = Index.begin();
  std::vector< CRegisteredObjectName >::const_iterator it = cnIndex.begin();
  std::vector< CRegisteredObjectName >::const_iterator itEnd = cnIndex.end();
  std::vector< std::vector<CRegisteredObjectName> >::const_iterator itCNs = mAnnotationsCN.begin();
  size_t index = 0;

  for (; it != itEnd; ++it, ++itCNs, ++to)
    {
      std::vector<CRegisteredObjectName>::const_iterator itCN = itCNs->begin();
      std::vector<CRegisteredObjectName>::const_iterator endCN = itCNs->end();

      size_t index = 0;

      for (; itCN != endCN; ++itCN, ++index)
        {
          if (*it == *itCN) break;
        }

      *to = index;
    }

  return Index;
}
Coordinates2DGeographic::Coordinates2DGeographic(const std::vector<double>& coords) {
    uassert(0,
            "Number of elements in coords must match dimensionality of coordinate type",
            coords.size() == dimensionality());
    _longitude = coords[0];
    _latitude = coords[1];
}
Ejemplo n.º 4
0
void CArrayAnnotation::setAnnotationString(size_t d, size_t i, const std::string s)
{
  assert(d < dimensionality());
  assert(i < mAnnotationsString[d].size());

  mAnnotationsCN[d][i] = "String=" + s;
  mAnnotationsString[d][i] = s;
}
Ejemplo n.º 5
0
void CDataArray::setAnnotationString(size_t d, size_t i, const std::string s)
{
  assert(d < dimensionality());
  assert(i < mAnnotationsString[d].size());

  mAnnotationsCN[d][i] = "String=" + CCommonName::escape(s);
  mAnnotationsString[d][i] = s;
}
Ejemplo n.º 6
0
CArrayAnnotation::name_index_type CArrayAnnotation::displayNamesToCN(const std::vector< std::string > & DisplayNames) const
{
  assert(DisplayNames.size() == dimensionality()
         || dimensionality() == 0);

  name_index_type CNIndex(dimensionality());
  name_index_type::iterator to = CNIndex.begin();
  std::vector< std::string >::const_iterator it = DisplayNames.begin();
  std::vector< std::string >::const_iterator end = DisplayNames.end();
  std::vector< std::vector<CRegisteredObjectName> >::const_iterator itCNs = mAnnotationsCN.begin();
  size_t index = 0;

  for (; it != end && index < dimensionality(); ++it, ++itCNs, ++index, ++to)
    {
      std::vector<CRegisteredObjectName>::const_iterator itCN = itCNs->begin();
      std::vector<CRegisteredObjectName>::const_iterator endCN = itCNs->end();

      for (; itCN != endCN; ++itCN)
        {
          if (*it == this->createDisplayName(*itCN))
            {
              *to = *itCN;
              break;
            }
        }

      if (itCN == endCN)
        {
          const char * pTail = NULL;

          C_INT32 index = strToInt(it->c_str(), &pTail);

          if (itCNs->empty() || pTail != it->c_str() + it->size())
            {
              *to = std::string("not found");
            }
          else
            {
              *to = itCNs->operator [](index);
            }
        }
    }

  return CNIndex;
}
Ejemplo n.º 7
0
double Shape::length() const
{
  ASSERT_RETURN_V(dimensionality() == SHAPE_1D, 0.);
  QPolygonF p = polygon();
  double result = 0.;
  for (int i = 0; i < p.size() - 1; i++)
    result += segmentLenght(p[i], p[i + 1]);
  return result;
}
Ejemplo n.º 8
0
void CArrayAnnotation::setAnnotationCN(size_t d, size_t i, const std::string cn)
{
  assert(d < dimensionality());

  resizeOneDimension(d);
  assert(i < mAnnotationsCN[d].size());

  mAnnotationsCN[d][i] = cn;
  mAnnotationsString[d][i] = createDisplayName(cn);
}
Ejemplo n.º 9
0
int ClintStmtOccurrence::maximumValue(int dimIdx) const {
  if (dimIdx >= dimensionality() || dimIdx < 0)
    return 0;
  if (m_cachedDimMaxs.count(dimIdx) == 0) {
    projectOn(dimIdx, -2); // FIXME: -2 is VizProperties::NoDimension
  }
  CLINT_ASSERT(m_cachedDimMaxs.count(dimIdx) == 1,
               "max cache failure");
  return m_cachedDimMaxs[dimIdx];
}
Ejemplo n.º 10
0
double Shape::area() const
{
  ASSERT_RETURN_V(dimensionality() == SHAPE_2D, 0.);
  QPolygonF p = polygon();
  assertPolygonIsClosed(p);
  double result = 0.;
  for (int i = 1; i < p.size() - 2; i++)
    result += triangleSignedArea(p[0], p[i], p[i + 1]);
  return qAbs(result);
}
Ejemplo n.º 11
0
/**
Generates tperm::Boundary objects and sorts them into
tperm::OpposingBoundaries.

@todo Different boundaries (internal) from settings file
@todo Region support
*/
Boundaries sort_boundaries(const Model<3> &m, const Settings &s) {
  const size_t d = dimensionality(m);
  auto obnames = opposing_boundary_names(m);
  Boundaries bds(d);
  for (size_t i(0); i < d; ++i) {
    bds[i].first.assign(m.Boundary(obnames.at(i).first).NodesBegin(),
                        m.Boundary(obnames.at(i).first).NodesEnd()); // in
    bds[i].second.assign(m.Boundary(obnames.at(i).second).NodesBegin(),
                         m.Boundary(obnames.at(i).second).NodesEnd()); // out
  }
  return bds;
}
Ejemplo n.º 12
0
void CArrayAnnotation::printRecursively(std::ostream & ostream, size_t level,
                                        CCopasiAbstractArray::index_type & index,
                                        const std::vector<std::vector<std::string> > & display) const
{
  size_t indent = 2 * (dimensionality() - 1 - level);

  if (level == 0) //only vector
    {
      ostream << SPC(indent) << "Rows: " << getDimensionDescription(level) << "\n";

      size_t imax = size()[0];

      for (index[0] = 0; index[0] < imax; ++index[0])
        ostream << SPC(indent) << display[0][index[0]] << "\t" << (*array())[index] << "\n";
    }
  else if (level == 1) //matrix
    {
      ostream << SPC(indent) << "Rows:    " << getDimensionDescription(level - 1) << "\n";
      ostream << SPC(indent) << "Columns: " << getDimensionDescription(level) << "\n";

      size_t imax = size()[0];
      size_t jmax = size()[1];
      ostream << SPC(indent);

      for (index[1] = 0; index[1] < jmax; ++index[1])
        ostream << "\t" << display[1][index[1]];

      ostream << "\n";

      for (index[0] = 0; index[0] < imax; ++index[0])
        {
          ostream << SPC(indent) << display[0][index[0]];

          for (index[1] = 0; index[1] < jmax; ++index[1])
            ostream << "\t" << (*array())[index];

          ostream << "\n";
        }
    }
  else //dimensionality > 2
    {
      size_t i, imax = size()[level];

      for (i = 0; i < imax; ++i)
        {
          ostream << SPC(indent) << getDimensionDescription(level) << ": " << display[level][i] << "\n";
          index[level] = i;
          printRecursively(ostream, level - 1, index, display);
        }
    }
}
Ejemplo n.º 13
0
bool CArrayAnnotation::isEmpty()
{
  // either the dimension itself ...
  size_t dim = dimensionality();

  if (dim == 0) return false;

  // ... or the size of each dimension should be greater than zero.
  size_t idx = 0;

  for (idx = 0; idx < dim; idx++)
    {
      if (!size()[idx])
        return true;
    }

  return false;
}
Ejemplo n.º 14
0
void CDataArray::setAnnotation(size_t d, size_t i, const CDataObject * pObject)
{
  assert(d < dimensionality());

  resizeOneDimension(d);
  assert(i < mAnnotationsCN[d].size());

  if (pObject != NULL)
    {
      mAnnotationsCN[d][i] = pObject->getCN();
      mAnnotationsString[d][i] = pObject->getObjectDisplayName();
    }
  else
    {
      mAnnotationsCN[d][i] = std::string("");
      mAnnotationsString[d][i] = "";
    }
}
Ejemplo n.º 15
0
std::vector<std::vector<int>> ClintStmtOccurrence::projectOn(int horizontalDimIdx, int verticalDimIdx) const {
  if (m_oslScattering == nullptr) {
    std::cerr << "don't project" << std::endl;
  }
  CLINT_ASSERT(m_oslStatement != nullptr && m_oslScattering != nullptr,
               "Trying to project a non-initialized statement");

  // Transform iterator (alpha only) indices to enumerator (beta-alpha-beta) indices
  // betaDims are found properly iff the dimensionalityChecker assertion holds.
  int horizontalScatDimIdx    = 1 + 2 * horizontalDimIdx;
  int verticalScatDimIdx      = 1 + 2 * verticalDimIdx;
  int horizontalOrigDimIdx   = m_oslScattering->nb_output_dims + horizontalDimIdx;
  int verticalOrigDimIdx     = m_oslScattering->nb_output_dims + verticalDimIdx;

  horizontalScatDimIdx  = ignoreTilingDim(horizontalScatDimIdx);
  verticalScatDimIdx    = ignoreTilingDim(verticalScatDimIdx);
//  horizontalOrigDimIdx = ignoreTilingDim(horizontalOrigDimIdx);
//  verticalOrigDimIdx   = ignoreTilingDim(verticalOrigDimIdx);

  // Checking if all the relations for the same beta have the same structure.
  // AZ: Not sure if it is theoretically possible: statements with the same beta-vector
  // should normally be in the same part of the domain union and therefore have same
  // number of scattering variables.  If the following assertion ever fails, check the
  // theoretical statement and if it does not hold, perform enumeration separately for
  // each union part.
  // AZ: this holds for SCoPs generated by Clan.
  // TODO: piggyback on oslUtils and Enumerator to pass around the mapping from original iterators
  // to the scattering (indices in applied matrix) since different parts of the domain and scattering
  // relation unions may have different number of input/output dimensions for the codes
  // originating from outside Clan/Clay toolset.
  // AZ: is this even possible without extra information?  Two problematic cases,
  // 1. a1 = i + j, a2 = i - j; no clear mapping between a and i,j
  // 2. stripmine a1 >/< f(i), a2 = i; two a correspond to i in the same time.
  auto dimensionalityCheckerFunction = [](osl_relation_p rel, int output_dims,
                                          int input_dims, int parameters) {
    CLINT_ASSERT(rel->nb_output_dims == output_dims,
                 "Dimensionality mismatch, proper polyhedron construction impossible");
    CLINT_ASSERT(rel->nb_input_dims == input_dims,
                 "Dimensionality mismatch, proper polyhedron construction impossible");
    CLINT_ASSERT(rel->nb_parameters == parameters,
                 "Dimensionality mismatch, proper polyhedron construction impossible");
  };
  oslListForeach(m_oslStatement->domain, dimensionalityCheckerFunction, m_oslStatement->domain->nb_output_dims,
                 m_oslStatement->domain->nb_input_dims, m_oslStatement->domain->nb_parameters);
  CLINT_ASSERT(m_oslStatement->domain->nb_output_dims == m_oslScattering->nb_input_dims,
               "Scattering is not compatible with the domain");

  bool horizontalOrigDimValid = horizontalOrigDimIdx < m_oslScattering->nb_output_dims
      + m_oslStatement->domain->nb_output_dims;
  bool verticalOrigDimValid = verticalOrigDimIdx < m_oslScattering->nb_output_dims
      + m_oslStatement->domain->nb_output_dims;

  // Get original and scattered iterator values depending on the axis displayed.
  bool projectHorizontal = (horizontalDimIdx != -2) && (dimensionality() > horizontalDimIdx); // FIXME: -2 is in VizProperties::NO_DIMENSION, but should be in a different class since it has nothing to do with viz
  bool projectVertical   = (verticalDimIdx != -2) && (dimensionality() > verticalDimIdx);
  CLINT_ASSERT(!(projectHorizontal ^ (horizontalScatDimIdx >= 0 && horizontalScatDimIdx < m_oslScattering->nb_output_dims)),
               "Trying to project to the horizontal dimension that is not present in scattering");
  CLINT_ASSERT(!(projectVertical ^ (verticalScatDimIdx >= 0 && verticalScatDimIdx < m_oslScattering->nb_output_dims)),
               "Trying to project to the vertical dimension that is not present in scattering");

  std::vector<osl_relation_p> scatterings { m_oslScattering };
  osl_relation_p applied = oslApplyScattering(oslListToVector(m_oslStatement->domain),
                                              scatterings);
  osl_relation_p ready = oslRelationsWithContext(applied, m_statement->scop()->fixedContext());

  std::vector<int> allDimensions;
  allDimensions.reserve(m_oslScattering->nb_output_dims + 2);
  if (projectHorizontal && horizontalOrigDimValid) {
    allDimensions.push_back(horizontalScatDimIdx);
  }
  if (projectVertical && verticalOrigDimValid) {
    allDimensions.push_back(verticalScatDimIdx);
  }
  for (int i = 0, e = m_oslScattering->nb_input_dims; i < e; ++i) {
    allDimensions.push_back(m_oslScattering->nb_output_dims + i);
  }
  std::vector<std::vector<int>> points = program()->enumerator()->enumerate(ready, allDimensions);
  computeMinMax(points, horizontalDimIdx, verticalDimIdx);

  return std::move(points);
}