std::fill(res,res+nbOfCompo,0.);
const double *arrPtr=arr->getConstPointer();
const double *volPtr=vol->getArray()->getConstPointer();
+ double deno=0.;
for(int i=0;i<nbOfElems;i++)
{
+ double v=fabs(volPtr[i]);
for(int j=0;j<nbOfCompo;j++)
- res[j]+=fabs(arrPtr[i*nbOfCompo+j])*volPtr[i];
+ res[j]+=fabs(arrPtr[i*nbOfCompo+j])*v;
+ deno+=v;
}
+ std::transform(res,res+nbOfCompo,res,std::bind2nd(std::multiplies<double>(),1./deno));
vol->decrRef();
}
std::fill(res,res+nbOfCompo,0.);
const double *arrPtr=arr->getConstPointer();
const double *volPtr=vol->getArray()->getConstPointer();
+ double deno=0.;
for(int i=0;i<nbOfElems;i++)
{
+ double v=fabs(volPtr[i]);
for(int j=0;j<nbOfCompo;j++)
- res[j]+=arrPtr[i*nbOfCompo+j]*arrPtr[i*nbOfCompo+j]*fabs(volPtr[i]);
+ res[j]+=arrPtr[i*nbOfCompo+j]*arrPtr[i*nbOfCompo+j]*v;
+ deno+=v;
}
+ std::transform(res,res+nbOfCompo,res,std::bind2nd(std::multiplies<double>(),1./deno));
std::transform(res,res+nbOfCompo,res,std::ptr_fun<double,double>(std::sqrt));
vol->decrRef();
}
CPPUNIT_ASSERT_DOUBLES_EQUAL(expected4[i],res[i],1e-12);
//normL1
f1->normL1(res);
- double expected5[3]={11.3068,27.3621,43.7881};
+ double expected5[3]={6.979506172839505, 16.89018518518518, 27.02969135802469};
for(int i=0;i<3;i++)
CPPUNIT_ASSERT_DOUBLES_EQUAL(expected5[i],res[i],1e-12);
CPPUNIT_ASSERT_DOUBLES_EQUAL(expected5[0],f1->normL1(0),1e-12);
CPPUNIT_ASSERT_DOUBLES_EQUAL(expected5[2],f1->normL1(2),1e-12);
//normL2
f1->normL2(res);
- double expected7[3]={9.0252562290496776, 21.545259176904789, 34.433193070059595};
+ double expected7[3]={7.090910979452395, 16.9275542960123, 27.053271464160858};
for(int i=0;i<3;i++)
CPPUNIT_ASSERT_DOUBLES_EQUAL(expected7[i],res[i],1e-9);
CPPUNIT_ASSERT_DOUBLES_EQUAL(expected7[0],f1->normL2(0),1e-9);
CPPUNIT_ASSERT_DOUBLES_EQUAL(sqrt(2.)*expected4[i],res[i],1e-12);
f1->normL1(res);
for(int i=0;i<3;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL(sqrt(2.)*expected5[i],res[i],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected5[i],res[i],1e-12);
f1->normL2(res);
for(int i=0;i<3;i++)
- CPPUNIT_ASSERT_DOUBLES_EQUAL(sqrt(sqrt(2.))*expected7[i],res[i],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected7[i],res[i],1e-12);
//
f1->decrRef();
m1->decrRef();
#normL1
res=f1.normL1();
self.assertTrue(3,len(res))
- expected5=[11.3068,27.3621,43.7881]
+ expected5=[6.979506172839505, 16.89018518518518, 27.02969135802469]
for i in xrange(3):
self.assertTrue(abs(expected5[i]-res[i])<1e-12);
pass
#normL2
res=f1.normL2();
self.assertTrue(3,len(res))
- expected7=[9.0252562290496776, 21.545259176904789, 34.433193070059595]
+ expected7=[7.090910979452395, 16.9275542960123, 27.053271464160858]
for i in xrange(3):
self.assertTrue(abs(expected7[i]-res[i])<1e-9);
pass
pass
res=f1.normL1();
for i in xrange(3):
- self.assertTrue(abs(sqrt(2.)*expected5[i]-res[i])<1e-12);
+ self.assertTrue(abs(expected5[i]-res[i])<1e-12);
pass
res=f1.normL2();
for i in xrange(3):
- self.assertTrue(abs(sqrt(sqrt(2.))*expected7[i]-res[i])<1e-12);
+ self.assertTrue(abs(expected7[i]-res[i])<1e-12);
pass
pass