Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impl ordinary diff equation solver #77

Merged
merged 328 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
328 commits
Select commit Hold shift + click to select a range
8e1ac91
Fix bugs in explicit RK nd ODE solver
cpmech Feb 5, 2024
84551a7
[wip] Add sample ODE
cpmech Feb 5, 2024
5a29439
Fix sample
cpmech Feb 5, 2024
feea5bd
Add test
cpmech Feb 5, 2024
1f580fe
[Important] Rename parameters
cpmech Feb 5, 2024
54ca76a
[wip] Organize parameters
cpmech Feb 5, 2024
276d401
Rename files
cpmech Feb 5, 2024
d7b3a00
Rename Params
cpmech Feb 5, 2024
3e5bdb3
Rename Solver
cpmech Feb 5, 2024
23aab5d
Rename System
cpmech Feb 5, 2024
e8421dd
Fix doc
cpmech Feb 5, 2024
6cfc343
Remove unused files
cpmech Feb 5, 2024
36502c7
Improve doc
cpmech Feb 5, 2024
fffb823
Improve params checks and comments
cpmech Feb 5, 2024
fac9316
Fix check
cpmech Feb 5, 2024
c86cb61
Improve Params
cpmech Feb 6, 2024
280dcb1
Improve test
cpmech Feb 6, 2024
096b057
[wip] Radau5
cpmech Feb 6, 2024
3621161
Remove phantom data
cpmech Feb 6, 2024
ea0f953
[wip] Radau5
cpmech Feb 6, 2024
02d4716
[sparse] Impl Symmetry::No and remove Option<Symmetry>
cpmech Feb 6, 2024
7dd5ac4
Remove use of rmp-serde in tests
cpmech Feb 8, 2024
4c2d3bf
[sparse] Impl serialize for enums
cpmech Feb 8, 2024
aa6c63e
Make CooMatrix generic
cpmech Feb 8, 2024
1bb5846
[sparse] Fix bug: mat_vec_mul needs to use alpha in symmetric case
cpmech Feb 8, 2024
9048b7d
Add tests
cpmech Feb 8, 2024
f69c6cd
[wip] Important: Impl COO to CSC directly
cpmech Feb 8, 2024
268ea98
[wip] Coo to Csc matrix
cpmech Feb 8, 2024
084e141
Save Coo to Csc temp vectors in CscMatrix
cpmech Feb 9, 2024
6d61492
Improve comments
cpmech Feb 9, 2024
0ac259c
Improve comment
cpmech Feb 9, 2024
f89e65a
Remove unnecessary cast
cpmech Feb 9, 2024
ca3e970
[sparse] Use samples in tests
cpmech Feb 9, 2024
8278787
[sparse] Use samples in tests
cpmech Feb 9, 2024
abf3626
[sparse] Add tests
cpmech Feb 9, 2024
b2e0eaa
[sparse] Add tests
cpmech Feb 9, 2024
bffda00
[sparse] Add tests
cpmech Feb 9, 2024
c31a1d6
[sparse] Add aux code
cpmech Feb 9, 2024
ecc25cc
[sparse] Fix comment in sample
cpmech Feb 9, 2024
748e0b5
[sparse] Shuffle sample data
cpmech Feb 9, 2024
c7c1952
[sparse] Improve comment
cpmech Feb 9, 2024
8c97657
[sparse] Important: replace Coo to Csr with Davis' code
cpmech Feb 9, 2024
691fe5a
[sparse] Improve comments
cpmech Feb 9, 2024
86ae77c
[sparse] Remove unused comment
cpmech Feb 9, 2024
afa07f5
[sparse] Impl serialize + deserialize for Csc and Csr matrices
cpmech Feb 9, 2024
9e05494
[sparse] Improve sorting in Coo to Csr conversion
cpmech Feb 9, 2024
1ee912b
[sparse] Improve comments
cpmech Feb 9, 2024
e491127
Improve comments about types
cpmech Feb 9, 2024
53ff4e8
[sparse] Make CSC and CSR matrices generic. Working on Complex numbers
cpmech Feb 9, 2024
62a1664
[sparse] Fix doc
cpmech Feb 9, 2024
e5e47b3
[sparse] Add tests
cpmech Feb 10, 2024
4286f85
[sparse] Add sample
cpmech Feb 10, 2024
1966f71
[sparse] Add tests
cpmech Feb 10, 2024
bd605ee
[sparse] Add sample
cpmech Feb 10, 2024
7bd77ce
[sparse] Add sample
cpmech Feb 10, 2024
2cbd225
[sparse] Add tests
cpmech Feb 10, 2024
4edcdde
[sparse] Add tests
cpmech Feb 10, 2024
2cd9738
[sparse] Add dup and shuffle samples
cpmech Feb 10, 2024
7af43b4
[sparse] Fix grammar
cpmech Feb 11, 2024
fe5e107
[sparse] Impl serialize for SparseMatrix
cpmech Feb 11, 2024
63f242a
[sparse] Use unwrap where an error cannot happen
cpmech Feb 11, 2024
aa5a4fe
[sparse] Add tests
cpmech Feb 11, 2024
2120c75
[sparse] Make SparseMatrix generic
cpmech Feb 11, 2024
573984d
Merge branch 'main' into impl-ordinary-diff-equation-solver
cpmech Feb 12, 2024
7d7455b
Merge branch 'main' into impl-ordinary-diff-equation-solver
cpmech Feb 12, 2024
3b73850
[ode] Fix dep version
cpmech Feb 12, 2024
3be5f44
[wip] Impl real and imag parts of the mantissa in stats
cpmech Feb 12, 2024
7b42f7e
[lab] Impl complex vec norm and update
cpmech Feb 13, 2024
43ea14d
[lab] Replace http with https for netlib links
cpmech Feb 13, 2024
eb0486d
[lab] Impl complex_mat_update
cpmech Feb 13, 2024
ce885cc
[lab] Fix doc tests
cpmech Feb 13, 2024
abfdbb1
[sparse] Impl complex option in VerifyLinSys
cpmech Feb 13, 2024
9866157
[sparse] Rename method from of VerifyLinSys
cpmech Feb 13, 2024
eff66de
[sparse] Fix doc test
cpmech Feb 13, 2024
a10799d
[sparse] [wip] Complex UMFPACK
cpmech Feb 14, 2024
d6b83ba
[lab] Impl complex mat copy and inverse
cpmech Feb 14, 2024
dadcff2
[sparse] Add sample
cpmech Feb 14, 2024
96c65f8
[sparse] [wip] Add test
cpmech Feb 14, 2024
e83defb
[lab] Add test
cpmech Feb 14, 2024
0b819de
[sparse] Improve sample
cpmech Feb 14, 2024
7c4dcf8
[sparse] Fix test
cpmech Feb 14, 2024
fdf89a7
[sparse] Add sample
cpmech Feb 14, 2024
32788aa
[sparse] Add test
cpmech Feb 14, 2024
e416e27
[sparse] Add tests
cpmech Feb 14, 2024
297bd00
[sparse] Add tests
cpmech Feb 14, 2024
721ac71
[sparse] Improve tests
cpmech Feb 14, 2024
f3f4c4c
[sparse] c_code: set determinant data to zero
cpmech Feb 14, 2024
290dc94
[sparse] Make MUMPS methods pub(crate)
cpmech Feb 14, 2024
86cbd61
[sparse] Improve var name in test
cpmech Feb 14, 2024
c81b53a
[sparse] Improve samples
cpmech Feb 14, 2024
e9e5794
[sparse] Impl Complex solver MUMPS
cpmech Feb 14, 2024
ef8c1bf
[sparse] Add tests
cpmech Feb 14, 2024
2d64d74
[sparse] Add tests
cpmech Feb 14, 2024
7a800d3
[sparse] Organize tests: MUMPS
cpmech Feb 15, 2024
9bc7773
[sparse] Improve test
cpmech Feb 15, 2024
71317c4
[sparse] Add example
cpmech Feb 15, 2024
9013aee
[sparse] Improve memcheck
cpmech Feb 15, 2024
22ec39f
[sparse] [Important] Enforce Send on the C-wrapped structures
cpmech Feb 16, 2024
889fcba
[sparse] Impl augment in CooMatrix
cpmech Feb 16, 2024
05efa58
[sparse] Impl augment for Sparse Matrix
cpmech Feb 16, 2024
6fbfa9a
[sparse] Improve comment
cpmech Feb 16, 2024
937a081
[sparse] Impl assign and augment for complex COO
cpmech Feb 16, 2024
b0bec36
[lab] Improve complex zip methods
cpmech Feb 16, 2024
faeb7c1
[lab] Impl complex_mat_unzip
cpmech Feb 16, 2024
73e6900
[lab] Impl complex_vec_unzip
cpmech Feb 16, 2024
a774c19
[lab] Improve doc tests
cpmech Feb 16, 2024
24c0ee1
[lab] Fix mod.rs
cpmech Feb 16, 2024
8ebcda9
[sparse] [wip] Impl Radau5
cpmech Feb 16, 2024
cb94d61
[ode] Improve OdeSolver
cpmech Feb 16, 2024
72d4ad8
[ode] Rename ode solver files
cpmech Feb 16, 2024
7c315bd
[ode] Rename OdeSolverTrait
cpmech Feb 16, 2024
c11e1b3
[ode] Rename OdeSolver
cpmech Feb 16, 2024
841dc0a
[lab] Fix test name
cpmech Feb 17, 2024
80bd8c4
[lab] Fix test name
cpmech Feb 17, 2024
9a37259
[ode] [wip] Radau5
cpmech Feb 17, 2024
71a641d
[ode] Improve params for Radau5
cpmech Feb 17, 2024
4b430ad
[sparse] Impl assign method of Coo and Sparse matrices
cpmech Feb 17, 2024
c074561
[ode] [wip] Radau5 (working)
cpmech Feb 17, 2024
9bf6486
[ode] Rewrite test function
cpmech Feb 18, 2024
3b76330
[ode] Organize params
cpmech Feb 19, 2024
2103091
[ode] Rename first accept step variable
cpmech Feb 19, 2024
e65b796
[lab] Impl format fortran number
cpmech Feb 19, 2024
20eeb20
[ode] Add check for x == x1
cpmech Feb 19, 2024
c3c3102
[ode] Remove new line in display bench
cpmech Feb 20, 2024
d5f3eb9
[ode] Ignore log txt file
cpmech Feb 20, 2024
cac0e67
[ode] Rename success flag in BwEuler
cpmech Feb 20, 2024
3b3b2fb
[ode] Add fortran radau5.f reference results
cpmech Feb 20, 2024
ad048ba
[ode] Impl summary for Benchmark
cpmech Feb 20, 2024
da596c9
[ode] Fix radau5 and improve tests
cpmech Feb 20, 2024
ed4c509
[ode] Improve tests
cpmech Feb 20, 2024
c7f4add
[wip] Impl dense output for Radau5
cpmech Feb 20, 2024
e0d644b
[wip] Impl dense output for Radau5
cpmech Feb 20, 2024
7f264d3
[wip] Impl Output for Ode Solver
cpmech Feb 20, 2024
79bdcc1
[ode] Rename push_step method
cpmech Feb 20, 2024
fa1c45e
[ode] Improve dense output comments. Add assert to radau5
cpmech Feb 21, 2024
f67f342
[ode] Improve Output
cpmech Feb 21, 2024
2b7376b
[ode] Add prelude
cpmech Feb 21, 2024
b36bf76
[ode] Fix dense output
cpmech Feb 21, 2024
ccf0ceb
[ode] Handle unavailable dense output cases
cpmech Feb 21, 2024
5b30a10
[ode] Fix saving of optimal stepsize. Improve tests
cpmech Feb 21, 2024
e73a281
[ode] Fix saving accepted steps in dense output
cpmech Feb 21, 2024
2a5d6f9
[ode] Remove redundant step stat. Fix tests
cpmech Feb 21, 2024
900922e
[ode] Organize tests
cpmech Feb 21, 2024
baddbad
[ode] Rename log files
cpmech Feb 21, 2024
390677a
[ode] Remove the last three lines of the log files
cpmech Feb 21, 2024
a5a8a06
[ode] Improve compare script
cpmech Feb 21, 2024
9ffa6a7
[ode] Simplify comparison script
cpmech Feb 21, 2024
adf6e64
[ode] Rename debug test files
cpmech Feb 21, 2024
9a33d27
[ode] Rename test debug functions
cpmech Feb 21, 2024
29a14ac
[ode] Rename test files
cpmech Feb 21, 2024
8665368
[ode] Rename test functions
cpmech Feb 21, 2024
4d806d0
[ode] Fix comment about fortran file
cpmech Feb 21, 2024
432ea1b
[ode] Split dopri5 test files
cpmech Feb 21, 2024
5935a7f
[ode] [wip] Impl ERK Dense Output
cpmech Feb 21, 2024
cd0522b
[ode] Improve params
cpmech Feb 22, 2024
e124e03
[ode] Improve doc comments
cpmech Feb 22, 2024
09dea8f
[ode] Add comments in Radau5
cpmech Feb 22, 2024
48b1dac
[ode] Impl logging in Explicit Runge-Kutta
cpmech Feb 22, 2024
40a2055
[ode] Rename script
cpmech Feb 22, 2024
0bbef1f
[ode] Print method description in Benchmark
cpmech Feb 22, 2024
72a5388
[ode] Check DoPri5
cpmech Feb 22, 2024
9ac177d
[ode] Rename variable
cpmech Feb 22, 2024
632c2bc
[ode] Show log for reject steps in ERK
cpmech Feb 22, 2024
89a44df
[ode] Important: simplify the main loop. Save h_accepted instead of o…
cpmech Feb 23, 2024
7238246
[ode] Add test
cpmech Feb 23, 2024
f89b7dc
[ode] Add DoPri8 test
cpmech Feb 23, 2024
f495669
[ode] Improve doc comment
cpmech Feb 23, 2024
cbec082
[ode] Check for small stepsize. Impl Robertson's equation
cpmech Feb 23, 2024
09d5da7
[ode] Remove use of unzip in Radau5
cpmech Feb 23, 2024
4774b15
[ode] Improve doc comments
cpmech Feb 24, 2024
c3b33bd
[ode] Fix x1 in Robertson's equation
cpmech Feb 24, 2024
969f0e8
[ode] Add robertson's test
cpmech Feb 24, 2024
bf7e437
[ode] Fix robertson's test
cpmech Feb 24, 2024
e21ee1c
[ode] Remove unnecessary output in robertson's test
cpmech Feb 24, 2024
ab0ac6e
[ode] [wip] Amplifier problem
cpmech Feb 24, 2024
67771f6
[lab] Impl matrix conversion to BLAS band format
cpmech Feb 26, 2024
09eb3c6
[ode] Add the Amplifier test
cpmech Feb 26, 2024
06d5cf5
[ode] Remove stiffness detection temporarily
cpmech Feb 27, 2024
5d1e5fb
[ode] Organize ERK code
cpmech Feb 27, 2024
fde6db5
[ode] Simplify ERK dense output struct
cpmech Feb 27, 2024
07cf883
[ode] [wip] Stiffness detection
cpmech Feb 27, 2024
d72e578
[ode] Important: Organize parameters
cpmech Feb 27, 2024
513c27b
[ode] Add tests
cpmech Feb 27, 2024
9312e94
[ode] Rename debug flag
cpmech Feb 27, 2024
312ae2a
[ode] Add test: VDP equation with DoPri8
cpmech Feb 27, 2024
88f0d3b
[ode] Remove temporary stiff detect in ERK
cpmech Feb 27, 2024
a418997
[ode] Improve comment
cpmech Feb 27, 2024
9d130c5
[ode] [wip] Impl stiffness detection
cpmech Feb 27, 2024
a4212a7
[ode] Improve stiffness detection
cpmech Feb 28, 2024
8a6d58d
[ode] Simplify detect_stiffness function
cpmech Feb 28, 2024
dbced5c
[ode] Debug DoPri8 stiffness detection
cpmech Feb 28, 2024
e4f2122
[ode] Add test
cpmech Feb 28, 2024
bd83583
Increase tol to make tests work on different machines
cpmech Feb 28, 2024
0a17e32
Increase tol of test for Intel MKL
cpmech Feb 28, 2024
257b57b
Remove unnecessary pub use command
cpmech Feb 28, 2024
610ce0b
[ode] Improve samples
cpmech Mar 2, 2024
32d322f
[ode] Improve doc comments
cpmech Mar 2, 2024
0db7d77
[ode] Improve test script
cpmech Mar 2, 2024
5b868cc
[ode] Improve comments
cpmech Mar 2, 2024
1bc0ee1
[ode] Organize tests
cpmech Mar 2, 2024
cbe00d8
[ode] Improve tests
cpmech Mar 2, 2024
eebee54
[ode] Improve tests
cpmech Mar 2, 2024
92c63d1
[ode] Improve test
cpmech Mar 2, 2024
a755c83
[ode] Simplify test
cpmech Mar 2, 2024
80bd74e
[ode] Add test
cpmech Mar 2, 2024
3084722
[ode] Add test
cpmech Mar 2, 2024
ff0052d
[ode] Add test
cpmech Mar 2, 2024
3782e7e
[ode] Add test
cpmech Mar 2, 2024
70b13c1
[ode] Rename sample
cpmech Mar 4, 2024
410ad88
[ode] Update Mathematica reference results
cpmech Mar 4, 2024
5770fbc
[ode] Add Mathematica code to example
cpmech Mar 4, 2024
a15043d
[ode] Add Mathematica code to test
cpmech Mar 4, 2024
61f2b78
[ode] Add Mathematica code to test
cpmech Mar 4, 2024
68977ac
[ode] Rename sample equation
cpmech Mar 4, 2024
9ee243d
[ode] Remove sample eq
cpmech Mar 4, 2024
76e5cd1
[ode] Add sample problem
cpmech Mar 4, 2024
b49d050
[ode] Run initialize inside step in Radau5. Simplify BwEuler. Remove …
cpmech Mar 5, 2024
4f61645
[ode] Fix handling of unavailable dense output in ERK
cpmech Mar 5, 2024
c8c4919
[ode] Improve handling of (un)availability of dense output
cpmech Mar 5, 2024
2d1107c
[ode] Fix comment in test
cpmech Mar 5, 2024
2b8819a
[ode] Improve test
cpmech Mar 5, 2024
714c276
[ode] Add test
cpmech Mar 5, 2024
8cefd8e
[ode] Add test
cpmech Mar 5, 2024
d9c4682
[ode] Add test
cpmech Mar 5, 2024
d228f93
[ode] Add test
cpmech Mar 5, 2024
da527a5
[ode] Add test
cpmech Mar 5, 2024
e41b819
[ode] Use unwrap in Samples put command
cpmech Mar 5, 2024
0332fa7
[ode] Test num Jacobian in BwEuler
cpmech Mar 5, 2024
9e49b0b
[ode] Add test
cpmech Mar 5, 2024
985ed1f
[ode] Use unwrap where error cannot occur (Radau5)
cpmech Mar 5, 2024
63b882d
[ode] Improve test
cpmech Mar 5, 2024
472f4a7
[ode] Rename NoArgs type
cpmech Mar 5, 2024
e192da5
[ode] Add sample ODE
cpmech Mar 5, 2024
f24c130
[ode] Improve handling of final step. Add tests
cpmech Mar 5, 2024
817b2a5
[ode] Improve small step checking
cpmech Mar 5, 2024
886d2a5
[ode] Remove unnecessary error return in dense_output function (becau…
cpmech Mar 5, 2024
332b160
[ode] Improve ErkDenseOut
cpmech Mar 5, 2024
2b51f22
[ode] Rename sample amplifier to amplifier2t (two-transistors)
cpmech Mar 6, 2024
11d88f8
[ode] Impl sample: one-transistor amplifier
cpmech Mar 6, 2024
0459b0b
[lab] Impl format scientific
cpmech Mar 6, 2024
df13915
[ode] Add missing semicolon
cpmech Mar 6, 2024
e81d118
[ode] Test one-transistor amplifier with Radau5
cpmech Mar 6, 2024
b4acbc5
[ode] Remove two-transistor amplifier example
cpmech Mar 6, 2024
9d20f46
[ode] Simplify ERK a little
cpmech Mar 7, 2024
69c25f6
[sparse] Increase tol of test for Intel MKL
cpmech Mar 7, 2024
717bac9
[ode] Add comments about RK constants
cpmech Mar 7, 2024
377c61f
[ode] [Important] Store the mass matrix in System. Use Fn instead of …
cpmech Mar 8, 2024
55c5c93
[sparse] [Important] Remove the one_based flag. Store Fortran indices…
cpmech Mar 8, 2024
31e6310
[sparse] Fix tests that use intel mkl feature
cpmech Mar 8, 2024
7750622
[ode] Add tests
cpmech Mar 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
"cSpell.words": [
"aiᵢⱼ",
"archlinux",
"Arenstorf",
"Arioli",
"BLACS",
"blasint",
"bweuler",
"Demmel",
"devel",
"dgeev",
Expand All @@ -17,14 +19,23 @@
"dgetri",
"dgssvx",
"Dᵢⱼₖₗ",
"dopri",
"Dormand",
"Dorozhinskii",
"dpotrf",
"dscal",
"dsyev",
"dsyrk",
"dtype",
"dznrm2",
"FACCON",
"Fehlberg",
"Flannery",
"FSAL",
"fweuler",
"gfortran",
"Gustafsson",
"Heun",
"ifort",
"IIIₛ",
"ᵢⱼₖₗ",
Expand All @@ -43,27 +54,36 @@
"lredrhs",
"lrhs",
"lsol",
"Lubich",
"lwork",
"mdeuler",
"memcheck",
"Merson",
"msgpass",
"nelt",
"Nørsett",
"nstage",
"nstep",
"odyad",
"oneapi",
"PERMUT",
"PREORDER",
"pthread",
"Radau",
"RINFOG",
"rowcol",
"rowcoliter",
"rowcolrig",
"rustup",
"Schur",
"substeps",
"Teukolsky",
"tgamma",
"tocsc",
"tocsr",
"udyad",
"unsym",
"Verner",
"Vetterling",
"zcopy",
"zgemm",
Expand All @@ -74,6 +94,8 @@
"zgetri",
"zherk",
"zlange",
"ZMUMPS",
"Zonneveld",
"zpotrf",
"zscal",
"zsyrk"
Expand Down
9 changes: 5 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
[workspace]

members = [
"russell_lab",
"russell_sparse",
"russell_stat",
"russell_tensor"
"russell_lab",
"russell_ode",
"russell_sparse",
"russell_stat",
"russell_tensor",
]

resolver = "2"
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

![Bertrand Russell](Bertrand_Russell_1957.jpg)

([CC0](http://creativecommons.org/publicdomain/zero/1.0/deed.en). Photo: [Bertrand Russell](https://en.wikipedia.org/wiki/Bertrand_Russell))
([CC0](https://creativecommons.org/publicdomain/zero/1.0/deed.en). Photo: [Bertrand Russell](https://en.wikipedia.org/wiki/Bertrand_Russell))

## Contents

Expand Down Expand Up @@ -298,7 +298,7 @@ fn main() -> Result<(), StrError> {
// . -1 -3 2 .
// . . 1 . .
// . 4 2 . 1
let mut coo = SparseMatrix::new_coo(ndim, ndim, nnz, None, false)?;
let mut coo = SparseMatrix::new_coo(ndim, ndim, nnz, None)?;
coo.put(0, 0, 1.0)?; // << (0, 0, a00/2) duplicate
coo.put(0, 0, 1.0)?; // << (0, 0, a00/2) duplicate
coo.put(1, 0, 3.0)?;
Expand Down Expand Up @@ -336,7 +336,7 @@ fn main() -> Result<(), StrError> {
// analysis
let mut stats = StatsLinSol::new();
umfpack.update_stats(&mut stats);
let (mx, ex) = (stats.determinant.mantissa, stats.determinant.exponent);
let (mx, ex) = (stats.determinant.mantissa_real, stats.determinant.exponent);
println!("det(a) = {:?}", mx * f64::powf(10.0, ex));
println!("rcond = {:?}", stats.output.umfpack_rcond_estimate);
Ok(())
Expand Down
1 change: 0 additions & 1 deletion russell_lab/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ num-traits = "0.2"
serde = { version = "1.0", features = ["derive"] }

[dev-dependencies]
rmp-serde = "1.1"
serde_json = "1.0"

[build-dependencies]
Expand Down
45 changes: 36 additions & 9 deletions russell_lab/c_code/interface_blas.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#define FN_DGESVD dgesvd_
#define FN_DGETRF dgetrf_
#define FN_DGETRI dgetri_
#define FN_ZGETRF zgetrf_
#define FN_ZGETRI zgetri_
#else
#include "cblas.h"
#include "lapack.h"
Expand All @@ -28,6 +30,8 @@
#define FN_DGESVD LAPACK_dgesvd
#define FN_DGETRF LAPACK_dgetrf
#define FN_DGETRI LAPACK_dgetri
#define FN_ZGETRF LAPACK_zgetrf
#define FN_ZGETRI LAPACK_zgetri
#endif

#include "constants.h"
Expand Down Expand Up @@ -78,7 +82,7 @@ int32_t c_get_num_threads() {
}

// Computes the solution to a system of linear equations
// <http://www.netlib.org/lapack/explore-html/d8/d72/dgesv_8f.html>
// <https://www.netlib.org/lapack/explore-html/d8/d72/dgesv_8f.html>
void c_dgesv(const int32_t *n,
const int32_t *nrhs,
double *a,
Expand All @@ -91,7 +95,7 @@ void c_dgesv(const int32_t *n,
}

// Computes the solution to a real system of linear equations (complex version)
// <http://www.netlib.org/lapack/explore-html/d1/ddc/zgesv_8f.html>
// <https://www.netlib.org/lapack/explore-html/d1/ddc/zgesv_8f.html>
void c_zgesv(const int32_t *n,
const int32_t *nrhs,
COMPLEX64 *a,
Expand All @@ -104,7 +108,7 @@ void c_zgesv(const int32_t *n,
}

// Computes the matrix norm
// <http://www.netlib.org/lapack/explore-html/dc/d09/dlange_8f.html>
// <https://www.netlib.org/lapack/explore-html/dc/d09/dlange_8f.html>
double c_dlange(int32_t norm_code,
const int32_t *m,
const int32_t *n,
Expand All @@ -119,7 +123,7 @@ double c_dlange(int32_t norm_code,
}

// Computes the matrix norm (complex version)
// <http://www.netlib.org/lapack/explore-html/d5/d8f/zlange_8f.html>
// <https://www.netlib.org/lapack/explore-html/d5/d8f/zlange_8f.html>
double c_zlange(int32_t norm_code,
const int32_t *m,
const int32_t *n,
Expand All @@ -134,7 +138,7 @@ double c_zlange(int32_t norm_code,
}

// Computes the Cholesky factorization of a real symmetric positive definite matrix
// <http://www.netlib.org/lapack/explore-html/d0/d8a/dpotrf_8f.html>
// <https://www.netlib.org/lapack/explore-html/d0/d8a/dpotrf_8f.html>
void c_dpotrf(C_BOOL upper,
const int32_t *n,
double *a,
Expand All @@ -161,7 +165,7 @@ void c_dsyev(C_BOOL calc_v,
}

// Computes the eigenvalues and eigenvectors of a general matrix
// <http://www.netlib.org/lapack/explore-html/d9/d28/dgeev_8f.html>
// <https://www.netlib.org/lapack/explore-html/d9/d28/dgeev_8f.html>
void c_dgeev(C_BOOL calc_vl,
C_BOOL calc_vr,
const int32_t *n,
Expand All @@ -182,7 +186,7 @@ void c_dgeev(C_BOOL calc_vl,
}

// Computes the singular value decomposition (SVD)
// <http://www.netlib.org/lapack/explore-html/d8/d2d/dgesvd_8f.html>
// <https://www.netlib.org/lapack/explore-html/d8/d2d/dgesvd_8f.html>
void c_dgesvd(int32_t jobu_code,
int32_t jobvt_code,
const int32_t *m,
Expand All @@ -209,7 +213,7 @@ void c_dgesvd(int32_t jobu_code,
}

// Computes the LU factorization of a general (m,n) matrix
// <http://www.netlib.org/lapack/explore-html/d3/d6a/dgetrf_8f.html>
// <https://www.netlib.org/lapack/explore-html/d3/d6a/dgetrf_8f.html>
void c_dgetrf(const int32_t *m,
const int32_t *n,
double *a,
Expand All @@ -220,7 +224,7 @@ void c_dgetrf(const int32_t *m,
}

// Computes the inverse of a matrix using the LU factorization computed by dgetrf
// <http://www.netlib.org/lapack/explore-html/df/da4/dgetri_8f.html>
// <https://www.netlib.org/lapack/explore-html/df/da4/dgetri_8f.html>
void c_dgetri(const int32_t *n,
double *a,
const int32_t *lda,
Expand All @@ -230,3 +234,26 @@ void c_dgetri(const int32_t *n,
int32_t *info) {
FN_DGETRI(n, a, lda, ipiv, work, lwork, info);
}

// Computes the LU factorization of a general (m,n) matrix
// <https://www.netlib.org/lapack/explore-html/dd/dd1/zgetrf_8f.html>
void c_zgetrf(const int32_t *m,
const int32_t *n,
COMPLEX64 *a,
const int32_t *lda,
int32_t *ipiv,
int32_t *info) {
FN_ZGETRF(m, n, a, lda, ipiv, info);
}

// Computes the inverse of a matrix using the LU factorization computed by zgetrf
// <https://www.netlib.org/lapack/explore-html/d0/db3/zgetri_8f.html>
void c_zgetri(const int32_t *n,
COMPLEX64 *a,
const int32_t *lda,
const int32_t *ipiv,
COMPLEX64 *work,
const int32_t *lwork,
int32_t *info) {
FN_ZGETRI(n, a, lda, ipiv, work, lwork, info);
}
6 changes: 4 additions & 2 deletions russell_lab/examples/ex_matrix_eigenvalues.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ fn main() -> Result<(), StrError> {
// err := a⋅v - v⋅λ
// ```
let a = ComplexMatrix::from(&data);
let v = complex_mat_zip(&v_real, &v_imag)?;
let d = complex_vec_zip(&l_real, &l_imag)?;
let mut v = ComplexMatrix::new(m, m);
let mut d = ComplexVector::new(m);
complex_mat_zip(&mut v, &v_real, &v_imag)?;
complex_vec_zip(&mut d, &l_real, &l_imag)?;
let lam = ComplexMatrix::diagonal(d.as_data());
let mut a_v = ComplexMatrix::new(m, m);
let mut v_l = ComplexMatrix::new(m, m);
Expand Down
2 changes: 1 addition & 1 deletion russell_lab/src/base/auxiliary_blas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ extern "C" {
fn c_get_num_threads() -> i32;

// Finds the index of the maximum absolute value
// <http://www.netlib.org/lapack/explore-html/dd/de0/idamax_8f.html>
// <https://www.netlib.org/lapack/explore-html/dd/de0/idamax_8f.html>
fn cblas_idamax(n: i32, x: *const f64, incx: i32) -> i32;
}

Expand Down
50 changes: 49 additions & 1 deletion russell_lab/src/base/formatters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,31 @@ pub fn format_nanoseconds(nanoseconds: u128) -> String {
buf
}

/// Formats a number using the scientific notation
pub fn format_scientific(num: f64, width: usize, precision: usize) -> String {
// based on <https://stackoverflow.com/questions/65264069/alignment-of-floating-point-numbers-printed-in-scientific-notation>
const EXP_PAD: usize = 2;
let mut result = format!("{:.precision$e}", num, precision = precision);
let exp = result.split_off(result.find('e').unwrap());
let (sign, exp) = if exp.starts_with("e-") {
('-', &exp[2..])
} else {
('+', &exp[1..])
};
result.push_str(&format!("E{}{:0>pad$}", sign, exp, pad = EXP_PAD));
format!("{:>width$}", result, width = width)
}

/// Formats a number using the scientific notation as in Fortran with the ES23.15 format
pub fn format_fortran(num: f64) -> String {
format_scientific(num, 23, 15)
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#[cfg(test)]
mod tests {
use super::format_nanoseconds;
use super::{format_fortran, format_nanoseconds, format_scientific};

#[test]
fn format_nanoseconds_works() {
Expand Down Expand Up @@ -170,4 +190,32 @@ mod tests {
res = format_nanoseconds(3_601_100_000_000);
assert_eq!(res, "1h1.1s");
}

#[test]
fn format_scientific_works() {
assert_eq!(format_scientific(0.1111, 9, 2), " 1.11E-01");
assert_eq!(format_scientific(0.02222, 11, 4), " 2.2220E-02");
assert_eq!(format_scientific(3333.0, 10, 3), " 3.333E+03");
assert_eq!(format_scientific(-44444.0, 9, 1), " -4.4E+04");
assert_eq!(format_scientific(0.0, 8, 1), " 0.0E+00");
assert_eq!(format_scientific(1.0, 23, 15), " 1.000000000000000E+00");
assert_eq!(format_scientific(42.0, 23, 15), " 4.200000000000000E+01");
assert_eq!(format_scientific(9999999999.00, 8, 1), " 1.0E+10");
assert_eq!(format_scientific(999999999999.00, 23, 15), " 9.999999999990000E+11");
assert_eq!(format_scientific(123456789.1011, 11, 4), " 1.2346E+08");
}

#[test]
fn format_fortran_works() {
assert_eq!(format_fortran(0.1111), " 1.111000000000000E-01");
assert_eq!(format_fortran(0.02222), " 2.222000000000000E-02");
assert_eq!(format_fortran(3333.0), " 3.333000000000000E+03");
assert_eq!(format_fortran(-44444.0), " -4.444400000000000E+04");
assert_eq!(format_fortran(0.0), " 0.000000000000000E+00");
assert_eq!(format_fortran(1.0), " 1.000000000000000E+00");
assert_eq!(format_fortran(42.0), " 4.200000000000000E+01");
assert_eq!(format_fortran(9999999999.00), " 9.999999999000000E+09");
assert_eq!(format_fortran(999999999999.00), " 9.999999999990000E+11");
assert_eq!(format_fortran(123456789.1011), " 1.234567891011000E+08");
}
}
Loading