Skip to content
This repository has been archived by the owner on Jun 21, 2024. It is now read-only.

Commit

Permalink
fix: clean macro ITERATION_METHOD_TIMING
Browse files Browse the repository at this point in the history
  • Loading branch information
tiankaima committed Dec 18, 2023
1 parent ee5cebe commit fc3b0ef
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 42 deletions.
1 change: 1 addition & 0 deletions CustomMath_lib/CustomMath_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "HouseholderMethod/HouseholderMethod.h"
#include "InfinityNorm/InfinityNorm.h"
#include "IterationMethod/IterationMethod.h"
#include "JacobiMethod/JacobiMethod.h"
#include "PowerIteration/PowerIteration.h"
#include "QRMethod/QRMethod.h"

Expand Down
13 changes: 1 addition & 12 deletions CustomMath_lib/IterationMethod/IterationMethod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,7 @@

#include "IterationMethod.h"

#define ENABLE_ITERATION_METHOD_TIMING

#ifdef ENABLE_ITERATION_METHOD_TIMING
#define ITERATION_METHOD_TIMING_START auto start = std::chrono::high_resolution_clock::now();
#define ITERATION_METHOD_TIMING_END auto end = std::chrono::high_resolution_clock::now(); \
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(end - start);
#define ITERATION_METHOD_RETURN_DURATION duration
#else
#define ITERATION_METHOD_TIMING_START
#define ITERATION_METHOD_TIMING_END
#define ITERATION_METHOD_RETURN_DURATION std::chrono::microseconds(0)
#endif


VIterationMethodOutput JacobiIteration(const IterationMethodInput &input) {
auto A = input.A;
Expand Down
10 changes: 10 additions & 0 deletions CustomMath_lib/JacobiMethod/JacobiMethod.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,14 @@
#ifndef NUMERICAL_ALGEBRA_JACOBIMETHOD_H
#define NUMERICAL_ALGEBRA_JACOBIMETHOD_H

#include "CustomMath_lib.h"

typedef struct {
Matrix H;
Matrix P;
} JacobiMethodOutput;




#endif //NUMERICAL_ALGEBRA_JACOBIMETHOD_H
15 changes: 0 additions & 15 deletions CustomMath_lib/PowerIteration/PowerIteration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,6 @@

#include "PowerIteration.h"

#define ITERATION_METHOD_MAX_ITERATION 100000

#define ENABLE_POWER_ITERATION_METHOD_TIMING

#ifdef ENABLE_POWER_ITERATION_METHOD_TIMING
#define ITERATION_METHOD_TIMING_START auto start = std::chrono::high_resolution_clock::now();
#define ITERATION_METHOD_TIMING_END auto end = std::chrono::high_resolution_clock::now(); \
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(end - start);
#define ITERATION_METHOD_RETURN_DURATION duration
#else
#define ITERATION_METHOD_TIMING_START
#define ITERATION_METHOD_TIMING_END
#define ITERATION_METHOD_RETURN_DURATION std::chrono::microseconds(0)
#endif

PowerIterationOutput PowerIteration(const PowerIterationInput &input) {
auto A = input.A;
auto x = input.x_default;
Expand Down
16 changes: 1 addition & 15 deletions CustomMath_lib/QRMethod/QRMethod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,6 @@

#include "QRMethod.h"

#define MAX_ITERATION 100000
#define ENABLE_TIMING

#ifdef ENABLE_TIMING
#define ITERATION_METHOD_TIMING_START auto start = std::chrono::high_resolution_clock::now();
#define ITERATION_METHOD_TIMING_END auto end = std::chrono::high_resolution_clock::now(); \
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(end - start);
#define ITERATION_METHOD_RETURN_DURATION duration
#else
#define ITERATION_METHOD_TIMING_START
#define ITERATION_METHOD_TIMING_END
#define ITERATION_METHOD_RETURN_DURATION std::chrono::microseconds(0)
#endif

MIterationMethodOutput QRMethod(const Matrix &matrix) {
Matrix H = matrix;
Matrix Q;
Expand All @@ -28,7 +14,7 @@ MIterationMethodOutput QRMethod(const Matrix &matrix) {

HessenbergMethod_Inplace(H, Q);

for (int count = 0; count < MAX_ITERATION; count++) {
for (int count = 0; count < ITERATION_METHOD_MAX_ITERATION; count++) {
// set all abs(h_{i,i-1}) < 1e-10 to 0
for (ull i = 0; i < H.rows - 1; i++) {
if (std::abs(H.matrix[i + 1][i]) < 1e-6) {
Expand Down
14 changes: 14 additions & 0 deletions CustomMath_lib/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#ifndef NUMERICAL_ALGEBRA_BASE_H
#define NUMERICAL_ALGEBRA_BASE_H

#define ENABLE_ITERATION_METHOD_TIMING
#define ITERATION_METHOD_MAX_ITERATION 100000

#include "iostream"
#include "iomanip"
#include "cmath"
Expand All @@ -28,4 +31,15 @@ struct IterationMethodOutput {
std::chrono::microseconds time_cost;
};

#ifdef ENABLE_ITERATION_METHOD_TIMING
#define ITERATION_METHOD_TIMING_START auto start = std::chrono::high_resolution_clock::now();
#define ITERATION_METHOD_TIMING_END auto end = std::chrono::high_resolution_clock::now(); \
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(end - start);
#define ITERATION_METHOD_RETURN_DURATION duration
#else
#define ITERATION_METHOD_TIMING_START
#define ITERATION_METHOD_TIMING_END
#define ITERATION_METHOD_RETURN_DURATION std::chrono::microseconds(0)
#endif

#endif //NUMERICAL_ALGEBRA_BASE_H

0 comments on commit fc3b0ef

Please sign in to comment.