Skip to content

Commit 7dcf62b

Browse files
amaureaBai-Chiang
authored andcommitted
array_ops.cxx: Add new arg (DCT toggle) to nmat_detvecs_apply
Add `dct_binning` boolean option to `nmat_detvecs_apply` with default value being false. `nmat_detvecs_apply` would disable internal double binning when `dct_binning` is set to true. Co-authored-by: Bai-Chiang <contact@bai-chiang.com>
1 parent 75a01c0 commit 7dcf62b

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

src/array_ops.cxx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ extern "C" {
3535
// * bins[nbin,{from,to}] the start and end of each bin
3636
// * iD[nbin,ndet] the inverse uncorrelated variance for each detector per bin
3737
// * iV[nbin,ndet,nvec] matrix representing the scaled eivenvectors per bin
38-
void nmat_detvecs_apply(const bp::object & ft, const bp::object & bins, const bp::object & iD, const bp::object & iV, float s, float norm) {
38+
// * dct_binning(bool) If true, does not apply double `bins`. This works wth Discrete Cosine Transform.
39+
void nmat_detvecs_apply(const bp::object & ft, const bp::object & bins, const bp::object & iD, const bp::object & iV, float s, float norm, bool dct_binning = false) {
3940
// Should pass in this too
4041
BufferWrapper<float> ft_buf ("ft", ft, false, std::vector<int>{-1,-1});
4142
BufferWrapper<int32_t> bins_buf("bins", bins, false, std::vector<int>{-1, 2});
@@ -51,17 +52,18 @@ void nmat_detvecs_apply(const bp::object & ft, const bp::object & bins, const bp
5152
throw buffer_exception("iD must be C-contiguous along last axis");
5253
if (iV_buf->strides[2] != iV_buf->itemsize || iV_buf->strides[1] != iV_buf->itemsize*nvec || iV_buf->strides[0] != iV_buf->itemsize*nvec*ndet)
5354
throw buffer_exception("iV must be C-contiguous along last axis");
54-
// Internally we work with a real view of ft, with twice as many elements to compensate
55+
// When dct_binning is false, internally we work with a real view of ft, with twice as many elements to compensate, so bin_scale = 2.
5556
//int nmode = 2*nfreq;
57+
int bin_scale = (dct_binning) ? 1 : 2;
5658
float * ft_ = (float*) ft_buf->buf;
5759
int32_t * bins_ = (int32_t*) bins_buf->buf;
5860
float * iD_ = (float*) iD_buf->buf;
5961
float * iV_ = (float*) iV_buf->buf;
6062

6163
// Ok, actually do the work
6264
for(int bi = 0; bi < nbin; bi++) {
63-
int b1 = min(2*bins_[2*bi+0],nmode-1);
64-
int b2 = min(2*bins_[2*bi+1],nmode);
65+
int b1 = min(bin_scale*bins_[2*bi+0],nmode-1);
66+
int b2 = min(bin_scale*bins_[2*bi+1],nmode);
6567
int nm = b2-b1;
6668
float * biD = iD_ + bi*ndet;
6769
float * biV = iV_ + bi*ndet*nvec;
@@ -1262,7 +1264,7 @@ void detrend(bp::object & tod, const std::string & method, const int linear_ncou
12621264

12631265
PYBINDINGS("so3g")
12641266
{
1265-
bp::def("nmat_detvecs_apply", nmat_detvecs_apply);
1267+
bp::def("nmat_detvecs_apply", nmat_detvecs_apply, bp::arg("dct_binning")=false);
12661268
bp::def("process_cuts", process_cuts);
12671269
bp::def("translate_cuts", translate_cuts);
12681270
bp::def("get_gap_fill_poly", get_gap_fill_poly<float>,
@@ -1418,4 +1420,4 @@ PYBINDINGS("so3g")
14181420
" linear_ncount: Number (int) of samples to use on each end, when measuring mean level for 'linear'"
14191421
" detrend. Must be a positive integer or -1. If -1, nsamps / 2 will be used. Values "
14201422
" larger than 1 suppress the influence of white noise.\n");
1421-
}
1423+
}

0 commit comments

Comments
 (0)