| 1 | /* |
| 2 | * This file is part of Healpix_cxx. |
| 3 | * |
| 4 | * Healpix_cxx is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; either version 2 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * Healpix_cxx is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with Healpix_cxx; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 17 | * |
| 18 | * For more information about HEALPix, see http://healpix.sourceforge.net |
| 19 | */ |
| 20 | |
| 21 | /* |
| 22 | * Healpix_cxx is being developed at the Max-Planck-Institut fuer Astrophysik |
| 23 | * and financially supported by the Deutsches Zentrum fuer Luft- und Raumfahrt |
| 24 | * (DLR). |
| 25 | */ |
| 26 | |
| 27 | /*! \file weight_utils.cc |
| 28 | * |
| 29 | * Functionality for computing ring weights and full map weights |
| 30 | * |
| 31 | * Helpful literature: |
| 32 | * Graef, Kunis, Potts: On the computation of nonnegative quadrature weights |
| 33 | * on the sphere |
| 34 | * (https://www-user.tu-chemnitz.de/~potts/paper/quadgewS2.pdf) |
| 35 | * Lambers: Minimum Norm Solutions of Underdetermined Systems |
| 36 | * (http://www.math.usm.edu/lambers/mat419/lecture15.pdf) |
| 37 | * Shewchuk: An Introduction to the Conjugate Gradient Method Without the |
| 38 | * Agonizing Pain |
| 39 | * (https://www.cs.cmu.edu/~quake-papers/painless-conjugate-gradient.pdf) |
| 40 | * |
| 41 | * Copyright (C) 2016-2019 Max-Planck-Society |
| 42 | * \author Martin Reinecke |
| 43 | */ |
| 44 | |
| 45 | #include <vector> |
| 46 | #include <numeric> |
| 47 | #include <algorithm> |
| 48 | #include "healpix_map.h"cxx . . $ `<file>/Healpix_cxx/healpix_map.h`/ |
| 49 | #include "alm_healpix_tools.h"cxx . . $ `<file>/Healpix_cxx/alm_healpix_tools.h`/ |
| 50 | #include "weight_utils.h"cxx . . $ `<file>/Healpix_cxx/weight_utils.h`/ |
| 51 | #include "alm.h"cxx . . $ `<file>/Healpix_cxx/alm.h`/ |
| 52 | #include "libsharp/sharp_cxx.h" |
| 53 | #include "lsconstants.h"cxx . . $ `<file>/cxxsupport/lsconstants.h`/ |
| 54 | |
| 55 | using namespace std; |
| 56 | |
| 57 | /* General considerations concerning the full weights and their a_lm |
| 58 | coefficients: |
| 59 | The Healpix grid geometry has several symmetries: |
| 60 | - mirror symmetry with respect to phi=0 |
| 61 | - mirror symmetry with respect to the equator |
| 62 | - invariance with respect to rotation around the z-axis by multiples of |
| 63 | pi/2 |
| 64 | This reduces the number of pixels with distinct weights to roughly 1/16 of |
| 65 | the total number of map pixels. |
| 66 | The geometrical symmetries also reduce the number of a_lm coefficients |
| 67 | required to describe the weight map: |
| 68 | - the mirror symmetry in phi means that all a_lm are purely real-valued |
| 69 | - the mirror symmetry in theta means that all a_lm with odd l are zero |
| 70 | - the rotational symmetry means that all a_lm with m not a multiple of 4 |
| 71 | vanish as well. |
| 72 | |
| 73 | These symmetries are used when storing a_lm coefficients and weight maps to |
| 74 | save memory. So far, the SHTs themselves are carried out with full maps and |
| 75 | a_lm sets, because there is no libsharp support for this kind of symmetries |
| 76 | yet. */ |
| 77 | |
| 78 | namespace weight_utils_detailcxx . . $ weight_utils_detail/ { |
| 79 | |
| 80 | using namespace std; |
| 81 | |
| 82 | // inner product of two vectors |
| 83 | double dprodcxx . . $ weight_utils_detail/dprod(33345cf21c18115f).(const vectorcxx . . $ std/vector#<double> &a, const vectorcxx . . $ std/vector#<double> &b) |
| 84 | { return inner_productcxx . . $ std/inner_product(9baadb9f685e59eb).(a.begincxx . . $ std/vector#begin(d1e1699016b9d7e6).(),a.endcxx . . $ std/vector#end(d1e1699016b9d7e6).(),b.begincxx . . $ std/vector#begin(d1e1699016b9d7e6).(),0.); } |
| 85 | |
| 86 | tsizecxx . . $ tsize# n_fullweightscxx . . $ weight_utils_detail/n_fullweights(c104ebd7d68b2193). (int nside) |
| 87 | { return ((3*nside+1)*(nside+1))/4; } |
| 88 | |
| 89 | template <typename T> void apply_weightcxx . . $ weight_utils_detail/apply_weight(9efcc6afd78ae83a). (T &pix, double w, bool setwgt) |
| 90 | { |
| 91 | if (setwgt) |
| 92 | pix=T(w); |
| 93 | else |
| 94 | if (!approxcxx . . $ approx(c516e863860b14de).<double>(pix,Healpix_undefcxx . . $ Healpix_undef.)) pix*=T(1.+w); |
| 95 | } |
| 96 | |
| 97 | template <typename T> void apply_fullweightscxx . . $ weight_utils_detail/apply_fullweights(3cf739d72b787215). (Healpix_Mapcxx . . $ Healpix_Map#<T> &map, |
| 98 | const vectorcxx . . $ std/vector#<double> &wgt, bool setwgt) |
| 99 | { |
| 100 | planck_assertcxx . . $ `cxxsupport/error_handling.h:79:9`! (map.Scheme()==RING, "bad map ordering scheme"); |
| 101 | int nside=map.Nsidecxx . . $ T_Healpix_Base#Nside(8f5363d873dd4781).(); |
| 102 | planck_assertcxx . . $ `cxxsupport/error_handling.h:79:9`!(wgt.size()==n_fullweights(nside), |
| 103 | "incorrect size of weight array"); |
| 104 | int pix=0, vpix=0; |
| 105 | for (int i=0; i<2*nside; ++i) |
| 106 | { |
| 107 | bool shifted = (i<nside-1) || ((i+nside)&1); |
| 108 | int qpix=mincxx . . $ std/min(2a338fce5842aa6a).(nside,i+1); |
| 109 | bool odd=qpix&1; |
| 110 | int wpix=((qpix+1)>>1) + ((odd||shifted) ? 0 : 1); |
| 111 | int psouth=map.Npixcxx . . $ T_Healpix_Base#Npix(8f5363d873dd4781).()-cxx . . $ std/operator-(a6e85813984128c7).pix-cxx . . $ std/operator-(a6e85813984128c7).(qpix<<2); |
| 112 | for (int j=0; j<(qpix<<2); ++j) |
| 113 | { |
| 114 | int j4=j%qpix; |
| 115 | int rpix=mincxx . . $ std/min(2a338fce5842aa6a).(j4,qpix - (shifted ? 1:0) - j4); |
| 116 | apply_weightcxx . . $ weight_utils_detail/apply_weight(9efcc6afd78ae83a). (map[pix+j],wgt[cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).vpix+rpix],setwgt); |
| 117 | if (i!=2*nside-1) // everywhere except on equator |
| 118 | apply_weightcxx . . $ weight_utils_detail/apply_weight(9efcc6afd78ae83a).(map[psouth+j],wgt[cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).vpix+rpix],setwgt); |
| 119 | } |
| 120 | pix+=qpix<<2; |
| 121 | vpix+=wpix; |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | vectorcxx . . $ std/vector#<double> extract_fullweightscxx . . $ weight_utils_detail/extract_fullweights(8de48d195e112adb). (const Healpix_Mapcxx . . $ Healpix_Map#<double> &map) |
| 126 | { |
| 127 | planck_assertcxx . . $ `cxxsupport/error_handling.h:79:9`! (map.Scheme()==RING, "bad map ordering scheme"); |
| 128 | int nside=map.Nsidecxx . . $ T_Healpix_Base#Nside(8f5363d873dd4781).(); |
| 129 | vectorcxx . . $ std/vector#<double> rescxx . . $ std/vector#vector(49f6e7a06ebc5aa8).; res.reservecxx . . $ std/vector#reserve(2c44cd906ae4e829).(n_fullweightscxx . . $ weight_utils_detail/n_fullweights(c104ebd7d68b2193).(nside)); |
| 130 | int pix=0; |
| 131 | for (int i=0; i<2*nside; ++i) |
| 132 | { |
| 133 | bool shifted = (i<nside-1) || ((i+nside)&1); |
| 134 | int qpix=mincxx . . $ std/min(2a338fce5842aa6a).(nside,i+1); |
| 135 | bool odd=qpix&1; |
| 136 | int wpix=((qpix+1)>>1) + ((odd||shifted) ? 0 : 1); |
| 137 | for (int j=0; j<wpix; ++j) |
| 138 | res.push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(map[cxx . . $ Healpix_Map#`operator[]`(e2681f9bb6b2f357).pix+j]); |
| 139 | pix+=qpix<<2; |
| 140 | } |
| 141 | return rescxx . . $ std/vector#vector(6f559d22b039ccdb).; |
| 142 | } |
| 143 | |
| 144 | tsizecxx . . $ tsize# n_weightalmcxx . . $ weight_utils_detail/n_weightalm(beccc266862daf71). (int lmax, int mmax) |
| 145 | { |
| 146 | int nmsteps=(mmax>>2)+1; |
| 147 | return nmsteps * (((lmax+2)>>1) - nmsteps+1); |
| 148 | } |
| 149 | vectorcxx . . $ std/vector#<double> extract_weightalmcxx . . $ weight_utils_detail/extract_weightalm(af667ad207949eaa). (const Almcxx . . $ Alm#<xcomplexcxx . . $ `cxxsupport/xcomplex.h:37:9`!<double> > &alm) |
| 150 | { |
| 151 | vectorcxx . . $ std/vector#<double> rescxx . . $ std/vector#vector(49f6e7a06ebc5aa8).; res.reservecxx . . $ std/vector#reserve(2c44cd906ae4e829).(n_weightalmcxx . . $ weight_utils_detail/n_weightalm(beccc266862daf71).(alm.Lmaxcxx . . $ Alm_Base#Lmax(455f465bc33b4cdf).(),alm.Mmaxcxx . . $ Alm_Base#Mmax(455f465bc33b4cdf).())); |
| 152 | for (int m=0; m<=alm.Mmaxcxx . . $ Alm_Base#Mmax(455f465bc33b4cdf).(); m+=4) |
| 153 | for (int l=m; l<=alm.Lmaxcxx . . $ Alm_Base#Lmax(455f465bc33b4cdf).(); l+=2) |
| 154 | res.push_backcxx . . $ std/vector#push_back(fe7a8a4d1eddb70).(realcxx . . $ std/real(bb57395c51337e15).(alm(cxx . . $ Alm#`operator()`(17c8b25841cc6a04).l,m)) * ((m==0) ? 1 : sqrt(2.))); |
| 155 | return rescxx . . $ std/vector#vector(6f559d22b039ccdb).; |
| 156 | } |
| 157 | void expand_weightalmcxx . . $ weight_utils_detail/expand_weightalm(3d67ea478a691722). (const vectorcxx . . $ std/vector#<double> &calm, Almcxx . . $ Alm#<xcomplexcxx . . $ `cxxsupport/xcomplex.h:37:9`!<double> > &alm) |
| 158 | { |
| 159 | planck_assertcxx . . $ `cxxsupport/error_handling.h:79:9`!(calm.size()==n_weightalm(alm.Lmax(), alm.Mmax()), |
| 160 | "incorrect size of weight array"); |
| 161 | alm.SetToZerocxx . . $ Alm#SetToZero(49f6e7a06ebc5aa8).(); |
| 162 | tsizecxx . . $ tsize# idx=0; |
| 163 | for (int m=0; m<=alm.Mmaxcxx . . $ Alm_Base#Mmax(455f465bc33b4cdf).(); m+=4) |
| 164 | for (int l=m; l<=alm.Lmaxcxx . . $ Alm_Base#Lmax(455f465bc33b4cdf).(); l+=2) |
| 165 | alm(cxx . . $ Alm#`operator()`(81532356f20a340f).l,m) =cxx . . $ std/complex#`operator=`(3b07e393e346b962). calm[cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).idx++] * ((m==0) ? 1 : sqrt(0.5)); |
| 166 | } |
| 167 | |
| 168 | class STS_hpwgtcxx . . $ weight_utils_detail/STS_hpwgt# |
| 169 | { |
| 170 | private: |
| 171 | int lmaxcxx . . $ weight_utils_detail/STS_hpwgt#lmax., mmaxcxx . . $ weight_utils_detail/STS_hpwgt#mmax., nsidecxx . . $ weight_utils_detail/STS_hpwgt#nside.; |
| 172 | |
| 173 | public: |
| 174 | using vectypecxx . . $ weight_utils_detail/STS_hpwgt#vectype#=vectorcxx . . $ std/vector#<double>; |
| 175 | STS_hpwgtcxx . . $ weight_utils_detail/STS_hpwgt#STS_hpwgt(b1146eedae1e1d0b). (int lmax_, int mmax_, int nside_) |
| 176 | : lmaxcxx . . $ weight_utils_detail/STS_hpwgt#lmax.(lmax_), mmaxcxx . . $ weight_utils_detail/STS_hpwgt#mmax.(mmax_), nsidecxx . . $ weight_utils_detail/STS_hpwgt#nside.(nside_) |
| 177 | { planck_assertcxx . . $ `cxxsupport/error_handling.h:79:9`!((lmax&1)==0,"lmax must be even"); } |
| 178 | vectypecxx . . $ weight_utils_detail/STS_hpwgt#vectype# Scxx . . $ weight_utils_detail/STS_hpwgt#S(be3d5686be3109ae). (const vectypecxx . . $ weight_utils_detail/STS_hpwgt#vectype# &x) const |
| 179 | { |
| 180 | Almcxx . . $ Alm#<xcomplexcxx . . $ `cxxsupport/xcomplex.h:37:9`!<double> > tacxx . . $ Alm#Alm(3e454b8ccf442868).(lmaxcxx . . $ weight_utils_detail/STS_hpwgt#lmax.,mmaxcxx . . $ weight_utils_detail/STS_hpwgt#mmax.); |
| 181 | expand_weightalmcxx . . $ weight_utils_detail/expand_weightalm(3d67ea478a691722).(x,ta); |
| 182 | Healpix_Mapcxx . . $ Healpix_Map#<double> tmcxx . . $ Healpix_Map#Healpix_Map(e1fcea588b18719).(nsidecxx . . $ weight_utils_detail/STS_hpwgt#nside.,RINGcxx . . $ RING., SET_NSIDEcxx . . $ SET_NSIDE.); |
| 183 | alm2mapcxx . . $ alm2map(2408b94ef4a290fa).(ta,tm); |
| 184 | return extract_fullweightscxx . . $ weight_utils_detail/extract_fullweights(8de48d195e112adb).(tm); |
| 185 | } |
| 186 | vectypecxx . . $ weight_utils_detail/STS_hpwgt#vectype# STcxx . . $ weight_utils_detail/STS_hpwgt#ST(be3d5686be3109ae). (const vectypecxx . . $ weight_utils_detail/STS_hpwgt#vectype# &x) const |
| 187 | { |
| 188 | Healpix_Mapcxx . . $ Healpix_Map#<double> tmcxx . . $ Healpix_Map#Healpix_Map(e1fcea588b18719).(nsidecxx . . $ weight_utils_detail/STS_hpwgt#nside.,RINGcxx . . $ RING., SET_NSIDEcxx . . $ SET_NSIDE.); |
| 189 | apply_fullweightscxx . . $ weight_utils_detail/apply_fullweights(3cf739d72b787215).(tm,x,true); |
| 190 | Almcxx . . $ Alm#<xcomplexcxx . . $ `cxxsupport/xcomplex.h:37:9`!<double> > tacxx . . $ Alm#Alm(3e454b8ccf442868).(lmaxcxx . . $ weight_utils_detail/STS_hpwgt#lmax.,mmaxcxx . . $ weight_utils_detail/STS_hpwgt#mmax.); |
| 191 | alm2map_adjointcxx . . $ alm2map_adjoint(ddecc97d7791368d).(tm,ta); |
| 192 | return extract_weightalmcxx . . $ weight_utils_detail/extract_weightalm(af667ad207949eaa).(ta); |
| 193 | } |
| 194 | vectypecxx . . $ weight_utils_detail/STS_hpwgt#vectype# applycxx . . $ weight_utils_detail/STS_hpwgt#apply(be3d5686be3109ae). (const vectypecxx . . $ weight_utils_detail/STS_hpwgt#vectype# &x) const |
| 195 | { return STcxx . . $ weight_utils_detail/STS_hpwgt#ST(be3d5686be3109ae).(Scxx . . $ weight_utils_detail/STS_hpwgt#S(be3d5686be3109ae).(x)); } |
| 196 | }; |
| 197 | |
| 198 | class STS_hpringcxx . . $ weight_utils_detail/STS_hpring# |
| 199 | { |
| 200 | private: |
| 201 | int lmaxcxx . . $ weight_utils_detail/STS_hpring#lmax., nsidecxx . . $ weight_utils_detail/STS_hpring#nside.; |
| 202 | sharp_cxxjobcxx . . $ sharp_cxxjob#<double> jobcxx . . $ weight_utils_detail/STS_hpring#job.; |
| 203 | |
| 204 | public: |
| 205 | using vectypecxx . . $ weight_utils_detail/STS_hpring#vectype#=vectorcxx . . $ std/vector#<double>; |
| 206 | STS_hpringcxx . . $ weight_utils_detail/STS_hpring#STS_hpring(3e454b8ccf442868). (int lmax_, int nside_) |
| 207 | : lmaxcxx . . $ weight_utils_detail/STS_hpring#lmax.(lmax_), nsidecxx . . $ weight_utils_detail/STS_hpring#nside.(nside_) |
| 208 | { |
| 209 | planck_assertcxx . . $ `cxxsupport/error_handling.h:79:9`!((lmax&1)==0,"lmax must be even"); |
| 210 | int nring=2*nsidecxx . . $ weight_utils_detail/STS_hpring#nside.; |
| 211 | vectorcxx . . $ std/vector#<double> dbl0cxx . . $ std/vector#vector(229e4d6bd205de31).(nring,0.),thetacxx . . $ std/vector#vector(83fdeebbe0501a83).(nring); |
| 212 | vectorcxx . . $ std/vector#<int> int1cxx . . $ std/vector#vector(229e4d6bd205de31).(nring,1); |
| 213 | vectorcxx . . $ std/vector#<ptrdiff_t> ofscxx . . $ std/vector#vector(83fdeebbe0501a83).(nring); |
| 214 | Healpix_Basecxx . . $ Healpix_Base# basecxx . . $ T_Healpix_Base#T_Healpix_Base(1a29ef13819bad63).(nsidecxx . . $ weight_utils_detail/STS_hpring#nside., RINGcxx . . $ RING., SET_NSIDEcxx . . $ SET_NSIDE.); |
| 215 | for (int i=0; i<nring; ++i) |
| 216 | { |
| 217 | ofs[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i]=i; |
| 218 | int idum1,idum2; |
| 219 | bool bdum; |
| 220 | base.get_ring_info2cxx . . $ T_Healpix_Base#get_ring_info2(5e9d787810d3bb8). (i+1, idum1, idum2, theta[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i], bdum); |
| 221 | } |
| 222 | jobcxx . . $ weight_utils_detail/STS_hpring#job..set_general_geometrycxx . . $ sharp_base#set_general_geometry(ae74747fa4d5fb3c). (nring, int1.datacxx . . $ std/vector#data(258ee1c9e0a18a5c).(), ofs.datacxx . . $ std/vector#data(258ee1c9e0a18a5c).(), |
| 223 | int1.datacxx . . $ std/vector#data(258ee1c9e0a18a5c).(), dbl0.datacxx . . $ std/vector#data(258ee1c9e0a18a5c).(), theta.datacxx . . $ std/vector#data(258ee1c9e0a18a5c).(), dbl0.datacxx . . $ std/vector#data(258ee1c9e0a18a5c).()); |
| 224 | jobcxx . . $ weight_utils_detail/STS_hpring#job..set_triangular_alm_infocxx . . $ sharp_base#set_triangular_alm_info(3e454b8ccf442868). (lmaxcxx . . $ weight_utils_detail/STS_hpring#lmax., 0); |
| 225 | } |
| 226 | vectypecxx . . $ weight_utils_detail/STS_hpring#vectype# Scxx . . $ weight_utils_detail/STS_hpring#S(be3d5686be3109ae).(const vectypecxx . . $ weight_utils_detail/STS_hpring#vectype# &alm) const |
| 227 | { |
| 228 | planck_assertcxx . . $ `cxxsupport/error_handling.h:79:9`!(int(alm.size())==lmax/2+1,"bad input size"); |
| 229 | vectypecxx . . $ weight_utils_detail/STS_hpring#vectype# rescxx . . $ std/vector#vector(83fdeebbe0501a83).(2*nsidecxx . . $ weight_utils_detail/STS_hpring#nside.); |
| 230 | vectorcxx . . $ std/vector#<xcomplexcxx . . $ `cxxsupport/xcomplex.h:37:9`!<double> > alm2cxx . . $ std/vector#vector(229e4d6bd205de31).(2*alm.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).()-1,0.cxx . . $ std/complex#complex(bc12c9ec15586e6a).); |
| 231 | for (tsizecxx . . $ tsize# i=0; i<alm.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); ++i) |
| 232 | alm2[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).2*i]=cxx . . $ std/complex#`operator=`(3b07e393e346b962).alm[cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).i]; |
| 233 | jobcxx . . $ weight_utils_detail/STS_hpring#job..alm2mapcxx . . $ sharp_cxxjob#alm2map(8bd20cbd1163cc80).(&alm2[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).0],&res[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).0],false); |
| 234 | return rescxx . . $ std/vector#vector(6f559d22b039ccdb).; |
| 235 | } |
| 236 | vectypecxx . . $ weight_utils_detail/STS_hpring#vectype# STcxx . . $ weight_utils_detail/STS_hpring#ST(be3d5686be3109ae).(const vectypecxx . . $ weight_utils_detail/STS_hpring#vectype# &map) const |
| 237 | { |
| 238 | planck_assertcxx . . $ `cxxsupport/error_handling.h:79:9`!(int(map.size())==2*nside,"bad input size"); |
| 239 | vectorcxx . . $ std/vector#<xcomplexcxx . . $ `cxxsupport/xcomplex.h:37:9`!<double> > alm2cxx . . $ std/vector#vector(229e4d6bd205de31).(lmaxcxx . . $ weight_utils_detail/STS_hpring#lmax.+1,0.cxx . . $ std/complex#complex(bc12c9ec15586e6a).); |
| 240 | jobcxx . . $ weight_utils_detail/STS_hpring#job..alm2map_adjointcxx . . $ sharp_cxxjob#alm2map_adjoint(7a0576db58ad1df4).(&map[cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).0],&alm2[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).0], false); |
| 241 | vectypecxx . . $ weight_utils_detail/STS_hpring#vectype# rescxx . . $ std/vector#vector(83fdeebbe0501a83).(lmaxcxx . . $ weight_utils_detail/STS_hpring#lmax./2+1); |
| 242 | for (tsizecxx . . $ tsize# i=0; i<res.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); ++i) |
| 243 | res[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i]=realcxx . . $ std/real(bb57395c51337e15).(alm2[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).2*i]); |
| 244 | return rescxx . . $ std/vector#vector(6f559d22b039ccdb).; |
| 245 | } |
| 246 | vectypecxx . . $ weight_utils_detail/STS_hpring#vectype# applycxx . . $ weight_utils_detail/STS_hpring#apply(be3d5686be3109ae). (const vectypecxx . . $ weight_utils_detail/STS_hpring#vectype# &x) const |
| 247 | { return STcxx . . $ weight_utils_detail/STS_hpring#ST(be3d5686be3109ae).(Scxx . . $ weight_utils_detail/STS_hpring#S(be3d5686be3109ae).(x)); } |
| 248 | }; |
| 249 | |
| 250 | vectorcxx . . $ std/vector#<double> muladdcxx . . $ weight_utils_detail/muladd(2211ffc31ff52639). (double fct, const vectorcxx . . $ std/vector#<double> &a, |
| 251 | const vectorcxx . . $ std/vector#<double> &b) |
| 252 | { |
| 253 | planck_assertcxx . . $ `cxxsupport/error_handling.h:79:9`!(a.size()==b.size(),"types not conformable"); |
| 254 | vectorcxx . . $ std/vector#<double> rescxx . . $ std/vector#vector(a1201200cf0efa42).(b); |
| 255 | for (tsizecxx . . $ tsize# i=0; i<a.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); ++i) |
| 256 | res[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i] += fct*a[cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).i]; |
| 257 | return rescxx . . $ std/vector#vector(6f559d22b039ccdb).; |
| 258 | } |
| 259 | |
| 260 | // canned algorithm B2 from Shewchuk |
| 261 | template<typename M> double cg_solvecxx . . $ weight_utils_detail/cg_solve(5b34b383020010c8). (const M &A, typename M::vectype &x, |
| 262 | const typename M::vectype &b, double epsilon, int itmax) |
| 263 | { |
| 264 | typename M::vectype r=muladdcxx . . $ weight_utils_detail/muladd(2211ffc31ff52639).(-1.,A.apply(x),b), d(r); |
| 265 | double delta0=dprodcxx . . $ weight_utils_detail/dprod(33345cf21c18115f).(r,r), deltanew=delta0; |
| 266 | coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "res0: " <<cxx . . $ std/basic_ostream#`operator<<`(968942d578224538). sqrt(delta0) <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 267 | for (int iter=0; iter<itmax; ++iter) |
| 268 | { |
| 269 | auto q=A.apply(d); |
| 270 | double alpha = deltanew/cxx . . $ std/`operator/`(804c2413f71972e2).dprodcxx . . $ weight_utils_detail/dprod(33345cf21c18115f).(d,q); |
| 271 | x=muladdcxx . . $ weight_utils_detail/muladd(2211ffc31ff52639).(alpha,d,x); |
| 272 | if (iter%300==0) // get accurate residual |
| 273 | r=muladdcxx . . $ weight_utils_detail/muladd(2211ffc31ff52639).(-1.,A.apply(x),b); |
| 274 | else |
| 275 | r=muladdcxx . . $ weight_utils_detail/muladd(2211ffc31ff52639).(-alpha,q,r); |
| 276 | double deltaold=deltanew; |
| 277 | deltanew=dprodcxx . . $ weight_utils_detail/dprod(33345cf21c18115f).(r,r); |
| 278 | coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "\rIteration " <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). iter |
| 279 | <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ": residual=" <<cxx . . $ std/basic_ostream#`operator<<`(968942d578224538). sqrt(deltanew/delta0) |
| 280 | <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " " <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). flushcxx . . $ std/flush(345bf97a19cc83a9).; |
| 281 | if (deltanew<epsilon*epsilon*delta0) { coutcxx . . $ std/cout. <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). endlcxx . . $ std/endl(345bf97a19cc83a9).; break; } // convergence |
| 282 | double beta=deltanew/deltaold; |
| 283 | d=muladdcxx . . $ weight_utils_detail/muladd(2211ffc31ff52639).(beta,d,r); |
| 284 | } |
| 285 | return sqrt(deltanew/delta0); |
| 286 | } |
| 287 | |
| 288 | class FullWeightImplcxx . . $ weight_utils_detail/FullWeightImpl# |
| 289 | { |
| 290 | private: |
| 291 | STS_hpwgtcxx . . $ weight_utils_detail/STS_hpwgt# matcxx . . $ weight_utils_detail/FullWeightImpl#mat.; |
| 292 | vectorcxx . . $ std/vector#<double> xcxx . . $ weight_utils_detail/FullWeightImpl#x., rhscxx . . $ weight_utils_detail/FullWeightImpl#rhs., rcxx . . $ weight_utils_detail/FullWeightImpl#r., dcxx . . $ weight_utils_detail/FullWeightImpl#d.; |
| 293 | double delta0cxx . . $ weight_utils_detail/FullWeightImpl#delta0., delta_curcxx . . $ weight_utils_detail/FullWeightImpl#delta_cur.; |
| 294 | int itercxx . . $ weight_utils_detail/FullWeightImpl#iter.; |
| 295 | |
| 296 | public: |
| 297 | FullWeightImplcxx . . $ weight_utils_detail/FullWeightImpl#FullWeightImpl(3e454b8ccf442868).(int nside, int lmax) |
| 298 | : matcxx . . $ weight_utils_detail/FullWeightImpl#mat.(lmax, lmax, nside), xcxx . . $ weight_utils_detail/FullWeightImpl#x.(n_weightalmcxx . . $ weight_utils_detail/n_weightalm(beccc266862daf71).(lmax,lmax),0.), itercxx . . $ weight_utils_detail/FullWeightImpl#iter.(0) |
| 299 | { |
| 300 | planck_assertcxx . . $ `cxxsupport/error_handling.h:79:9`!((lmax&1)==0,"lmax must be even"); |
| 301 | rhscxx . . $ weight_utils_detail/FullWeightImpl#rhs. =cxx . . $ std/vector#`operator=`(1104576815caab1a). matcxx . . $ weight_utils_detail/FullWeightImpl#mat..STcxx . . $ weight_utils_detail/STS_hpwgt#ST(be3d5686be3109ae).(vectorcxx . . $ std/vector#vector(229e4d6bd205de31).<double>(n_fullweightscxx . . $ weight_utils_detail/n_fullweights(c104ebd7d68b2193).(nside),-1.)); |
| 302 | rhscxx . . $ weight_utils_detail/FullWeightImpl#rhs.[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).0]+=12*nside*nside/sqrt(4*picxx . . $ pi.); |
| 303 | rcxx . . $ weight_utils_detail/FullWeightImpl#r.=cxx . . $ std/vector#`operator=`(1104576815caab1a).muladdcxx . . $ weight_utils_detail/muladd(2211ffc31ff52639).(-1.,matcxx . . $ weight_utils_detail/FullWeightImpl#mat..applycxx . . $ weight_utils_detail/STS_hpwgt#apply(be3d5686be3109ae).(xcxx . . $ weight_utils_detail/FullWeightImpl#x.),rhscxx . . $ weight_utils_detail/FullWeightImpl#rhs.); |
| 304 | dcxx . . $ weight_utils_detail/FullWeightImpl#d.=cxx . . $ std/vector#`operator=`(e6b68e61becad66f).rcxx . . $ weight_utils_detail/FullWeightImpl#r.; |
| 305 | delta0cxx . . $ weight_utils_detail/FullWeightImpl#delta0.=dprodcxx . . $ weight_utils_detail/dprod(33345cf21c18115f).(rcxx . . $ weight_utils_detail/FullWeightImpl#r.,rcxx . . $ weight_utils_detail/FullWeightImpl#r.); |
| 306 | delta_curcxx . . $ weight_utils_detail/FullWeightImpl#delta_cur.=delta0cxx . . $ weight_utils_detail/FullWeightImpl#delta0.; |
| 307 | } |
| 308 | void iteratecxx . . $ weight_utils_detail/FullWeightImpl#iterate(d4f767463ce0a6b3).(int niter) |
| 309 | { |
| 310 | int iend=itercxx . . $ weight_utils_detail/FullWeightImpl#iter.+niter; |
| 311 | for (; itercxx . . $ weight_utils_detail/FullWeightImpl#iter.<iend; ++itercxx . . $ weight_utils_detail/FullWeightImpl#iter.) |
| 312 | { |
| 313 | auto q=matcxx . . $ weight_utils_detail/FullWeightImpl#mat..applycxx . . $ weight_utils_detail/STS_hpwgt#apply(be3d5686be3109ae).(dcxx . . $ weight_utils_detail/FullWeightImpl#d.); |
| 314 | double alpha = delta_curcxx . . $ weight_utils_detail/FullWeightImpl#delta_cur./dprodcxx . . $ weight_utils_detail/dprod(33345cf21c18115f).(dcxx . . $ weight_utils_detail/FullWeightImpl#d.,q); |
| 315 | xcxx . . $ weight_utils_detail/FullWeightImpl#x.=cxx . . $ std/vector#`operator=`(1104576815caab1a).muladdcxx . . $ weight_utils_detail/muladd(2211ffc31ff52639).(alpha,dcxx . . $ weight_utils_detail/FullWeightImpl#d.,xcxx . . $ weight_utils_detail/FullWeightImpl#x.); |
| 316 | if (itercxx . . $ weight_utils_detail/FullWeightImpl#iter.%300==0) // get accurate residual |
| 317 | rcxx . . $ weight_utils_detail/FullWeightImpl#r.=cxx . . $ std/vector#`operator=`(1104576815caab1a).muladdcxx . . $ weight_utils_detail/muladd(2211ffc31ff52639).(-1.,matcxx . . $ weight_utils_detail/FullWeightImpl#mat..applycxx . . $ weight_utils_detail/STS_hpwgt#apply(be3d5686be3109ae).(xcxx . . $ weight_utils_detail/FullWeightImpl#x.),rhscxx . . $ weight_utils_detail/FullWeightImpl#rhs.); |
| 318 | else |
| 319 | rcxx . . $ weight_utils_detail/FullWeightImpl#r.=cxx . . $ std/vector#`operator=`(1104576815caab1a).muladdcxx . . $ weight_utils_detail/muladd(2211ffc31ff52639).(-alpha,q,rcxx . . $ weight_utils_detail/FullWeightImpl#r.); |
| 320 | double deltaold=delta_curcxx . . $ weight_utils_detail/FullWeightImpl#delta_cur.; |
| 321 | delta_curcxx . . $ weight_utils_detail/FullWeightImpl#delta_cur.=dprodcxx . . $ weight_utils_detail/dprod(33345cf21c18115f).(rcxx . . $ weight_utils_detail/FullWeightImpl#r.,rcxx . . $ weight_utils_detail/FullWeightImpl#r.); |
| 322 | coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "\rIteration " <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). itercxx . . $ weight_utils_detail/FullWeightImpl#iter. |
| 323 | <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ": residual=" <<cxx . . $ std/basic_ostream#`operator<<`(968942d578224538). sqrt(delta_curcxx . . $ weight_utils_detail/FullWeightImpl#delta_cur./delta0cxx . . $ weight_utils_detail/FullWeightImpl#delta0.) |
| 324 | <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " " <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). flushcxx . . $ std/flush(345bf97a19cc83a9).; |
| 325 | double beta=delta_curcxx . . $ weight_utils_detail/FullWeightImpl#delta_cur./deltaold; |
| 326 | dcxx . . $ weight_utils_detail/FullWeightImpl#d.=cxx . . $ std/vector#`operator=`(1104576815caab1a).muladdcxx . . $ weight_utils_detail/muladd(2211ffc31ff52639).(beta,dcxx . . $ weight_utils_detail/FullWeightImpl#d.,rcxx . . $ weight_utils_detail/FullWeightImpl#r.); |
| 327 | } |
| 328 | } |
| 329 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<double> current_almcxx . . $ weight_utils_detail/FullWeightImpl#current_alm(933de244a6110113).() const { return xcxx . . $ std/vector#vector(a1201200cf0efa42).; } |
| 330 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<double> alm2wgtcxx . . $ weight_utils_detail/FullWeightImpl#alm2wgt(be3d5686be3109ae).(const vectorcxx . . $ std/vector#<double> &alm) const |
| 331 | { return matcxx . . $ weight_utils_detail/FullWeightImpl#mat..Scxx . . $ weight_utils_detail/STS_hpwgt#S(be3d5686be3109ae).(alm); } |
| 332 | double current_epsiloncxx . . $ weight_utils_detail/FullWeightImpl#current_epsilon(21b6c25e127938e2).() const { return sqrt(delta_curcxx . . $ weight_utils_detail/FullWeightImpl#delta_cur./delta0cxx . . $ weight_utils_detail/FullWeightImpl#delta0.); } |
| 333 | int current_itercxx . . $ weight_utils_detail/FullWeightImpl#current_iter(455f465bc33b4cdf).() const { return itercxx . . $ weight_utils_detail/FullWeightImpl#iter.; } |
| 334 | }; |
| 335 | |
| 336 | } //namespace weight_utils_detail; |
| 337 | |
| 338 | using namespace weight_utils_detail; |
| 339 | |
| 340 | vectorcxx . . $ std/vector#<double> get_fullweightscxx . . $ get_fullweights(ba056636dd5eb39a).(int nside, int lmax, double epsilon, int itmax, |
| 341 | double &epsilon_out) |
| 342 | { |
| 343 | planck_assertcxx . . $ `cxxsupport/error_handling.h:79:9`!((lmax&1)==0,"lmax must be even"); |
| 344 | STS_hpwgtcxx . . $ weight_utils_detail/STS_hpwgt# matcxx . . $ weight_utils_detail/STS_hpwgt#STS_hpwgt(b1146eedae1e1d0b).(lmax, lmax, nside); |
| 345 | vectorcxx . . $ std/vector#<double> xcxx . . $ std/vector#vector(229e4d6bd205de31).(n_weightalmcxx . . $ weight_utils_detail/n_weightalm(beccc266862daf71).(lmax,lmax),0.); |
| 346 | vectorcxx . . $ std/vector#<double> rhs=mat.STcxx . . $ weight_utils_detail/STS_hpwgt#ST(be3d5686be3109ae).(vectorcxx . . $ std/vector#vector(229e4d6bd205de31).<double> (n_fullweightscxx . . $ weight_utils_detail/n_fullweights(c104ebd7d68b2193).(nside),-1.)); |
| 347 | rhs[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).0]+=12*nside*nside/sqrt(4*picxx . . $ pi.); |
| 348 | epsilon_out=cg_solvecxx . . $ weight_utils_detail/cg_solve(5b34b383020010c8).(mat, x, rhs, epsilon, itmax); |
| 349 | return mat.Scxx . . $ weight_utils_detail/STS_hpwgt#S(be3d5686be3109ae).(x); |
| 350 | } |
| 351 | |
| 352 | FullWeightComputercxx . . $ FullWeightComputer#::FullWeightComputercxx . . $ FullWeightComputer#FullWeightComputer(3e454b8ccf442868).(int nside, int lmax) |
| 353 | : implcxx . . $ FullWeightComputer#impl.(new FullWeightImplcxx . . $ weight_utils_detail/FullWeightImpl#FullWeightImpl(3e454b8ccf442868).(nside, lmax)) {} |
| 354 | |
| 355 | FullWeightComputercxx . . $ FullWeightComputer#::~cxx . . $ FullWeightComputer#`~FullWeightComputer`(ced63f7c635d850d).FullWeightComputercxx . . $ FullWeightComputer#() {} |
| 356 | |
| 357 | void FullWeightComputercxx . . $ FullWeightComputer#::iteratecxx . . $ FullWeightComputer#iterate(d4f767463ce0a6b3).(int niter) { implcxx . . $ FullWeightComputer#impl.->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).iteratecxx . . $ weight_utils_detail/FullWeightImpl#iterate(d4f767463ce0a6b3).(niter); } |
| 358 | |
| 359 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<double> FullWeightComputercxx . . $ FullWeightComputer#::current_almcxx . . $ FullWeightComputer#current_alm(933de244a6110113).() const |
| 360 | { return implcxx . . $ FullWeightComputer#impl.->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).current_almcxx . . $ weight_utils_detail/FullWeightImpl#current_alm(933de244a6110113).(); } |
| 361 | |
| 362 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<double> FullWeightComputercxx . . $ FullWeightComputer#::alm2wgtcxx . . $ FullWeightComputer#alm2wgt(be3d5686be3109ae).(const vectorcxx . . $ std/vector#<double> &alm) const |
| 363 | { return implcxx . . $ FullWeightComputer#impl.->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).alm2wgtcxx . . $ weight_utils_detail/FullWeightImpl#alm2wgt(be3d5686be3109ae).(alm); } |
| 364 | |
| 365 | double FullWeightComputercxx . . $ FullWeightComputer#::current_epsiloncxx . . $ FullWeightComputer#current_epsilon(21b6c25e127938e2).() const |
| 366 | { return implcxx . . $ FullWeightComputer#impl.->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).current_epsiloncxx . . $ weight_utils_detail/FullWeightImpl#current_epsilon(21b6c25e127938e2).(); } |
| 367 | |
| 368 | int FullWeightComputercxx . . $ FullWeightComputer#::current_itercxx . . $ FullWeightComputer#current_iter(455f465bc33b4cdf).() const |
| 369 | { return implcxx . . $ FullWeightComputer#impl.->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).current_itercxx . . $ weight_utils_detail/FullWeightImpl#current_iter(455f465bc33b4cdf).(); } |
| 370 | |
| 371 | template <typename T> void apply_fullweightscxx . . $ apply_fullweights(eaacd2364977c880). (Healpix_Mapcxx . . $ Healpix_Map#<T> &map, |
| 372 | const vectorcxx . . $ std/vector#<double> &wgt) |
| 373 | { apply_fullweightscxx . . $ apply_fullweights(eaacd2364977c880). (map,wgt,false); } |
| 374 | |
| 375 | template void apply_fullweights (Healpix_Map<float> &map, |
| 376 | const vector<double> &wgt); |
| 377 | template void apply_fullweights (Healpix_Map<double> &map, |
| 378 | const vector<double> &wgt); |
| 379 | |
| 380 | vectorcxx . . $ std/vector#<double> get_ringweightscxx . . $ get_ringweights(ba056636dd5eb39a).(int nside, int lmax, double epsilon, int itmax, |
| 381 | double &epsilon_out) |
| 382 | { |
| 383 | planck_assertcxx . . $ `cxxsupport/error_handling.h:79:9`!((lmax&1)==0,"lmax must be even"); |
| 384 | STS_hpringcxx . . $ weight_utils_detail/STS_hpring# matcxx . . $ weight_utils_detail/STS_hpring#STS_hpring(3e454b8ccf442868).(lmax,nside); |
| 385 | vectorcxx . . $ std/vector#<double> nircxx . . $ std/vector#vector(83fdeebbe0501a83).(2*nside), xcxx . . $ std/vector#vector(229e4d6bd205de31).(lmax/2+1,0.); |
| 386 | for (tsizecxx . . $ tsize# ith=0; ith<nir.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); ++ith) |
| 387 | nir[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).ith]=8*mincxx . . $ std/min(2a338fce5842aa6a).<int>(ith+1,nside); |
| 388 | nir[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).2*nside-1]/=2; |
| 389 | auto b=mat.STcxx . . $ weight_utils_detail/STS_hpring#ST(be3d5686be3109ae).(nir); |
| 390 | for (tsizecxx . . $ tsize# i=0; i<b.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); ++i) |
| 391 | b[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i]=-b[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i]; |
| 392 | b[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).0]+=12*nside*nside/sqrt(4*picxx . . $ pi.); |
| 393 | epsilon_out=cg_solvecxx . . $ weight_utils_detail/cg_solve(5b34b383020010c8).(mat, x, b, epsilon, itmax); |
| 394 | auto mtmp=mat.Scxx . . $ weight_utils_detail/STS_hpring#S(be3d5686be3109ae).(x); |
| 395 | for (tsizecxx . . $ tsize# i=0; i<mtmp.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); ++i) |
| 396 | mtmp[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i]/=nir[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i]; |
| 397 | return mtmpcxx . . $ std/vector#vector(6f559d22b039ccdb).; |
| 398 | } |