diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..83445c6 --- /dev/null +++ b/.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 \ No newline at end of file diff --git a/.clangd.bak b/.clangd.bak new file mode 100644 index 0000000..b76514c --- /dev/null +++ b/.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, #同上 + ] diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 202c2b8..85f8bcb 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -1,13 +1,13 @@ { - "configurations": [ - { - "name": "Linux", - "includePath": [ - "${workspaceFolder}/**" - ], - "defines": [], - "compileCommands": "${workspaceFolder}/build/compile_commands.json" - } - ], - "version": 4 + "configurations": [ + { + "name": "Linux", + "includePath": [ + "${workspaceFolder}/**" + ], + "defines": [], + "compileCommands": "${workspaceFolder}/build/compile_commands.json" + } + ], + "version": 4 } \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 1031d59..06e2d75 100644 --- a/.vscode/settings.json +++ b/.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-tidy在系统PATH中 +// "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 } \ No newline at end of file diff --git a/algoim/organizer/primitive.hpp b/algoim/organizer/primitive.hpp index a92bc17..8c36c3f 100644 --- a/algoim/organizer/primitive.hpp +++ b/algoim/organizer/primitive.hpp @@ -148,24 +148,11 @@ public: // PowerTensor() {} - PowerTensor(uvector ext_) - { - tensor.ext_ = ext_; - tensor.data_ = nullptr; - algoim_spark_alloc(real, tensor); - // sparkStackPtr = algoim_spark_alloc_heap(real, tensor); - xarrayInit(tensor); - } + PowerTensor(const xarray& t_) : tensor(t_) {} - // PowerTensor(xarray t_) : tensor(t_) {} + // const xarray& 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& pts_) + PowerTensorComplex(const std::vector& pts_, xarray& 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& pcs_) diff --git a/gjj/myDebug.hpp b/gjj/myDebug.hpp index 649e16d..d9a3203 100644 --- a/gjj/myDebug.hpp +++ b/gjj/myDebug.hpp @@ -205,8 +205,9 @@ void testMultiPolys() } template -void power2BernsteinTensorProduct(const xarray& phiPower, xarray& phiBernsetin) +void power2BernsteinTensorProduct(const xarray& phiPower, xarray& 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& phiPower, xarray 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& x) { return 1.0; }; + auto integrand = [](const uvector&) { return 1.0; }; power2BernsteinTensorProduct(phiPower, phiBernstein); v = xarray2StdVector(phiPower); @@ -393,7 +393,6 @@ void testSpherePowerDirectlyByTransformation() xarray 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 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 testX(0., 0.75, 0); + uvector 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& 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 ext(3, 3, 3); + xarray power(nullptr, ext), bernstein(nullptr, ext); + algoim_spark_alloc(real, power, bernstein); + xarrayInit(power); + power.m(uvector(1, 2, 0)) = 3; + power.m(uvector(0, 1, 2)) = 4; + power.m(uvector(1, 2, 2)) = 5; + power.m(uvector(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(); } diff --git a/main.cpp b/main.cpp index b96ee32..6bb3fb2 100644 --- a/main.cpp +++ b/main.cpp @@ -2,7 +2,9 @@ using namespace std; -int main() { - cout << "Hello, World!" << endl; - return 0; +int main() +{ + int a; + cout << "Hello, World!" << endl; + return 0; } \ No newline at end of file