* \param [in] a - the first coefficient of the function.
* \param [in] b - the second coefficient of the function.
* \param [in] compoId - the index of component to modify.
- * \throw If \a this is not allocated.
+ * \throw If \a this is not allocated, or \a compoId is not in [0,\c this->getNumberOfComponents() ).
*/
void DataArrayDouble::applyLin(double a, double b, int compoId)
{
checkAllocated();
- double *ptr=getPointer()+compoId;
- int nbOfComp=getNumberOfComponents();
- int nbOfTuple=getNumberOfTuples();
+ double *ptr(getPointer()+compoId);
+ int nbOfComp(getNumberOfComponents()),nbOfTuple(getNumberOfTuples());
+ if(compoId<0 || compoId>=nbOfComp)
+ {
+ std::ostringstream oss; oss << "DataArrayDouble::applyLin : The compoId requested (" << compoId << ") is not valid ! Must be in [0," << nbOfComp << ") !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
for(int i=0;i<nbOfTuple;i++,ptr+=nbOfComp)
*ptr=a*(*ptr)+b;
declareAsNew();
self.assertEqual(3,amr.getMaxNumberOfLevelsRelativeToThis())
self.assertEqual(2,amr.getSpaceDimension())
pass
+
+ def testSwig2NonRegressionTestPAL1164(self):
+ """ Test PAL1164 Protection of applyLin against error in compoId ( #CEA22584 ) """
+ xarr=DataArrayDouble(3,1)
+ xarr.iota(0.)
+ cmesh=MEDCouplingCMesh()
+ cmesh.setCoords(xarr,xarr,xarr)
+ mesh=cmesh.buildUnstructured()
+ f=mesh.fillFromAnalytic(ON_CELLS,1,"(x-5.)*(x-5.)+(y-5.)*(y-5.)+(z-5.)*(z-5.)")
+ f.setName("MyField")
+ self.assertTrue(f.getArray().isEqual(DataArrayDouble([60.75,52.75,52.75,44.75,52.75,44.75,44.75,36.75]),1e-12))
+ self.assertRaises(InterpKernelException,f.applyLin,2.,0.,1)# compoId 1 whereas f has only one component !
+ self.assertTrue(f.getArray().isEqual(DataArrayDouble([60.75,52.75,52.75,44.75,52.75,44.75,44.75,36.75]),1e-12))
+ f.applyLin(2.,0.,0)# here it is OK !
+ self.assertTrue(f.getArray().isEqual(DataArrayDouble([121.5,105.5,105.5,89.5,105.5,89.5,89.5,73.5]),1e-12))
+ #f.applyLin(2.,0.)
+ #self.assertTrue(f.getArray().isEqual(DataArrayDouble([243.,211.,211.,179.,211.,179.,179.,127.]),1e-12))
+ pass
def setUp(self):
pass