https://github.com/jturney/EinsumsInCpp
Provides compile-time contraction pattern analysis to determine optimal tensor operation to perform.
https://github.com/jturney/EinsumsInCpp
cp-decomposition cpp cpp20 dense-matrices einsum linear-algebra matrix matrix-computations matrix-library scientific-computing tensor tensor-contraction tensor-decomposition tensors tucker-decomposition
Last synced: 4 months ago
JSON representation
Provides compile-time contraction pattern analysis to determine optimal tensor operation to perform.
- Host: GitHub
- URL: https://github.com/jturney/EinsumsInCpp
- Owner: Einsums
- License: mit
- Created: 2022-01-12T15:47:35.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-10-29T19:35:11.000Z (7 months ago)
- Last Synced: 2024-10-29T21:38:49.343Z (7 months ago)
- Topics: cp-decomposition, cpp, cpp20, dense-matrices, einsum, linear-algebra, matrix, matrix-computations, matrix-library, scientific-computing, tensor, tensor-contraction, tensor-decomposition, tensors, tucker-decomposition
- Language: C++
- Homepage: https://einsums.github.io/Einsums/
- Size: 23.6 MB
- Stars: 46
- Watchers: 5
- Forks: 7
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Einsums in C++
| | |
|---|---|
| **Status** | [](https://codecov.io/github/Einsums/Einsums)  |
| **Release** |   |
| **Documentation** | [](https://einsums.github.io/Einsums/) |Provides compile-time contraction pattern analysis to determine optimal operation to perform.
## Requirements
A C++ compiler with C++20 support.The following libraries are required to build Einsums:
* BLAS and LAPACK
* HDF5The following libraries are also required, but will be fetched if they can not be found.
* fmtlib >= 11
* Catch2 >= 3
* Einsums/h5cpp
* p-ranav/argparse
* gabime/spdlog >= 1On my personal development machine, I use MKL for the above requirements. On GitHub Actions, stock BLAS, LAPACK, and FFTW3 are used.
Optional requirements:
* A Fast Fourier Transform library, either FFTW3 or DFT from MKL.
* For call stack backtracing, refer to the requirements listed [here](https://github.com/bombela/backward-cpp).
* HIP for graphics card support. Uses hipBlas, hipSolver, and the HIP language. Does not yet support hipFFT.
* cpptrace for backtraces.
* LibreTT for GPU transposes.
* pybind11 for the Python extension module.## Examples
This will optimize at compile-time to a BLAS dgemm call.
```C++
#include "Einsums/TensorAlgebra.hpp"using einsums; // Provides Tensor and create_random_tensor
using einsums::tensor_algebra; // Provides einsum and Indices
using einsums::index; // Provides i, j, kTensor<2> A = create_random_tensor("A", 7, 7);
Tensor<2> B = create_random_tensor("B", 7, 7);
Tensor<2> C{"C", 7, 7};einsum(Indices{i, j}, &C, Indices{i, k}, A, Indices{k, j}, B);
```Two-Electron Contribution to the Fock Matrix
```C++
#include "Einsums/TensorAlgebra.hpp"using namespace einsums;
void build_Fock_2e_einsum(Tensor<2> *F,
const Tensor<4> &g,
const Tensor<2> &D) {
using namespace einsums::tensor_algebra;
using namespace einsums::index;// Will compile-time optimize to BLAS gemv
einsum(1.0, Indices{p, q}, F,
2.0, Indices{p, q, r, s}, g, Indices{r, s}, D);// As written cannot be optimized.
// A generic arbitrary contraction function will be used.
einsum(1.0, Indices{p, q}, F,
-1.0, Indices{p, r, q, s}, g, Indices{r, s}, D);
}
```
W Intermediates in CCD
```C++
Wmnij = g_oooo;
// Compile-time optimizes to gemm
einsum(1.0, Indices{m, n, i, j}, &Wmnij,
0.25, Indices{i, j, e, f}, t_oovv,
Indices{m, n, e, f}, g_oovv);Wabef = g_vvvv;
// Compile-time optimizes to gemm
einsum(1.0, Indices{a, b, e, f}, &Wabef,
0.25, Indices{m, n, e, f}, g_oovv,
Indices{m, n, a, b}, t_oovv);Wmbej = g_ovvo;
// As written uses generic arbitrary contraction function
einsum(1.0, Indices{m, b, e, j}, &Wmbej,
-0.5, Indices{j, n, f, b}, t_oovv,
Indices{m, n, e, f}, g_oovv);
```CCD Energy
```C++
/// Compile-time optimizes to a dot product
einsum(0.0, Indices{}, &e_ccd,
0.25, Indices{i, j, a, b}, new_t_oovv,
Indices{i, j, a, b}, g_oovv);
```