Page MenuHomeHEPForge

test_ResponseMatrix.cc
No OneTemporary

test_ResponseMatrix.cc

#include "UnitTest++.h"
#include "test_utils.hh"
#include "npstat/stat/ResponseMatrix.hh"
using namespace npstat;
using namespace std;
namespace {
TEST(ResponseMatrix)
{
double a[3][4] = {{0, 2, 3, 4},
{5, 6, 0, 8},
{9, 0, 11, 12}};
Matrix<double> ma(3, 4, &a[0][0]);
ResponseMatrix r(makeShape(4), makeShape(3), ma);
CHECK(r.isValid());
CHECK(ma == r.denseMatrix());
ArrayND<double> arr(4);
for (int i=0; i<4; ++i)
arr(i) = i*2 + 1;
double buf[4];
ma.timesVector(arr.data(), arr.length(), buf, 3);
ArrayND<double> res;
r.timesVector(arr, &res);
for (int i=0; i<3; ++i)
CHECK_EQUAL(buf[i], res(i));
const ResponseMatrix& rt = r.T();
const ResponseMatrix& rtt = rt.T();
rtt.shrinkToFit();
CHECK(rtt == r);
CHECK(rt.denseMatrix() == ma.T());
ArrayND<double> arr2(3);
for (int i=0; i<3; ++i)
arr2(i) = i*3 + 11;
ma.rowMultiply(arr2.data(), arr2.length(), buf, 4);
r.rowMultiply(arr2, &res);
for (int i=0; i<4; ++i)
CHECK_EQUAL(buf[i], res(i));
}
}

File Metadata

Mime Type
text/x-c
Expires
Sat, May 3, 5:45 AM (5 h, 18 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4982815
Default Alt Text
test_ResponseMatrix.cc (1 KB)

Event Timeline