@@ -637,9 +637,11 @@ namespace BasisClasses
637637 }
638638
639639 if (pcavar) {
640- Eigen::VectorXd g = potd[tid].row (l).transpose () * fac * norm;
640+ Eigen::VectorXcd g = std::exp (std::complex <double >(0.0 , m*phi)) *
641+ potd[tid].row (l).transpose () * fac * norm;
642+
641643 meanV[T][L].noalias () += g * mass;
642- covrV[T][L].noalias () += g * g.transpose () * mass;
644+ covrV[T][L].noalias () += g * g.adjoint () * mass;
643645 }
644646
645647 }
@@ -1547,8 +1549,7 @@ namespace BasisClasses
15471549 EmpCylSL::CMAPZ = cmapZ;
15481550 EmpCylSL::logarithmic = logarithmic;
15491551 EmpCylSL::VFLAG = vflag;
1550- EmpCylSL::PCAVAR = pcavar;
1551-
1552+
15521553 // Check for non-null cache file name. This must be specified
15531554 // to prevent recomputation and unexpected behavior.
15541555 //
@@ -1570,9 +1571,9 @@ namespace BasisClasses
15701571 //
15711572 if (mlim>=0 ) sl->set_mlim (mlim);
15721573 if (EVEN_M ) sl->setEven (EVEN_M );
1573- if (sampT> 0 ) {
1574+ if (pcavar ) {
15741575 sl->setSampT (sampT);
1575- sl->init_pca ( );
1576+ sl->set_covar ( true );
15761577 }
15771578
15781579 // Cache override for old Eigen cache
@@ -4869,28 +4870,56 @@ namespace BasisClasses
48694870 size_t lmax = covar[T].size ();
48704871 size_t nmax = std::get<0 >(covar[T][0 ]).rows ();
48714872
4872- Eigen::VectorXd data (lmax*nmax);
4873- for (size_t l=0 , c=0 ; l<lmax; l++) {
4874- for (size_t n=0 ; n<nmax; n++, c++) {
4875- data (c) = std::get<0 >(covar[T][l])(n);
4873+ if (floatType) {
4874+ Eigen::VectorXcf data (lmax*nmax);
4875+
4876+ for (size_t l=0 , c=0 ; l<lmax; l++) {
4877+ for (size_t n=0 ; n<nmax; n++, c++) {
4878+ data (c) = static_cast <std::complex <float >>
4879+ (std::get<0 >(covar[T][l])(n));
4880+ }
48764881 }
4877- }
48784882
4879- HighFive::DataSet coefdata = sample.createDataSet (" coefficients" , data);
4883+ HighFive::DataSet coefdata = sample.createDataSet (" coefficients" , data);
48804884
4881- // Pack the covariance data in an upper triangular format
4882- //
4883- size_t diagonalSize = nmax*(nmax + 1 )/2 ;
4884- data.resize (lmax*diagonalSize);
4885- for (size_t l=0 , c=0 ; l<lmax; l++) {
4886- for (size_t n1=0 ; n1<nmax; n1++) {
4887- for (size_t n2=n1; n2<nmax; n2++, c++) {
4888- data (c) = std::get<1 >(covar[T][l])(n1, n2);
4885+ // Pack the covariance data in an upper triangular format
4886+ //
4887+ size_t diagonalSize = nmax*(nmax + 1 )/2 ;
4888+ data.resize (lmax*diagonalSize);
4889+ for (size_t l=0 , c=0 ; l<lmax; l++) {
4890+ for (size_t n1=0 ; n1<nmax; n1++) {
4891+ for (size_t n2=n1; n2<nmax; n2++, c++) {
4892+ data (c) = static_cast <std::complex <float >>
4893+ (std::get<1 >(covar[T][l])(n1, n2));
4894+ }
4895+ }
4896+ }
4897+
4898+ HighFive::DataSet covdata = sample.createDataSet (" covariance" , data);
4899+ } else {
4900+ Eigen::VectorXcd data (lmax*nmax);
4901+ for (size_t l=0 , c=0 ; l<lmax; l++) {
4902+ for (size_t n=0 ; n<nmax; n++, c++) {
4903+ data (c) = std::get<0 >(covar[T][l])(n);
48894904 }
48904905 }
4891- }
48924906
4893- HighFive::DataSet covdata = sample.createDataSet (" covariance" , data);
4907+ HighFive::DataSet coefdata = sample.createDataSet (" coefficients" , data);
4908+
4909+ // Pack the covariance data in an upper triangular format
4910+ //
4911+ size_t diagonalSize = nmax*(nmax + 1 )/2 ;
4912+ data.resize (lmax*diagonalSize);
4913+ for (size_t l=0 , c=0 ; l<lmax; l++) {
4914+ for (size_t n1=0 ; n1<nmax; n1++) {
4915+ for (size_t n2=n1; n2<nmax; n2++, c++) {
4916+ data (c) = std::get<1 >(covar[T][l])(n1, n2);
4917+ }
4918+ }
4919+ }
4920+
4921+ HighFive::DataSet covdata = sample.createDataSet (" covariance" , data);
4922+ }
48944923 }
48954924 // END: sample loop
48964925
@@ -4952,10 +4981,15 @@ namespace BasisClasses
49524981 //
49534982 file.createAttribute <std::string>(" CovarianceFileVersion" , HighFive::DataSpace::From (CovarianceFileVersion)).write (CovarianceFileVersion);
49544983
4955- // We write the basis identifier string
4984+ // Write the basis identifier string
49564985 //
49574986 file.createAttribute <std::string>(" BasisID" , HighFive::DataSpace::From (BasisID)).write (BasisID);
49584987
4988+ // Write the data type size
4989+ //
4990+ int sz = 8 ; if (floatType) sz = 4 ;
4991+ file.createAttribute <int >(" FloatSize" , HighFive::DataSpace::From (sz)).write (sz);
4992+
49594993 // Write the specific parameters
49604994 //
49614995 writeCovarH5Params (file);
@@ -5037,6 +5071,16 @@ namespace BasisClasses
50375071 //
50385072 file.getAttribute (" BasisID" ).read (basisID);
50395073
5074+ // Get the float size
5075+ int sz = 8 ;
5076+ file.getAttribute (" FloatSize" ).read (sz);
5077+ if (sz != 4 and sz != 8 ) {
5078+ std::ostringstream sout;
5079+ sout << " CovarianceReader: unsupported float size, " << sz;
5080+ throw std::runtime_error (sout.str ());
5081+ }
5082+ std::cout << " Float size is " << sz << std::endl;
5083+
50405084 int lmax, nmax, ltot;
50415085
50425086 // Current implemented spherical types
@@ -5102,7 +5146,7 @@ namespace BasisClasses
51025146 HighFive::Group sample = stanza.getGroup (sT .str ());
51035147
51045148 // Storage
5105- Eigen::VectorXd data;
5149+ Eigen::VectorXcd data;
51065150
51075151 // Repack the data
51085152 std::vector<CoefCovarType> elem (ltot);
@@ -5112,7 +5156,13 @@ namespace BasisClasses
51125156 }
51135157
51145158 // Get the flattened coefficient array
5115- data = sample.getDataSet (" coefficients" ).read <Eigen::VectorXd>();
5159+ if (sz==4 ) {
5160+ Eigen::VectorXcf dataF;
5161+ dataF = sample.getDataSet (" coefficients" ).read <Eigen::VectorXcf>();
5162+ data = dataF.cast <std::complex <double >>();
5163+ } else {
5164+ data = sample.getDataSet (" coefficients" ).read <Eigen::VectorXcd>();
5165+ }
51165166
51175167 // Pack the coefficient data
51185168 for (size_t l=0 , c=0 ; l<ltot; l++) {
@@ -5122,7 +5172,13 @@ namespace BasisClasses
51225172 }
51235173
51245174 // Get the flattened covariance array
5125- data = sample.getDataSet (" covariance" ).read <Eigen::VectorXd>();
5175+ if (sz==4 ) {
5176+ Eigen::VectorXcf dataF;
5177+ dataF = sample.getDataSet (" covariance" ).read <Eigen::VectorXcf>();
5178+ data = dataF.cast <std::complex <double >>();
5179+ } else {
5180+ data = sample.getDataSet (" covariance" ).read <Eigen::VectorXcd>();
5181+ }
51265182
51275183 // Pack the coefficient data
51285184 for (size_t l=0 , c=0 ; l<ltot; l++) {
0 commit comments