From 63cda215717fdf4b207d6f71978078074ca119a9 Mon Sep 17 00:00:00 2001 From: guanjihuan Date: Sat, 11 Oct 2025 14:05:37 +0800 Subject: [PATCH] update --- .../guan_cpp_project/pyproject.toml | 0 .../guan_cpp_project/setup.py | 0 .../guan_cpp_project/src/cpp/main.cpp | 0 .../guan_cpp_project/src/guan_cpp/__init__.py | 0 .../a.cpp | 35 +++++++++++++++++++ .../a.py | 22 ++++++++++++ 6 files changed, 57 insertions(+) rename {2026.10.10_cpp_python_uploaded_to_pypi => 2025.10.10_cpp_python_uploaded_to_pypi}/guan_cpp_project/pyproject.toml (100%) rename {2026.10.10_cpp_python_uploaded_to_pypi => 2025.10.10_cpp_python_uploaded_to_pypi}/guan_cpp_project/setup.py (100%) rename {2026.10.10_cpp_python_uploaded_to_pypi => 2025.10.10_cpp_python_uploaded_to_pypi}/guan_cpp_project/src/cpp/main.cpp (100%) rename {2026.10.10_cpp_python_uploaded_to_pypi => 2025.10.10_cpp_python_uploaded_to_pypi}/guan_cpp_project/src/guan_cpp/__init__.py (100%) create mode 100644 2025.10.11_time_test_of_openblas_eigen_numpy/a.cpp create mode 100644 2025.10.11_time_test_of_openblas_eigen_numpy/a.py diff --git a/2026.10.10_cpp_python_uploaded_to_pypi/guan_cpp_project/pyproject.toml b/2025.10.10_cpp_python_uploaded_to_pypi/guan_cpp_project/pyproject.toml similarity index 100% rename from 2026.10.10_cpp_python_uploaded_to_pypi/guan_cpp_project/pyproject.toml rename to 2025.10.10_cpp_python_uploaded_to_pypi/guan_cpp_project/pyproject.toml diff --git a/2026.10.10_cpp_python_uploaded_to_pypi/guan_cpp_project/setup.py b/2025.10.10_cpp_python_uploaded_to_pypi/guan_cpp_project/setup.py similarity index 100% rename from 2026.10.10_cpp_python_uploaded_to_pypi/guan_cpp_project/setup.py rename to 2025.10.10_cpp_python_uploaded_to_pypi/guan_cpp_project/setup.py diff --git a/2026.10.10_cpp_python_uploaded_to_pypi/guan_cpp_project/src/cpp/main.cpp b/2025.10.10_cpp_python_uploaded_to_pypi/guan_cpp_project/src/cpp/main.cpp similarity index 100% rename from 2026.10.10_cpp_python_uploaded_to_pypi/guan_cpp_project/src/cpp/main.cpp rename to 2025.10.10_cpp_python_uploaded_to_pypi/guan_cpp_project/src/cpp/main.cpp diff --git a/2026.10.10_cpp_python_uploaded_to_pypi/guan_cpp_project/src/guan_cpp/__init__.py b/2025.10.10_cpp_python_uploaded_to_pypi/guan_cpp_project/src/guan_cpp/__init__.py similarity index 100% rename from 2026.10.10_cpp_python_uploaded_to_pypi/guan_cpp_project/src/guan_cpp/__init__.py rename to 2025.10.10_cpp_python_uploaded_to_pypi/guan_cpp_project/src/guan_cpp/__init__.py diff --git a/2025.10.11_time_test_of_openblas_eigen_numpy/a.cpp b/2025.10.11_time_test_of_openblas_eigen_numpy/a.cpp new file mode 100644 index 0000000..fdbc0c0 --- /dev/null +++ b/2025.10.11_time_test_of_openblas_eigen_numpy/a.cpp @@ -0,0 +1,35 @@ +#define EIGEN_USE_BLAS // 注释或取消注释来测试 +#include +#include +#include +#include +#include + +int main() { + std::vector sizes = {100, 200, 300, 500, 1000, 2000, 3000, 5000}; // 要测试的不同矩阵大小 + const int trials = 3; // 每个尺寸的测试次数 + + for (int size : sizes) { + std::cout << "Testing size: " << size << "x" << size << std::endl; + + Eigen::MatrixXd A = Eigen::MatrixXd::Random(size, size); + A = A.transpose() * A + Eigen::MatrixXd::Identity(size, size); // 确保矩阵可逆 + + auto start = std::chrono::high_resolution_clock::now(); + + for (int i = 0; i < trials; ++i) { + Eigen::MatrixXd A_inv = A.inverse(); + } + + auto end = std::chrono::high_resolution_clock::now(); + auto duration = std::chrono::duration_cast(end - start); + + std::cout << "Average time per inversion: " + << std::fixed << std::setprecision(3) + << (static_cast(duration.count()) / 1000 / trials) + << " s" << std::endl; + std::cout << "----------------------------------" << std::endl; + } + + return 0; +} \ No newline at end of file diff --git a/2025.10.11_time_test_of_openblas_eigen_numpy/a.py b/2025.10.11_time_test_of_openblas_eigen_numpy/a.py new file mode 100644 index 0000000..1ca09a9 --- /dev/null +++ b/2025.10.11_time_test_of_openblas_eigen_numpy/a.py @@ -0,0 +1,22 @@ +import numpy as np +import time + +sizes = [100, 200, 300, 500, 1000, 2000, 3000, 5000] +trials = 3 + +for size in sizes: + print(f"Testing size: {size}x{size}") + + A = np.random.rand(size, size) + A = A.T @ A + np.eye(size) + + start = time.time() + + for _ in range(trials): + A_inv = np.linalg.inv(A) + + end = time.time() + duration = end - start + + print(f"Average time per inversion: {duration/trials:.3f} s") + print("----------------------------------") \ No newline at end of file