Skip to content

Commit 5d6b306

Browse files
ilfreddyRoberto Di Remigio
authored andcommitted
Fixed default template parameter problem for non C++11 compilers
1 parent 29a2785 commit 5d6b306

File tree

7 files changed

+31
-31
lines changed

7 files changed

+31
-31
lines changed

src/cavity/Cavity.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,23 +92,23 @@ void Cavity::loadCavity(const std::string & fname)
9292
// 1. Get the weights
9393
cnpy::NpyArray raw_weights = loaded_cavity["weights"];
9494
if (raw_weights.shape[0] != nElements_) PCMSOLVER_ERROR("elementArea_: incoherent dimensions read in", BOOST_CURRENT_FUNCTION);
95-
elementArea_ = cnpy::custom::npy_to_eigen(raw_weights);
95+
elementArea_ = cnpy::custom::npy_to_eigen<double>(raw_weights);
9696
// 2. Get the element sphere center
9797
cnpy::NpyArray raw_elSphCenter = loaded_cavity["elSphCenter"];
9898
if (raw_elSphCenter.shape[1] != nElements_) PCMSOLVER_ERROR("elementSphereCenter_: incoherent dimensions read in", BOOST_CURRENT_FUNCTION);
99-
elementSphereCenter_ = cnpy::custom::npy_to_eigen(raw_elSphCenter);
99+
elementSphereCenter_ = cnpy::custom::npy_to_eigen<double>(raw_elSphCenter);
100100
// 3. Get the element radius
101101
cnpy::NpyArray raw_elRadius = loaded_cavity["elRadius"];
102102
if (raw_elRadius.shape[0] != nElements_) PCMSOLVER_ERROR("elementRadius_: incoherent dimensions read in", BOOST_CURRENT_FUNCTION);
103-
elementRadius_ = cnpy::custom::npy_to_eigen(raw_elRadius);
103+
elementRadius_ = cnpy::custom::npy_to_eigen<double>(raw_elRadius);
104104
// 4. Get the centers
105105
cnpy::NpyArray raw_centers = loaded_cavity["centers"];
106106
if (raw_centers.shape[1] != nElements_) PCMSOLVER_ERROR("elementCenter_: incoherent dimensions read in", BOOST_CURRENT_FUNCTION);
107-
elementCenter_ = cnpy::custom::npy_to_eigen(raw_centers);
107+
elementCenter_ = cnpy::custom::npy_to_eigen<double>(raw_centers);
108108
// 5. Get the normal vectors
109109
cnpy::NpyArray raw_normals = loaded_cavity["normals"];
110110
if (raw_normals.shape[1] != nElements_) PCMSOLVER_ERROR("elementNormal_: incoherent dimensions read in", BOOST_CURRENT_FUNCTION);
111-
elementNormal_ = cnpy::custom::npy_to_eigen(raw_normals);
111+
elementNormal_ = cnpy::custom::npy_to_eigen<double>(raw_normals);
112112

113113
// Reconstruct the elements_ vector
114114
for (size_t i = 0; i < nElements_; ++i) {

src/interface/Meddle.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ namespace pcm {
308308
std::string functionName(name);
309309
printer("\nLoading surface function " + functionName + " from .npy file");
310310
std::string fname = functionName + ".npy";
311-
Eigen::VectorXd values = cnpy::custom::npy_load(fname);
311+
Eigen::VectorXd values = cnpy::custom::npy_load<double>(fname);
312312
// This is to avoid a -Wsign-compare warning
313313
typedef EIGEN_DEFAULT_DENSE_INDEX_TYPE Index;
314314
if (values.size() != Index(cavity_->size())) PCMSOLVER_ERROR("Inconsistent dimension of loaded surface function!", BOOST_CURRENT_FUNCTION);

src/utils/MathUtils.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ namespace cnpy
335335
* \tparam Rows number of rows in the Eigen object. Default is dynamic
336336
e \tparam Cols number of columns in the Eigen object. Default is dynamic
337337
*/
338-
template <typename Scalar = double, int Rows = Eigen::Dynamic, int Cols = Eigen::Dynamic>
338+
template <typename Scalar, int Rows, int Cols>
339339
inline void npy_save(const std::string & fname, const Eigen::Matrix<Scalar, Rows, Cols> & obj)
340340
{
341341
unsigned int rows = static_cast<unsigned int>(obj.rows());
@@ -353,7 +353,7 @@ namespace cnpy
353353
* \tparam Rows number of rows in the Eigen object. Default is dynamic
354354
* \tparam Cols number of columns in the Eigen object. Default is dynamic
355355
*/
356-
template <typename Scalar = double, int Rows = Eigen::Dynamic, int Cols = Eigen::Dynamic>
356+
template <typename Scalar, int Rows, int Cols>
357357
inline void npz_save(const std::string & fname, const std::string & name,
358358
const Eigen::Matrix<Scalar, Rows, Cols> & obj,
359359
bool overwrite = false)
@@ -374,7 +374,7 @@ namespace cnpy
374374
* \warning We check that the rank of the object read is not more than 2
375375
* Eigen cannot handle general tensors.
376376
*/
377-
template <typename Scalar = double>
377+
template <typename Scalar>
378378
inline Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> npy_to_eigen(const NpyArray & npy_array)
379379
{
380380
if (npy_array.shape.size() > 2) PCMSOLVER_ERROR("Only vectors and matrices can be read into Eigen objects.", BOOST_CURRENT_FUNCTION);
@@ -388,10 +388,10 @@ namespace cnpy
388388
*
389389
* \todo Extend to read in also data in row-major (C) storage order
390390
*/
391-
template <typename Scalar = double>
391+
template <typename Scalar>
392392
inline Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> npy_load(const std::string & fname)
393393
{
394-
return npy_to_eigen(cnpy::npy_load(fname));
394+
return npy_to_eigen<Scalar>(cnpy::npy_load(fname));
395395
}
396396
} // namespace custom
397397
/*! @} */

tests/bi_operators/bi_operators_collocation.cpp.in

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ SCENARIO("A collocation integrator with approximate diagonal elements", "[bi_ope
6464
THEN("the matrix elements of S are")
6565
{
6666
results = gf.singleLayer(cavity.elements());
67-
reference = cnpy::custom::npy_load("@CMAKE_CURRENT_LIST_DIR@/vacuum_S_collocation.npy");
67+
reference = cnpy::custom::npy_load<double>("@CMAKE_CURRENT_LIST_DIR@/vacuum_S_collocation.npy");
6868
for (size_t i = 0; i < cavity.size(); ++i) {
6969
for (size_t j = 0; j < cavity.size(); ++j) {
7070
REQUIRE(reference(i, j) == Approx(results(i, j)));
@@ -74,7 +74,7 @@ SCENARIO("A collocation integrator with approximate diagonal elements", "[bi_ope
7474
AND_THEN("the matrix elements of D are")
7575
{
7676
results = gf.doubleLayer(cavity.elements());
77-
reference = cnpy::custom::npy_load("@CMAKE_CURRENT_LIST_DIR@/vacuum_D_collocation.npy");
77+
reference = cnpy::custom::npy_load<double>("@CMAKE_CURRENT_LIST_DIR@/vacuum_D_collocation.npy");
7878
for (size_t i = 0; i < cavity.size(); ++i) {
7979
for (size_t j = 0; j < cavity.size(); ++j) {
8080
REQUIRE(reference(i, j) == Approx(results(i, j)));
@@ -93,7 +93,7 @@ SCENARIO("A collocation integrator with approximate diagonal elements", "[bi_ope
9393
THEN("the matrix elements of S are")
9494
{
9595
results = gf.singleLayer(cavity.elements());
96-
reference = cnpy::custom::npy_load("@CMAKE_CURRENT_LIST_DIR@/uniformdielectric_S_collocation.npy");
96+
reference = cnpy::custom::npy_load<double>("@CMAKE_CURRENT_LIST_DIR@/uniformdielectric_S_collocation.npy");
9797
for (size_t i = 0; i < cavity.size(); ++i) {
9898
for (size_t j = 0; j < cavity.size(); ++j) {
9999
REQUIRE(reference(i, j) == Approx(results(i, j)));
@@ -103,7 +103,7 @@ SCENARIO("A collocation integrator with approximate diagonal elements", "[bi_ope
103103
AND_THEN("the matrix elements of D are")
104104
{
105105
results = gf.doubleLayer(cavity.elements());
106-
reference = cnpy::custom::npy_load("@CMAKE_CURRENT_LIST_DIR@/uniformdielectric_D_collocation.npy");
106+
reference = cnpy::custom::npy_load<double>("@CMAKE_CURRENT_LIST_DIR@/uniformdielectric_D_collocation.npy");
107107
for (size_t i = 0; i < cavity.size(); ++i) {
108108
for (size_t j = 0; j < cavity.size(); ++j) {
109109
REQUIRE(reference(i, j) == Approx(results(i, j)));
@@ -124,7 +124,7 @@ SCENARIO("A collocation integrator with approximate diagonal elements", "[bi_ope
124124
THEN("the matrix elements of S are")
125125
{
126126
results = gf.singleLayer(cavity.elements());
127-
reference = cnpy::custom::npy_load("@CMAKE_CURRENT_LIST_DIR@/tanhsphericaldiffuse_S_collocation.npy");
127+
reference = cnpy::custom::npy_load<double>("@CMAKE_CURRENT_LIST_DIR@/tanhsphericaldiffuse_S_collocation.npy");
128128
for (size_t i = 0; i < cavity.size(); ++i) {
129129
for (size_t j = 0; j < cavity.size(); ++j) {
130130
REQUIRE(reference(i, j) == Approx(results(i, j)));
@@ -134,7 +134,7 @@ SCENARIO("A collocation integrator with approximate diagonal elements", "[bi_ope
134134
AND_THEN("the matrix elements of D are")
135135
{
136136
results = gf.doubleLayer(cavity.elements());
137-
reference = cnpy::custom::npy_load("@CMAKE_CURRENT_LIST_DIR@/tanhsphericaldiffuse_D_collocation.npy");
137+
reference = cnpy::custom::npy_load<double>("@CMAKE_CURRENT_LIST_DIR@/tanhsphericaldiffuse_D_collocation.npy");
138138
for (size_t i = 0; i < cavity.size(); ++i) {
139139
for (size_t j = 0; j < cavity.size(); ++j) {
140140
REQUIRE(reference(i, j) == Approx(results(i, j)));

tests/bi_operators/bi_operators_numerical.cpp.in

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ SCENARIO("A collocation integrator with numerical integrator of the diagonal ele
6565
results = gf.singleLayer(cavity.elements());
6666
// Numerical integrator not really working now...
6767
/*
68-
reference = cnpy::custom::npy_load("@CMAKE_CURRENT_LIST_DIR@/vacuum_S_numerical.npy");
68+
reference = cnpy::custom::npy_load<double>("@CMAKE_CURRENT_LIST_DIR@/vacuum_S_numerical.npy");
6969
for (size_t i = 0; i < cavity.size(); ++i) {
7070
for (size_t j = 0; j < cavity.size(); ++j) {
7171
REQUIRE(reference(i, j) == Approx(results(i, j)));
@@ -78,7 +78,7 @@ SCENARIO("A collocation integrator with numerical integrator of the diagonal ele
7878
Eigen::MatrixXd results = gf.doubleLayer(cavity.elements());
7979
// Numerical integrator not really working now...
8080
/*
81-
reference = cnpy::custom::npy_load("@CMAKE_CURRENT_LIST_DIR@/vacuum_D_numerical.npy");
81+
reference = cnpy::custom::npy_load<double>("@CMAKE_CURRENT_LIST_DIR@/vacuum_D_numerical.npy");
8282
for (size_t i = 0; i < cavity.size(); ++i) {
8383
for (size_t j = 0; j < cavity.size(); ++j) {
8484
REQUIRE(reference(i, j) == Approx(results(i, j)));
@@ -102,7 +102,7 @@ SCENARIO("A collocation integrator with numerical integrator of the diagonal ele
102102
results = gf.singleLayer(cavity.elements());
103103
// Numerical integrator not really working now...
104104
/*
105-
reference = cnpy::custom::npy_load("@CMAKE_CURRENT_LIST_DIR@/uniformdielectric_S_numerical.npy");
105+
reference = cnpy::custom::npy_load<double>("@CMAKE_CURRENT_LIST_DIR@/uniformdielectric_S_numerical.npy");
106106
for (size_t i = 0; i < cavity.size(); ++i) {
107107
for (size_t j = 0; j < cavity.size(); ++j) {
108108
REQUIRE(reference(i, j) == Approx(results(i, j)));
@@ -115,7 +115,7 @@ SCENARIO("A collocation integrator with numerical integrator of the diagonal ele
115115
Eigen::MatrixXd results = gf.doubleLayer(cavity.elements());
116116
// Numerical integrator not really working now...
117117
/*
118-
reference = cnpy::custom::npy_load("@CMAKE_CURRENT_LIST_DIR@/uniformdielectric_D_numerical.npy");
118+
reference = cnpy::custom::npy_load<double>("@CMAKE_CURRENT_LIST_DIR@/uniformdielectric_D_numerical.npy");
119119
for (size_t i = 0; i < cavity.size(); ++i) {
120120
for (size_t j = 0; j < cavity.size(); ++j) {
121121
REQUIRE(reference(i, j) == Approx(results(i, j)));
@@ -138,7 +138,7 @@ SCENARIO("A collocation integrator with numerical integrator of the diagonal ele
138138
results = gf.singleLayer(cavity.elements());
139139
// Numerical integrator not really working now...
140140
/*
141-
reference = cnpy::custom::npy_load("@CMAKE_CURRENT_LIST_DIR@/ionicliquid_S_numerical.npy");
141+
reference = cnpy::custom::npy_load<double>("@CMAKE_CURRENT_LIST_DIR@/ionicliquid_S_numerical.npy");
142142
for (size_t i = 0; i < cavity.size(); ++i) {
143143
for (size_t j = 0; j < cavity.size(); ++j) {
144144
REQUIRE(reference(i, j) == Approx(results(i, j)));
@@ -151,7 +151,7 @@ SCENARIO("A collocation integrator with numerical integrator of the diagonal ele
151151
results = gf.doubleLayer(cavity.elements());
152152
// Numerical integrator not really working now...
153153
/*
154-
reference = cnpy::custom::npy_load("@CMAKE_CURRENT_LIST_DIR@/ionicliquid_D_numerical.npy");
154+
reference = cnpy::custom::npy_load<double>("@CMAKE_CURRENT_LIST_DIR@/ionicliquid_D_numerical.npy");
155155
for (size_t i = 0; i < cavity.size(); ++i) {
156156
for (size_t j = 0; j < cavity.size(); ++j) {
157157
REQUIRE(reference(i, j) == Approx(results(i, j)));
@@ -174,7 +174,7 @@ SCENARIO("A collocation integrator with numerical integrator of the diagonal ele
174174
results = gf.singleLayer(cavity.elements());
175175
// Numerical integrator not really working now...
176176
/*
177-
reference = cnpy::custom::npy_load("@CMAKE_CURRENT_LIST_DIR@/anisotropicliquid_S_numerical.npy");
177+
reference = cnpy::custom::npy_load<double>("@CMAKE_CURRENT_LIST_DIR@/anisotropicliquid_S_numerical.npy");
178178
for (size_t i = 0; i < cavity.size(); ++i) {
179179
for (size_t j = 0; j < cavity.size(); ++j) {
180180
REQUIRE(reference(i, j) == Approx(results(i, j)));
@@ -187,7 +187,7 @@ SCENARIO("A collocation integrator with numerical integrator of the diagonal ele
187187
results = gf.doubleLayer(cavity.elements());
188188
// Numerical integrator not really working now...
189189
/*
190-
reference = cnpy::custom::npy_load("@CMAKE_CURRENT_LIST_DIR@/anisotropicliquid_D_numerical.npy");
190+
reference = cnpy::custom::npy_load<double>("@CMAKE_CURRENT_LIST_DIR@/anisotropicliquid_D_numerical.npy");
191191
for (size_t i = 0; i < cavity.size(); ++i) {
192192
for (size_t j = 0; j < cavity.size(); ++j) {
193193
REQUIRE(reference(i, j) == Approx(results(i, j)));

tests/bi_operators/bi_operators_purisima.cpp.in

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ SCENARIO("A collocation integrator with diagonal elements according to Purisima
6464
THEN("the matrix elements of S are")
6565
{
6666
results = gf.singleLayer(cavity.elements());
67-
reference = cnpy::custom::npy_load("@CMAKE_CURRENT_LIST_DIR@/vacuum_S_collocation.npy");
67+
reference = cnpy::custom::npy_load<double>("@CMAKE_CURRENT_LIST_DIR@/vacuum_S_collocation.npy");
6868
for (size_t i = 0; i < cavity.size(); ++i) {
6969
for (size_t j = 0; j < cavity.size(); ++j) {
7070
REQUIRE(reference(i, j) == Approx(results(i, j)));
@@ -74,7 +74,7 @@ SCENARIO("A collocation integrator with diagonal elements according to Purisima
7474
AND_THEN("the matrix elements of D are")
7575
{
7676
results = gf.doubleLayer(cavity.elements());
77-
reference = cnpy::custom::npy_load("@CMAKE_CURRENT_LIST_DIR@/vacuum_D_purisima.npy");
77+
reference = cnpy::custom::npy_load<double>("@CMAKE_CURRENT_LIST_DIR@/vacuum_D_purisima.npy");
7878
for (size_t i = 0; i < cavity.size(); ++i) {
7979
for (size_t j = 0; j < cavity.size(); ++j) {
8080
REQUIRE(reference(i, j) == Approx(results(i, j)));
@@ -93,7 +93,7 @@ SCENARIO("A collocation integrator with diagonal elements according to Purisima
9393
THEN("the matrix elements of S are")
9494
{
9595
results = gf.singleLayer(cavity.elements());
96-
reference = cnpy::custom::npy_load("@CMAKE_CURRENT_LIST_DIR@/uniformdielectric_S_collocation.npy");
96+
reference = cnpy::custom::npy_load<double>("@CMAKE_CURRENT_LIST_DIR@/uniformdielectric_S_collocation.npy");
9797
for (size_t i = 0; i < cavity.size(); ++i) {
9898
for (size_t j = 0; j < cavity.size(); ++j) {
9999
REQUIRE(reference(i, j) == Approx(results(i, j)));
@@ -103,7 +103,7 @@ SCENARIO("A collocation integrator with diagonal elements according to Purisima
103103
AND_THEN("the matrix elements of D are")
104104
{
105105
results = gf.doubleLayer(cavity.elements());
106-
reference = cnpy::custom::npy_load("@CMAKE_CURRENT_LIST_DIR@/uniformdielectric_D_purisima.npy");
106+
reference = cnpy::custom::npy_load<double>("@CMAKE_CURRENT_LIST_DIR@/uniformdielectric_D_purisima.npy");
107107
for (size_t i = 0; i < cavity.size(); ++i) {
108108
for (size_t j = 0; j < cavity.size(); ++j) {
109109
REQUIRE(reference(i, j) == Approx(results(i, j)));

tests/numerical_quadrature/numerical_quadrature.cpp.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ SCENARIO("Numerical quadrature of functions", "[numerical_quadrature]")
130130
// In case you need to update the reference files...
131131
cnpy::custom::npy_save("molecule.npy", results);
132132
*/
133-
reference = cnpy::custom::npy_load("@CMAKE_CURRENT_LIST_DIR@/molecule.npy");
133+
reference = cnpy::custom::npy_load<double>("@CMAKE_CURRENT_LIST_DIR@/molecule.npy");
134134

135135
for (size_t i = 0; i < cavity.size(); ++i) {
136136
REQUIRE(results(i) == Approx(reference(i)));
@@ -158,7 +158,7 @@ SCENARIO("Numerical quadrature of functions", "[numerical_quadrature]")
158158
// In case you need to update the reference files...
159159
cnpy::custom::npy_save("molecule_1r.npy", results);
160160
*/
161-
reference = cnpy::custom::npy_load("@CMAKE_CURRENT_LIST_DIR@/molecule_1r.npy");
161+
reference = cnpy::custom::npy_load<double>("@CMAKE_CURRENT_LIST_DIR@/molecule_1r.npy");
162162

163163
for (size_t i = 0; i < cavity.size(); ++i) {
164164
REQUIRE(results(i) == Approx(reference(i)));

0 commit comments

Comments
 (0)