Skip to content

Commit cec3cc9

Browse files
authored
Warning removal (#274)
* removed all warnings; tested with clang21 on macOS 26 on M4 processor * fixed failing tests * included suggestion; fix for compiling mrchem+mrcpp on mac
1 parent 14ebd2d commit cec3cc9

25 files changed

+77
-109
lines changed

src/core/CrossCorrelation.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,11 @@ void CrossCorrelation::readCCCBin() {
106106
int K = this->order + 1;
107107
this->Left = MatrixXd::Zero(K * K, 2 * K);
108108
this->Right = MatrixXd::Zero(K * K, 2 * K);
109-
double dL[2 * K];
110-
double dR[2 * K];
109+
std::vector<double> dL(2 * K);
110+
std::vector<double> dR(2 * K);
111111
for (int i = 0; i < K * K; i++) {
112-
L_fis.read((char *)dL, sizeof(double) * 2 * K);
113-
R_fis.read((char *)dR, sizeof(double) * 2 * K);
112+
L_fis.read(reinterpret_cast<char *>(dL.data()), sizeof(double) * 2 * K);
113+
R_fis.read(reinterpret_cast<char *>(dR.data()), sizeof(double) * 2 * K);
114114
for (int j = 0; j < 2 * K; j++) {
115115
if (std::abs(dL[j]) < MachinePrec) dL[j] = 0.0;
116116
if (std::abs(dR[j]) < MachinePrec) dR[j] = 0.0;

src/core/MWFilter.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,14 +206,14 @@ void MWFilter::generateBlocks() {
206206

207207
int K = this->order + 1;
208208

209-
double dH[K];
210-
double dG[K];
209+
std::vector<double> dH(K);
210+
std::vector<double> dG(K);
211211
/* read H0 and G0 from disk */
212212
this->G0 = Eigen::MatrixXd::Zero(K, K);
213213
this->H0 = Eigen::MatrixXd::Zero(K, K);
214214
for (int i = 0; i < K; i++) {
215-
H_fis.read((char *)dH, sizeof(double) * K);
216-
G_fis.read((char *)dG, sizeof(double) * K);
215+
H_fis.read(reinterpret_cast<char *>(dH.data()), sizeof(double) * K);
216+
G_fis.read(reinterpret_cast<char *>(dG.data()), sizeof(double) * K);
217217
for (int j = 0; j < K; j++) {
218218
this->G0(i, j) = dG[j]; // G0
219219
this->H0(i, j) = dH[j]; // H0

src/functions/Gaussian.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@ template <int D> GaussExp<D> Gaussian<D>::periodify(const std::array<double, D>
194194
auto needed_cells_vec = std::vector<int>();
195195
for (auto i = 0; i < D; i++) {
196196
auto upper_bound = pos[i] + x_std;
197-
auto lower_bound = pos[i] - x_std;
198197
// number of cells upp and down relative to the center of the Gaussian
199198
needed_cells_vec.push_back(std::ceil(upper_bound / period[i]));
200199
}

src/treebuilders/ABGVCalculator.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ ABGVCalculator::ABGVCalculator(const ScalingBasis &basis, double a, double b)
4848

4949
void ABGVCalculator::calcValueVectors(const ScalingBasis &basis) {
5050
int kp1 = basis.getQuadratureOrder();
51-
double sqrtCoef[kp1];
51+
std::vector<double> sqrtCoef(kp1);
5252
for (int i = 0; i < kp1; i++) { sqrtCoef[i] = std::sqrt(2.0 * i + 1.0); }
5353

5454
switch (basis.getScalingType()) {
@@ -74,7 +74,7 @@ void ABGVCalculator::calcValueVectors(const ScalingBasis &basis) {
7474

7575
void ABGVCalculator::calcKMatrix(const ScalingBasis &basis) {
7676
int kp1 = basis.getQuadratureOrder();
77-
double sqrtCoef[kp1];
77+
std::vector<double> sqrtCoef(kp1);
7878
for (int i = 0; i < kp1; i++) { sqrtCoef[i] = std::sqrt(2.0 * i + 1.0); }
7979
getQuadratureCache(qCache);
8080
const VectorXd &roots = qCache.getRoots(kp1);
@@ -105,7 +105,6 @@ void ABGVCalculator::calcNode(MWNode<2> &node) {
105105
node.zeroCoefs();
106106

107107
const auto &idx = node.getNodeIndex();
108-
int l = idx[1] - idx[0];
109108
int np1 = idx.getScale() + 1;
110109
int kp1 = node.getKp1();
111110
int kp1_d = node.getKp1_d();

src/treebuilders/ConvolutionCalculator.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ template <int D, typename T> MWNodeVector<D, T> *ConvolutionCalculator<D, T>::ma
143143
auto *band = new MWNodeVector<D, T>;
144144

145145
int o_depth = gNode.getScale() - this->oper->getOperatorRoot();
146-
int g_depth = gNode.getDepth();
147146
int width = this->oper->getMaxBandWidth(o_depth);
148147

149148
bool periodic = gNode.getMWTree().isPeriodic();
@@ -228,8 +227,8 @@ template <int D, typename T> void ConvolutionCalculator<D, T>::calcNode(MWNode<D
228227

229228
int o_depth = gNode.getScale() - this->oper->getOperatorRoot();
230229
if (manipulateOperator and this->oper->getOperatorRoot() < 0) o_depth = gNode.getDepth();
231-
T tmpCoefs[gNode.getNCoefs()];
232-
OperatorState<D, T> os(gNode, tmpCoefs);
230+
std::vector<T> tmpCoefs(gNode.getNCoefs());
231+
OperatorState<D, T> os(gNode, tmpCoefs.data());
233232
this->operStat.incrementGNodeCounters(gNode);
234233

235234
// Get all nodes in f within the bandwith of O in g

src/treebuilders/DerivativeCalculator.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ template <int D, typename T> void DerivativeCalculator<D, T>::calcNode(MWNode<D,
9090
// if (this->oper->getMaxBandWidth() > 1) MSG_ABORT("Only implemented for zero bw");
9191
outNode.zeroCoefs();
9292
int nComp = (1 << D);
93-
T tmpCoefs[outNode.getNCoefs()];
94-
OperatorState<D, T> os(outNode, tmpCoefs);
93+
std::vector<T> tmpCoefs(outNode.getNCoefs());
94+
OperatorState<D, T> os(outNode, tmpCoefs.data());
9595

9696
os.setFNode(inpNode);
9797
os.setFIndex(inpNode.nodeIndex);
@@ -116,8 +116,8 @@ template <int D, typename T> void DerivativeCalculator<D, T>::calcNode(MWNode<D,
116116
gNode.zeroCoefs();
117117

118118
int nComp = (1 << D);
119-
T tmpCoefs[gNode.getNCoefs()];
120-
OperatorState<D, T> os(gNode, tmpCoefs);
119+
std::vector<T> tmpCoefs(gNode.getNCoefs());
120+
OperatorState<D, T> os(gNode, tmpCoefs.data());
121121
this->operStat.incrementGNodeCounters(gNode);
122122

123123
// Get all nodes in f within the bandwith of O in g
@@ -182,11 +182,8 @@ template <int D, typename T> void DerivativeCalculator<D, T>::applyOperator_bw0(
182182
// cout<<" applyOperator "<<endl;
183183
MWNode<D, T> &gNode = *os.gNode;
184184
MWNode<D, T> &fNode = *os.fNode;
185-
const NodeIndex<D> &fIdx = *os.fIdx;
186-
const NodeIndex<D> &gIdx = gNode.getNodeIndex();
187185
int depth = gNode.getDepth();
188186

189-
double oNorm = 1.0;
190187
double **oData = os.getOperData();
191188

192189
for (int d = 0; d < D; d++) {
@@ -218,7 +215,6 @@ template <int D, typename T> void DerivativeCalculator<D, T>::applyOperator(Oper
218215
const NodeIndex<D> &gIdx = gNode.getNodeIndex();
219216
int depth = gNode.getDepth();
220217

221-
double oNorm = 1.0;
222218
double **oData = os.getOperData();
223219

224220
for (int d = 0; d < D; d++) {
@@ -236,8 +232,6 @@ template <int D, typename T> void DerivativeCalculator<D, T>::applyOperator(Oper
236232

237233
const OperatorNode &oNode = oTree.getNode(depth, oTransl);
238234
int oIdx = os.getOperIndex(d);
239-
double ocn = oNode.getComponentNorm(oIdx);
240-
oNorm *= ocn;
241235
if (this->applyDir == d) {
242236
oData[d] = const_cast<double *>(oNode.getCoefs()) + oIdx * os.kp1_2;
243237
} else {

src/treebuilders/grid.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ template <int D> void build_grid(FunctionTree<D> &out, const GaussExp<D> &inp, i
113113
builder.build(out, calculator, adaptor, maxIter);
114114
}
115115
} else {
116-
auto period = out.getMRA().getWorldBox().getScalingFactors();
117116
for (auto i = 0; i < inp.size(); i++) {
118117
auto *gauss = inp.getFunc(i).copy();
119118
build_grid(out, *gauss, maxIter);

src/treebuilders/multiply.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,8 @@ template <int D, typename T> double node_norm_dot(FunctionTree<D, T> &bra, Funct
334334

335335
double result = 0.0;
336336
int ncoef = bra.getKp1_d() * bra.getTDim();
337-
T valA[ncoef];
338-
T valB[ncoef];
337+
std::vector<T> valA(ncoef);
338+
std::vector<T> valB(ncoef);
339339
int nNodes = bra.getNEndNodes();
340340

341341
for (int n = 0; n < nNodes; n++) {
@@ -345,8 +345,8 @@ template <int D, typename T> double node_norm_dot(FunctionTree<D, T> &bra, Funct
345345
// convert to interpolating coef, take abs, convert back
346346
FunctionNode<D, T> *mwNode = static_cast<FunctionNode<D, T> *>(ket.findNode(idx));
347347
if (mwNode == nullptr) MSG_ABORT("Trees must have same grid");
348-
node.getAbsCoefs(valA);
349-
mwNode->getAbsCoefs(valB);
348+
node.getAbsCoefs(valA.data());
349+
mwNode->getAbsCoefs(valB.data());
350350
for (int i = 0; i < ncoef; i++) result += std::norm(valA[i] * valB[i]);
351351
} else {
352352
// approximate by product of node norms

src/trees/FunctionNode.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ template <int D, typename T> T FunctionNode<D, T>::integrateInterpolating() cons
130130
int qOrder = this->getKp1();
131131
getQuadratureCache(qc);
132132
const VectorXd &weights = qc.getWeights(qOrder);
133-
double sqWeights[qOrder];
133+
std::vector<double> sqWeights(qOrder);
134134
for (int i = 0; i < qOrder; i++) sqWeights[i] = std::sqrt(weights[i]);
135135

136136
int kp1_p[D];
@@ -170,7 +170,7 @@ template <int D, typename T> T FunctionNode<D, T>::integrateValues() const {
170170
this->getCoefs(coefs);
171171
int ncoefs = coefs.size();
172172
int ncoefChild = ncoefs / (1 << D);
173-
T cc[ncoefChild];
173+
std::vector<T> cc(ncoefChild);
174174
// factorize out the children
175175
for (int i = 0; i < ncoefChild; i++) cc[i] = coefs[i];
176176
for (int j = 1; j < (1 << D); j++)

src/trees/FunctionTree.cpp

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,6 @@ template <int D, typename T> void FunctionTree<D, T>::loadTreeTXT(const std::str
290290
* @param[in] file: File name
291291
*/
292292
template <int D, typename T> void FunctionTree<D, T>::saveTreeTXT(const std::string &fname) {
293-
int nRoots = this->getRootBox().size();
294-
MWNode<D, T> **roots = this->getRootBox().getNodes();
295-
296293
std::ofstream out(fname);
297294
out << std::setprecision(14);
298295
out << D << std::endl;
@@ -306,7 +303,7 @@ template <int D, typename T> void FunctionTree<D, T>::saveTreeTXT(const std::str
306303
int ncoefs = 1;
307304
for (int d = 0; d < D; d++) ncoefs *= kp1;
308305
int Tdim = std::pow(2, D);
309-
T values[ncoefs * Tdim];
306+
std::vector<T> values(ncoefs * Tdim);
310307

311308
int nout = this->endNodeTable.size();
312309
out << Tdim * nout << std::endl; // could output only scaling coeff?
@@ -334,7 +331,7 @@ template <int D, typename T> void FunctionTree<D, T>::saveTreeTXT(const std::str
334331
MWNode<D, T> *node = &(this->getNode(idx, false));
335332
T *coefs = node->getCoefs();
336333
for (int i = 0; i < ncoefs * Tdim; i++) values[i] = coefs[i];
337-
node->attachCoefs(values);
334+
node->attachCoefs(values.data());
338335
int n = idx.getScale();
339336
node->mwTransform(Reconstruction);
340337
node->cvTransform(Forward);
@@ -443,7 +440,6 @@ template <> double FunctionTree<3, double>::integrateEndNodes(RepresentableFunct
443440
// traverse tree, and treat end nodes only
444441
std::vector<FunctionNode<3> *> stack; // node from this
445442
for (int i = 0; i < this->getRootBox().size(); i++) stack.push_back(&(this->getRootFuncNode(i)));
446-
int basis = getMRA().getScalingBasis().getScalingType();
447443
double result = 0.0;
448444
while (stack.size() > 0) {
449445
FunctionNode<3> *Node = stack.back();
@@ -456,9 +452,9 @@ template <> double FunctionTree<3, double>::integrateEndNodes(RepresentableFunct
456452
double *coefs = Node->getCoefs(); // save position of coeff, but do not use them!
457453
// The data in fmat is not organized so that two consecutive points are stored after each other in memory, so needs to copy before mwtransform, cannot use memory adress directly.
458454
int nc = fmat.cols();
459-
double cc[nc];
455+
std::vector<double> cc(nc);
460456
for (int i = 0; i < nc; i++) cc[i] = fmat(0, i);
461-
Node->attachCoefs(cc);
457+
Node->attachCoefs(cc.data());
462458
result += Node->integrateValues();
463459
Node->attachCoefs(coefs); // put back original coeff
464460
}
@@ -880,8 +876,6 @@ void FunctionTree<D, T>::makeCoeffVector(std::vector<T *> &coefs,
880876
indices.clear();
881877
parent_indices.clear();
882878
max_index = 0;
883-
int sizecoeff = (1 << refTree.getDim()) * refTree.getKp1_d();
884-
int sizecoeffW = ((1 << refTree.getDim()) - 1) * refTree.getKp1_d();
885879
std::vector<MWNode<D, double> *> refstack; // nodes from refTree
886880
std::vector<MWNode<D, T> *> thisstack; // nodes from this Tree
887881
for (int rIdx = 0; rIdx < this->getRootBox().size(); rIdx++) {
@@ -1096,7 +1090,6 @@ template <> int FunctionTree<3, double>::saveNodesAndRmCoeff() {
10961090
for (int rIdx = 0; rIdx < this->getRootBox().size(); rIdx++) { stack.push_back(this->getRootBox().getNodes()[rIdx]); }
10971091
while (stack.size() > stack_p) {
10981092
MWNode<3, double> *Node = stack[stack_p++];
1099-
int id = 0;
11001093
NodesCoeff->put_data(Node->getNodeIndex(), sizecoeff, Node->getCoefs());
11011094
for (int i = 0; i < Node->getNChildren(); i++) { stack.push_back(Node->children[i]); }
11021095
}
@@ -1119,7 +1112,6 @@ template <> int FunctionTree<3, ComplexDouble>::saveNodesAndRmCoeff() {
11191112
for (int rIdx = 0; rIdx < this->getRootBox().size(); rIdx++) { stack.push_back(this->getRootBox().getNodes()[rIdx]); }
11201113
while (stack.size() > stack_p) {
11211114
MWNode<3, ComplexDouble> *Node = stack[stack_p++];
1122-
int id = 0;
11231115
NodesCoeff->put_data(Node->getNodeIndex(), sizecoeff, Node->getCoefs());
11241116
for (int i = 0; i < Node->getNChildren(); i++) { stack.push_back(Node->children[i]); }
11251117
}
@@ -1195,7 +1187,6 @@ template <int D, typename T> FunctionTree<D, double> *FunctionTree<D, T>::Imag()
11951187

11961188
template <> void FunctionTree<3, double>::CopyTreeToComplex(FunctionTree<3, ComplexDouble> *&outTree) {
11971189
delete outTree;
1198-
double ref = 0.0;
11991190
outTree = new FunctionTree<3, ComplexDouble>(this->getMRA());
12001191
std::vector<MWNode<3, double> *> instack; // node from this
12011192
std::vector<MWNode<3, ComplexDouble> *> outstack; // node from outTree
@@ -1204,7 +1195,6 @@ template <> void FunctionTree<3, double>::CopyTreeToComplex(FunctionTree<3, Comp
12041195
instack.push_back(this->getRootBox().getNodes()[rIdx]);
12051196
outstack.push_back(outTree->getRootBox().getNodes()[rIdx]);
12061197
}
1207-
int nNodes = std::min(this->getNNodes(), this->getNodeAllocator().getMaxNodesPerChunk());
12081198
int ncoefs = this->getNodeAllocator().getNCoefs();
12091199
while (instack.size() > 0) {
12101200
// inNode and outNode are the same node in space, but on different trees
@@ -1235,7 +1225,6 @@ template <> void FunctionTree<3, double>::CopyTreeToComplex(FunctionTree<3, Comp
12351225

12361226
template <> void FunctionTree<2, double>::CopyTreeToComplex(FunctionTree<2, ComplexDouble> *&outTree) {
12371227
delete outTree;
1238-
double ref = 0.0;
12391228
outTree = new FunctionTree<2, ComplexDouble>(this->getMRA());
12401229
std::vector<MWNode<2, double> *> instack; // node from this
12411230
std::vector<MWNode<2, ComplexDouble> *> outstack; // node from outTree
@@ -1244,7 +1233,6 @@ template <> void FunctionTree<2, double>::CopyTreeToComplex(FunctionTree<2, Comp
12441233
instack.push_back(this->getRootBox().getNodes()[rIdx]);
12451234
outstack.push_back(outTree->getRootBox().getNodes()[rIdx]);
12461235
}
1247-
int nNodes = std::min(this->getNNodes(), this->getNodeAllocator().getMaxNodesPerChunk());
12481236
int ncoefs = this->getNodeAllocator().getNCoefs();
12491237
while (instack.size() > 0) {
12501238
// inNode and outNode are the same node in space, but on different trees
@@ -1275,7 +1263,6 @@ template <> void FunctionTree<2, double>::CopyTreeToComplex(FunctionTree<2, Comp
12751263

12761264
template <> void FunctionTree<1, double>::CopyTreeToComplex(FunctionTree<1, ComplexDouble> *&outTree) {
12771265
delete outTree;
1278-
double ref = 0.0;
12791266
outTree = new FunctionTree<1, ComplexDouble>(this->getMRA());
12801267
std::vector<MWNode<1, double> *> instack; // node from this
12811268
std::vector<MWNode<1, ComplexDouble> *> outstack; // node from outTree
@@ -1284,7 +1271,6 @@ template <> void FunctionTree<1, double>::CopyTreeToComplex(FunctionTree<1, Comp
12841271
instack.push_back(this->getRootBox().getNodes()[rIdx]);
12851272
outstack.push_back(outTree->getRootBox().getNodes()[rIdx]);
12861273
}
1287-
int nNodes = std::min(this->getNNodes(), this->getNodeAllocator().getMaxNodesPerChunk());
12881274
int ncoefs = this->getNodeAllocator().getNCoefs();
12891275
while (instack.size() > 0) {
12901276
// inNode and outNode are the same node in space, but on different trees
@@ -1316,7 +1302,6 @@ template <> void FunctionTree<1, double>::CopyTreeToComplex(FunctionTree<1, Comp
13161302
// for testing
13171303
template <> void FunctionTree<3, double>::CopyTreeToReal(FunctionTree<3, double> *&outTree) {
13181304
delete outTree;
1319-
double ref = 0.0;
13201305
// FunctionTree<3, double>* inTree = this;
13211306
outTree = new FunctionTree<3, double>(this->getMRA());
13221307
std::vector<MWNode<3, double> *> instack; // node from this
@@ -1326,7 +1311,6 @@ template <> void FunctionTree<3, double>::CopyTreeToReal(FunctionTree<3, double>
13261311
instack.push_back(this->getRootBox().getNodes()[rIdx]);
13271312
outstack.push_back(outTree->getRootBox().getNodes()[rIdx]);
13281313
}
1329-
int nNodes = std::min(this->getNNodes(), this->getNodeAllocator().getMaxNodesPerChunk());
13301314
int ncoefs = this->getNodeAllocator().getNCoefs();
13311315
while (instack.size() > 0) {
13321316
// inNode and outNode are the same node in space, but on different trees

0 commit comments

Comments
 (0)