Browse Source

config clang-tidy

master
gjj 7 months ago
parent
commit
7f503be2c0
  1. 23
      .clang-tidy
  2. 24
      .clangd.bak
  3. 22
      .vscode/settings.json
  4. 26
      algoim/organizer/primitive.hpp
  5. 47
      gjj/myDebug.hpp
  6. 4
      main.cpp

23
.clang-tidy

@ -0,0 +1,23 @@
Checks: "
-*,
bugprone-*,
performance-*,
readability-*,
misc-*,
clang-analyzer-*,
cppcoreguidelines-*,
modernize-*,
performance-unnecessary-value-param,
modernize-pass-by-value,
-readability-identifier-length,
-modernize-use-trailing-return-type,
-cppcoreguidelines-magic-numbers,
-cppcoreguidelines-init-variables,
"
WarningsAsErrors: ''
HeaderFilterRegex: '.*'
AnalyzeTemporaryDtors: false
FormatStyle: file

24
.clangd.bak

@ -0,0 +1,24 @@
Index:
Background: Build
CompileFlags:
Add: [-xc++, -Wall, -std=c++20]
Compiler: clang++
Diagnostics:
ClangTidy:
Add: ["*"]
Remove: [
abseil*,
fuchsia*,
llvmlib*,
zircon*,
altera*,
google-readability-todo,
readability-braces-around-statements,
hicpp-braces-around-statements,
modernize-use-trailing-return-type, # 不要每个都加上尾返回值类型
readability-identifier-length, # 不检查变量名长度
; cppcoreguidelines-avoid-magic-numbers, # 不检查魔法数字
; readability-magic-numbers, #同上
]

22
.vscode/settings.json

@ -8,10 +8,28 @@
"C_Cpp.default.compilerPath": "/usr/bin/clang++",
"[cpp]": {
"editor.defaultFormatter": "llvm-vs-code-extensions.vscode-clangd",
"editor.formatOnSave": true
"editor.formatOnSave": true,
},
// "C_Cpp.clangTidy.enabled": true,
// "C_Cpp.clangTidy.path": "clang-tidy", // clang-tidyPATH
// "C_Cpp.clangTidy.args": [
// "--checks=*,-clang-analyzer-*,-cppcoreguidelines-pro-bounds-array-to-pointer-decay", //
// "--warnings-as-errors=*",
// "--header-filter=.*"
// ],
// "C_Cpp.clangTidy.fixOnSave": false, //
// "C_Cpp.cpplint.enabled": false, // cpplint使cppcheck
// "C_Cpp.cppcheck.enabled": true,
// "C_Cpp.cppcheck.args": [
// "--enable=all", //
// "--inconclusive", //
// "--std=c++17", // C++
// "--force" // 使
// ],
"[c]": {
"editor.defaultFormatter": "llvm-vs-code-extensions.vscode-clangd",
"editor.formatOnSave": true
}
},
"C_Cpp.codeAnalysis.clangTidy.enabled": true
}

26
algoim/organizer/primitive.hpp

@ -148,24 +148,11 @@ public:
// PowerTensor() {}
PowerTensor(uvector<int, 3> ext_)
{
tensor.ext_ = ext_;
tensor.data_ = nullptr;
algoim_spark_alloc(real, tensor);
// sparkStackPtr = algoim_spark_alloc_heap(real, tensor);
xarrayInit(tensor);
}
PowerTensor(const xarray<real, 3>& t_) : tensor(t_) {}
// PowerTensor(xarray<real, 3> t_) : tensor(t_) {}
// const xarray<real, 3>& getTensor() { return tensor; }
~PowerTensor()
{
// if (sparkStackPtr) {
// algoim_spark_release_heap(sparkStackPtr);
// sparkStackPtr = nullptr;
// }
}
~PowerTensor() = default;
};
class PowerTensorComplex : public Primitive
@ -189,13 +176,12 @@ public:
// // detail::compositePower(tensors, 0, uvector3(0, 0, 0), 1, compositeTensor);
// }
PowerTensorComplex(const std::vector<PowerTensor>& pts_)
PowerTensorComplex(const std::vector<PowerTensor>& pts_, xarray<real, 3>& ptc_) : tensors(pts_), compositeTensor(ptc_)
{
uvector3 ext(1);
for (auto& pt : pts_) { ext += pt.tensor.ext() - 1; }
compositeTensor.ext_ = ext;
sparkStackPtr = algoim_spark_alloc_heap(real, compositeTensor);
// detail::compositePower(tensors, 0, uvector3(0, 0, 0), 1, compositeTensor);
assert(all(ext == compositeTensor.ext()));
detail::compositePower(tensors, 0, uvector3(0, 0, 0), 1, compositeTensor);
}
PowerTensorComplex(const std::vector<PowerTensorComplex>& pcs_)

47
gjj/myDebug.hpp

@ -205,8 +205,9 @@ void testMultiPolys()
}
template <int N>
void power2BernsteinTensorProduct(const xarray<real, N>& phiPower, xarray<real, N>& phiBernsetin)
void power2BernsteinTensorProduct(const xarray<real, N>& phiPower, xarray<real, N>& phiBernstein)
{
xarrayInit(phiBernstein);
for (auto i = phiPower.loop(); ~i; ++i) {
// phi.l(i) = powerFactors.l(i);
real factorBase = phiPower.l(i);
@ -228,7 +229,7 @@ void power2BernsteinTensorProduct(const xarray<real, N>& phiPower, xarray<real,
for (auto ii = subgrid.loop(); ~ii; ++ii) {
real factor = factorBase;
for (int dim = 0; dim < N; ++dim) { factor *= decompFactors[dim][ii(dim)]; }
phiBernsetin.m(i() + ii()) += factor;
phiBernstein.m(i() + ii()) += factor;
}
}
}
@ -324,7 +325,6 @@ void testSpherePowerDirectly()
xarray<real, 3> phiPower(nullptr, ext), phiBernstein(nullptr, ext);
algoim_spark_alloc(real, phiPower, phiBernstein);
xarrayInit(phiPower);
xarrayInit(phiBernstein);
auto v = xarray2StdVector(phiPower);
auto vv = xarray2StdVector(phiBernstein);
for (int dim = 0; dim < 3; ++dim) {
@ -336,7 +336,7 @@ void testSpherePowerDirectly()
phiPower.m(idx) = a[dim] * k(dim) * k(dim);
}
phiPower.m(0) -= r * r;
auto integrand = [](const uvector<real, 3>& x) { return 1.0; };
auto integrand = [](const uvector<real, 3>&) { return 1.0; };
power2BernsteinTensorProduct(phiPower, phiBernstein);
v = xarray2StdVector(phiPower);
@ -393,7 +393,6 @@ void testSpherePowerDirectlyByTransformation()
xarray<real, 3> phiPower(nullptr, ext), phiBernstein(nullptr, ext);
algoim_spark_alloc(real, phiPower, phiBernstein);
xarrayInit(phiPower);
xarrayInit(phiBernstein);
auto v = xarray2StdVector(phiPower);
auto vv = xarray2StdVector(phiBernstein);
for (int dim = 0; dim < 3; ++dim) {
@ -435,7 +434,6 @@ void testCylinderPowerDirectly()
xarray<real, 3> phiPower(nullptr, ext), phiBernstein(nullptr, ext);
algoim_spark_alloc(real, phiPower, phiBernstein);
xarrayInit(phiPower);
xarrayInit(phiBernstein);
auto v = xarray2StdVector(phiPower);
auto vv = xarray2StdVector(phiBernstein);
real top = c[2] + h * 0.5, bottom = c[2] - h * 0.5;
@ -869,7 +867,7 @@ void test3PlanesPowerDirectly()
-1,
1,
integrand,
30,
10,
{
{1, 1, 0, 0 },
{1, -1, 0, 0 },
@ -1011,7 +1009,8 @@ void test4PlanesAlgoim()
real x = xx(0);
real y = xx(1);
real z = xx(2);
return x + y - z;
// return x + y - z;
return y - 1;
};
@ -1065,13 +1064,16 @@ void test4PlanesPowerDirectly()
compositePower(phiPowers, 0, 0, 1, phiPowerAll);
auto v = xarray2StdVector(phiPowerAll);
uvector<real, 3> testX(0., 0.75, 0);
uvector<real, 3> testX(0., 0.75, 0.2);
real testEval = powerEvaluation(phiPowerAll, testX);
std::cout << "eval power before trans:" << testEval << std::endl;
powerTransformation(range, xmin, phiPowerAll);
real testEvalAfterTrans = powerEvaluation(phiPowerAll, testX);
std::cout << "eval power after trans:" << testEvalAfterTrans << std::endl;
auto vAfterTrans = xarray2StdVector(phiPowerAll);
auto integrand = [](const uvector<real, 3>& x) { return 1.0; };
power2BernsteinTensorProduct(phiPowerAll, phiBernstein);
@ -1086,6 +1088,7 @@ void test4PlanesPowerDirectly()
real testEval2 = powerEvaluation(phiPowers[2], testX);
std::cout << "eval power2:" << testEval2 << std::endl;
real testEvalBernstein = bernstein::evalBernsteinPoly(phiBernstein, testX);
auto vec = xarray2StdVector(phiBernstein);
std::cout << "eval bernstein:" << testEvalBernstein << std::endl;
@ -1094,7 +1097,7 @@ void test4PlanesPowerDirectly()
-1,
1,
integrand,
20,
10,
{
{1, 1, 0, 0 },
{1, -1, 0, 0 },
@ -1149,6 +1152,24 @@ void testBooluarray()
std::cout << tmp.bits << std::endl;
}
void testPower2Bernstein()
{
uvector<real, 3> ext(3, 3, 3);
xarray<real, 3> power(nullptr, ext), bernstein(nullptr, ext);
algoim_spark_alloc(real, power, bernstein);
xarrayInit(power);
power.m(uvector<int, 3>(1, 2, 0)) = 3;
power.m(uvector<int, 3>(0, 1, 2)) = 4;
power.m(uvector<int, 3>(1, 2, 2)) = 5;
power.m(uvector<int, 3>(0, 0, 0)) = 3;
uvector3 X(0.8, 0.7, 0.6);
auto evalPower = powerEvaluation(power, X);
power2BernsteinTensorProduct(power, bernstein);
auto evalBernstein = bernstein::evalBernsteinPoly(bernstein, X);
std::cout << "eval power: " << evalPower << std::endl;
std::cout << "eval bernstein: " << evalBernstein << std::endl;
}
void testMain()
{
// testBooluarray();
@ -1162,11 +1183,11 @@ void testMain()
// test8PlanesAlgoim();
// test8PlanesPowerDirectly();
// test3PlanesAlgoim();
// test3PlanesPowerDirectly();
test4PlanesPowerDirectly();
// test4PlanesPowerDirectly();
// test4PlanesAlgoim();
// testQuarterSphere();
// testPower2Bernstein();
}

4
main.cpp

@ -2,7 +2,9 @@
using namespace std;
int main() {
int main()
{
int a;
cout << "Hello, World!" << endl;
return 0;
}
Loading…
Cancel
Save