项目作者: jdao55

项目描述 :
c++20 compile time, expression template matrix library
高级语言: C++
项目地址: git://github.com/jdao55/ce-matrix.git
创建时间: 2020-06-24T20:39:08Z
项目社区:https://github.com/jdao55/ce-matrix

开源协议:MIT License

下载


ce-matrix

c++20 compile time (constexpr), header only and expression template matrix library (WIP Expect api to change)

  1. /*
  2. 0 1 2 1 1 1
  3. 3 4 5 * 1 1 1
  4. 6 7 8 1 1 1
  5. */
  6. int main()
  7. {
  8. constexpr ce::vari::matrix_t<int, 3, 3> A{ 0, 1, 2,
  9. 3, 4, 5,
  10. 6, 7, 8};
  11. constexpr ce::vari::matrix_t<int, 3, 3> B{ 1, 1, 1,
  12. 1, 1, 1,
  13. 1, 1, 1};
  14. constexpr ce::vari::matrix_t<int, 3, 3> C = A*B;
  15. return C[0];
  16. }

The matrix mulitplication of A*B is evaluated at compile time
The above program is compiled to:(using gcc10.1 with flags: -S -std=c++2a -masm=intel)

  1. main:
  2. push rbp
  3. mov rbp, rsp
  4. sub rsp, 144
  5. mov DWORD PTR [rbp-48], 0
  6. mov DWORD PTR [rbp-44], 1
  7. mov DWORD PTR [rbp-40], 2
  8. mov DWORD PTR [rbp-36], 3
  9. mov DWORD PTR [rbp-32], 4
  10. mov DWORD PTR [rbp-28], 5
  11. mov DWORD PTR [rbp-24], 6
  12. mov DWORD PTR [rbp-20], 7
  13. mov DWORD PTR [rbp-16], 8
  14. mov DWORD PTR [rbp-96], 1
  15. mov DWORD PTR [rbp-92], 1
  16. mov DWORD PTR [rbp-88], 1
  17. mov DWORD PTR [rbp-84], 1
  18. mov DWORD PTR [rbp-80], 1
  19. mov DWORD PTR [rbp-76], 1
  20. mov DWORD PTR [rbp-72], 1
  21. mov DWORD PTR [rbp-68], 1
  22. mov DWORD PTR [rbp-64], 1
  23. mov DWORD PTR [rbp-144], 3
  24. mov DWORD PTR [rbp-140], 3
  25. mov DWORD PTR [rbp-136], 3
  26. mov DWORD PTR [rbp-132], 12
  27. mov DWORD PTR [rbp-128], 12
  28. mov DWORD PTR [rbp-124], 12
  29. mov DWORD PTR [rbp-120], 21
  30. mov DWORD PTR [rbp-116], 21
  31. mov DWORD PTR [rbp-112], 21
  32. lea rax, [rbp-144]
  33. mov esi, 0
  34. mov rdi, rax
  35. call _ZNK2ce8ctmatrixIiLm3ELm3EEixEm
  36. mov eax, DWORD PTR [rax]
  37. leave
  38. ret

Dependancies

  • c++20 compliant compiler
    • currently working on gcc-10.1, more compilers will be supported as they get better c++20 supportDependancies
  • for benchmarks and examples

Examples

  1. using namespace ce::vari;
  2. constexpr matrix_t<float, 3, 3> A{ 1, 2, 3, 4, 5, 6, 7, 8, 9 };
  3. constexpr matrix_t<float, 3, 3> B{ 1, 2, 3, 4, 5, 6, 7, 8, 9 };
  4. constexpr matrix_t<float, 3, 3> C{ 1, 2, 3, 4, 5, 6, 7, 8, 9 };
  5. //binary operators
  6. constexpr matrix_t<float, 3, 3> D = A + B + C;
  7. constexpr matrix_t<float, 3, 3> E = A * B - C;
  8. constexpr matrix_t<float, 3, 3> E2 = A * 2;
  9. //
  10. constexpr vector_t<int, 3> v1{ 1, 2, 3 };
  11. constexpr vector_t<int, 3> v2{ 2, 3, 4 };
  12. constexpr auto v3 = ce::vari::dot_product(v1, v2);
  13. static_assert(v3 == 20, "error wrong dot product value");