//
//-----------------------------------------------------------------------------------
// Page-in the required CFs and load them on the device.
//
std::tuple<hpg::opt_t<hpg::Error>, hpg::CFSimpleIndexer>
AWVisResamplerHPG::loadCF(VBStore& vbs, Int& nGridPol, Int& nDataPol,
Vector<Int>& wNdxList,
Vector<Int>& spwNdxList,
bool send_to_device)
{
LogIO log_l(LogOrigin("HPGLoadCF","loadCF"));
// Int vbSpw = (vbs.vb_p)->spectralWindows()(0);
// if (cachedVBSpw_p != vbSpw)
// cachedVBSpw_p=vbSpw;
Int irow=0, nWCF=1, nFreqCF, nPolCF;
Vector<float> sampling(2);
Vector<Int> support(2), cfShape;
Vector<Double> wVals, fVals; PolMapType mVals, mNdx, conjMVals, conjMNdx;
Bool Dummy;
Double vbPA = vbs.paQuant_p.getValue("rad");
//Double *freq = vbs.freq_p.getStorage(Dummy);
Double cfRefFreq,dataWVal=0,fIncr, wIncr;
CountedPtr<CFBuffer> cfb = (*vb2CFBMap_p)[irow];
cfb->getCoordList(fVals,wVals,mNdx, mVals, conjMNdx, conjMVals, fIncr, wIncr);
cerr << "####FVALS " << fVals << " wVals " << wVals << endl;
nWCF = wNdxList.nelements();
nFreqCF = spwNdxList.nelements();
cerr << "@@@LoadCF wndxls " << wNdxList << " spwNdxls " << spwNdxList << endl;
// Get the oversampling parameter.
{
Float s;
int dummyWNdx=0;
int refSpw;
//refSpw = getNearestSpw(fVals,vbs.imRefFreq_p);
//Double ref =
SynthesisUtils::stdNearestValue(fVals.tovector(), vbs.imRefFreq_p, refSpw);
// cerr << "RefSpw, W, F, RefFreq: "
// << refSpw << " " << wVals.nelements() << " " << fVals.nelements() << " " << vbs.imRefFreq_p
// << endl;
cfb->getParams(cfRefFreq, s, support(0), support(1),refSpw,dummyWNdx,0);
sampling(0) = sampling(1) = SynthesisUtils::nint(s);
}
nPolCF=0;
std::map<int,int> p2m; // MP: map of mNdx[][] value to mueller index for CFArray
if (cfArray.oversampling()==0)
{
//unsigned nc=mNdx[0].shape()(0);
unsigned nr=mNdx.shape()(0);
for (int r=0;r<nr;r++)
{
// MP: the use of "p2m" fixes the issue mentioned below
for (int c=0;c<mNdx[r].shape()[0];c++) {
auto p = mNdx[r][c];
if (p >= 0 && p2m.count(p) == 0) {
auto m = p2m.size();
p2m[p] = m;
}
}
// This assumes that all entries are unique elements of
// the Mueller matrix. In effect, this ignores symmetries
// in the Mueller matrix elements, which can (should?) be
// exploited to reduce memory footprint.
// SB: nPolCF += conjMNdx[r].shape()(0);
//cerr << mNdx[r] << endl;
}
nPolCF = p2m.size();
log_l << "CFBuffer shape (nW x nF x nPol): " << nWCF << " x " << nFreqCF << " x " << nPolCF << LogIO::POST;
unsigned nCF;
nCF = nWCF * nFreqCF;
log_l << "Setting cfArray size: " << "nCF: " << nCF << " x " << nPolCF << " sampling: " << sampling(0) << LogIO::POST;
cfArray.setSize((unsigned)(nCF),(unsigned)sampling(0));
}
// CFSimpleIndexer(
// const axis_desc_t& baseline_class,
// const axis_desc_t& time,
// const axis_desc_t& w_plane,
// const axis_desc_t& frequency,
// unsigned mueller)
// nBLType, nTime/PA, nW, nFreq, nPol