/[escript]/trunk/escriptcore/src/Data.cpp
ViewVC logotype

Diff of /trunk/escriptcore/src/Data.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 6423 by caltinay, Wed Nov 2 13:05:29 2016 UTC revision 6424 by jfenwick, Thu Nov 3 02:13:09 2016 UTC
# Line 776  Data::copyWithMask(const Data& other, Line 776  Data::copyWithMask(const Data& other,
776      {      {
777          throw DataException("Error - copyWithMask not permitted using instances of DataEmpty.");          throw DataException("Error - copyWithMask not permitted using instances of DataEmpty.");
778      }      }
779        if (mask.isComplex())
780        {
781            throw DataException("Error - copyWithMask not permitted using a complex mask.");
782        }
783      Data other2(other);      Data other2(other);
784      Data mask2(mask);      Data mask2(mask);
785      other2.resolve();      other2.resolve();
# Line 837  Data::copyWithMask(const Data& other, Line 841  Data::copyWithMask(const Data& other,
841          // and so I'm going to assume that you don't want your data objects getting a new shape.          // and so I'm going to assume that you don't want your data objects getting a new shape.
842          throw DataException("Attempt to copyWithMask into a scalar from an object or mask with rank>0.");          throw DataException("Attempt to copyWithMask into a scalar from an object or mask with rank>0.");
843      }      }
     exclusiveWrite();  
     // Now we iterate over the elements  
     RealVectorType& self=getReady()->getVectorRW();;  
     const RealVectorType& ovec=other2.getReadyPtr()->getVectorRO();  
     const RealVectorType& mvec=mask2.getReadyPtr()->getVectorRO();  
   
844      if ((selfrank>0) && (otherrank==0) &&(maskrank==0))      if ((selfrank>0) && (otherrank==0) &&(maskrank==0))
845      {      {
846          // Not allowing this combination.          // Not allowing this combination.
# Line 851  Data::copyWithMask(const Data& other, Line 849  Data::copyWithMask(const Data& other,
849          // or should the target object be reshaped to be a scalar as well.          // or should the target object be reshaped to be a scalar as well.
850          throw DataException("Attempt to copyWithMask from scalar mask and data into non-scalar target.");          throw DataException("Attempt to copyWithMask from scalar mask and data into non-scalar target.");
851      }      }
852        
853        if (isComplex()!=other2.isComplex())
854        {
855            complicate();
856            other2.complicate();
857        }
858        
859        exclusiveWrite();
860        if (!isComplex())
861        {
862        maskWorker(other2, mask2, DataTypes::real_t(0));
863        }
864        else
865        {
866        maskWorker(other2, mask2, DataTypes::cplx_t(0));
867        }
868    }
869    
870    template <typename S>
871    void
872    Data::maskWorker(Data& other2, Data& mask2, S sentinel)
873    {
874         // Now we iterate over the elements
875        auto& self=getReady()->getTypedVectorRW(sentinel);
876        auto& ovec=other2.getReadyPtr()->getTypedVectorRO(sentinel);
877        auto& mvec=mask2.getReadyPtr()->getTypedVectorRO(DataTypes::real_t(0));
878    
879        unsigned int selfrank=getDataPointRank();
880        unsigned int otherrank=other2.getDataPointRank();
881        unsigned int maskrank=mask2.getDataPointRank();    
882    
883      if ((selfrank>0) && (otherrank>0) &&(maskrank==0))      if ((selfrank>0) && (otherrank>0) &&(maskrank==0))
884      {      {
885          if (mvec[0]>0)          // copy whole object if scalar is >0          if (mvec[0]>0)          // copy whole object if scalar is >0
886          {          {
887              copy(other);              copy(other2);
888          }          }
889          return;          return;
890      }      }
# Line 897  Data::copyWithMask(const Data& other, Line 926  Data::copyWithMask(const Data& other,
926              for (i=tlookup.begin();i!=tlookup.end();i++)              for (i=tlookup.begin();i!=tlookup.end();i++)
927              {              {
928                  // get the target offset                  // get the target offset
929                  DataTypes::RealVectorType::size_type toff=tptr->getOffsetForTag(i->first);              // yes this is explicitly RealType but size_t should not vary
930                DataTypes::RealVectorType::size_type toff=tptr->getOffsetForTag(i->first);
931                  DataTypes::RealVectorType::size_type moff=mptr->getOffsetForTag(i->first);                  DataTypes::RealVectorType::size_type moff=mptr->getOffsetForTag(i->first);
932                  DataTypes::RealVectorType::size_type ooff=optr->getOffsetForTag(i->first);                  DataTypes::RealVectorType::size_type ooff=optr->getOffsetForTag(i->first);
933                  for (int j=0;j<getDataPointSize();++j)                  for (int j=0;j<getDataPointSize();++j)
# Line 922  Data::copyWithMask(const Data& other, Line 952  Data::copyWithMask(const Data& other,
952              for (i=tlookup.begin();i!=tlookup.end();i++)              for (i=tlookup.begin();i!=tlookup.end();i++)
953              {              {
954                  // get the target offset                  // get the target offset
955                  DataTypes::RealVectorType::size_type toff=tptr->getOffsetForTag(i->first);              DataTypes::RealVectorType::size_type toff=tptr->getOffsetForTag(i->first);
956                  DataTypes::RealVectorType::size_type moff=mptr->getOffsetForTag(i->first);                  DataTypes::RealVectorType::size_type moff=mptr->getOffsetForTag(i->first);
957                  DataTypes::RealVectorType::size_type ooff=optr->getOffsetForTag(i->first);                  DataTypes::RealVectorType::size_type ooff=optr->getOffsetForTag(i->first);        
958                  for (int j=0;j<getDataPointSize();++j)                  for (int j=0;j<getDataPointSize();++j)
959                  {                  {
960                      if (mvec[j+moff]>0)                      if (mvec[j+moff]>0)

Legend:
Removed from v.6423  
changed lines
  Added in v.6424

  ViewVC Help
Powered by ViewVC 1.1.26