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

Commit

Permalink
refactor: split files
Browse files Browse the repository at this point in the history
  • Loading branch information
tiankaima committed Oct 23, 2023
1 parent bdd5973 commit f309cb3
Show file tree
Hide file tree
Showing 25 changed files with 659 additions and 444 deletions.
49 changes: 0 additions & 49 deletions CustomMath_lib/Array.h

This file was deleted.

26 changes: 14 additions & 12 deletions CustomMath_lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
project(CustomMath)

set(HEADER_FILES
Matrix.h
Array.h
GaussMethod.cpp
GaussMethod.h
CholeskyMethod.cpp
CholeskyMethod.h
Matrix/Matrix.h
Vector/Vector.h
CholeskyMethod/CholeskyMethod.h
GaussMethod/TriangleMatrix.h
GaussMethod/LU.h
GaussMethod/LU_FP.h
GaussMethod/LU_PP.h
)

set(SOURCE_FILES
Matrix.cpp
Array.cpp
GaussMethod.cpp
GaussMethod.h
CholeskyMethod.cpp
CholeskyMethod.h
Matrix/Matrix.cpp
Vector/Vector.cpp
CholeskyMethod/CholeskyMethod.cpp
GaussMethod/TriangleMatrix.cpp
GaussMethod/LU.cpp
GaussMethod/LU_FP.cpp
GaussMethod/LU_PP.cpp
)

add_library(CustomMath_lib STATIC ${SOURCE_FILES} ${HEADER_FILES})
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@

#include "CholeskyMethod.h"

Array CholeskySolve(const Matrix &A, const Array &b) {
Vector CholeskySolve(const Matrix &A, const Vector &b) {
Matrix L;
CholeskyFactorization(A, &L);
Array y = LowerGaussSolve(L, b);
Array x = UpperGaussSolve(L.transpose(), y);
Vector y = LowerTriangleMatrixSolve(L, b);
Vector x = UpperTriangleMatrixSolve(L.transpose(), y);
return x;
}

void CholeskyFactorization_T(Matrix *A) {
A->requireSquare();
CHECK_SQUARE_MATRIX(A)

for (int k = 0; k < A->rows; k++) {
if (A->matrix[k][k] <= 0) {
Expand All @@ -34,7 +34,8 @@ void CholeskyFactorization_T(Matrix *A) {
}

void CholeskyFactorization(const Matrix &A, Matrix *L) {
A.requireSquare();
CHECK_SQUARE_MATRIX_REF(A)

*L = Matrix(A);
CholeskyFactorization_T(L);

Expand All @@ -45,21 +46,21 @@ void CholeskyFactorization(const Matrix &A, Matrix *L) {
}
}

Array Cholesky_LDLT_Solve(const Matrix &A, const Array &b) {
Vector Cholesky_LDLT_Solve(const Matrix &A, const Vector &b) {
Matrix L, D;
Cholesky_LDLT_Factorization(A, &L, &D);
Array y = LowerGaussSolve(L, b);
Vector y = LowerTriangleMatrixSolve(L, b);
for (int i = 0; i < A.rows; i++) {
y.array[i] /= D.matrix[i][i];
}
Array x = UpperGaussSolve(L.transpose(), y);
Vector x = UpperTriangleMatrixSolve(L.transpose(), y);
return x;
}

void Cholesky_LDLT_Factorization_T(Matrix *A) {
A->requireSquare();
CHECK_SQUARE_MATRIX(A)

Array tmp = Array(A->rows);
Vector tmp = Vector(A->rows);

for (int j = 0; j < A->rows; j++) {
for (int i = 0; i < j; i++) {
Expand All @@ -79,7 +80,8 @@ void Cholesky_LDLT_Factorization_T(Matrix *A) {


void Cholesky_LDLT_Factorization(const Matrix &A, Matrix *L, Matrix *D) {
A.requireSquare();
CHECK_SQUARE_MATRIX_REF(A)

*L = Matrix(A);
Cholesky_LDLT_Factorization_T(L);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@
#define NUMERICAL_ALGEBRA_CHOLESKYMETHOD_H

#include "vector"
#include "Array.h"
#include "Matrix.h"
#include "Vector/Vector.h"
#include "Matrix/Matrix.h"
#include "iostream"
#include "cmath"
#include "GaussMethod.h"
#include "GaussMethod/TriangleMatrix.h"

// 1.3.1
Array CholeskySolve(const Matrix &A, const Array &b);
Vector CholeskySolve(const Matrix &A, const Vector &b);

void CholeskyFactorization(const Matrix &A, Matrix *L);

void CholeskyFactorization_T(Matrix *A);

// 1.3.2
Array Cholesky_LDLT_Solve(const Matrix &A, const Array &b);
Vector Cholesky_LDLT_Solve(const Matrix &A, const Vector &b);

void Cholesky_LDLT_Factorization(const Matrix &A, Matrix *L, Matrix *D);

Expand Down
Loading

0 comments on commit f309cb3

Please sign in to comment.