ngsolve 6.2.2501.post16.dev1__cp313-cp313-macosx_10_15_universal2.whl → 6.2.2501.post34.dev1__cp313-cp313-macosx_10_15_universal2.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of ngsolve might be problematic. Click here for more details.

Files changed (286) hide show
  1. ngsolve/webgui.py +1 -1
  2. {ngsolve-6.2.2501.post16.dev1.dist-info → ngsolve-6.2.2501.post34.dev1.dist-info}/METADATA +2 -2
  3. ngsolve-6.2.2501.post34.dev1.dist-info/RECORD +25 -0
  4. netgen/include/arnoldi.hpp +0 -55
  5. netgen/include/bandmatrix.hpp +0 -334
  6. netgen/include/basematrix.hpp +0 -957
  7. netgen/include/basevector.hpp +0 -1268
  8. netgen/include/bdbequations.hpp +0 -2752
  9. netgen/include/bdbintegrator.hpp +0 -1659
  10. netgen/include/bessel.hpp +0 -1064
  11. netgen/include/bilinearform.hpp +0 -963
  12. netgen/include/bla.hpp +0 -29
  13. netgen/include/blockalloc.hpp +0 -95
  14. netgen/include/blockjacobi.hpp +0 -316
  15. netgen/include/bspline.hpp +0 -114
  16. netgen/include/calcinverse.hpp +0 -141
  17. netgen/include/cg.hpp +0 -368
  18. netgen/include/chebyshev.hpp +0 -44
  19. netgen/include/cholesky.hpp +0 -720
  20. netgen/include/clapack.h +0 -7254
  21. netgen/include/code_generation.hpp +0 -296
  22. netgen/include/coefficient.hpp +0 -2006
  23. netgen/include/coefficient_impl.hpp +0 -18
  24. netgen/include/coefficient_stdmath.hpp +0 -157
  25. netgen/include/commutingAMG.hpp +0 -106
  26. netgen/include/comp.hpp +0 -79
  27. netgen/include/compatibility.hpp +0 -41
  28. netgen/include/complex_wrapper.hpp +0 -73
  29. netgen/include/compressedfespace.hpp +0 -110
  30. netgen/include/contact.hpp +0 -231
  31. netgen/include/diagonalmatrix.hpp +0 -154
  32. netgen/include/differentialoperator.hpp +0 -276
  33. netgen/include/diffop.hpp +0 -1286
  34. netgen/include/diffop_impl.hpp +0 -326
  35. netgen/include/discontinuous.hpp +0 -84
  36. netgen/include/dump.hpp +0 -949
  37. netgen/include/eigen.hpp +0 -60
  38. netgen/include/eigensystem.hpp +0 -18
  39. netgen/include/elasticity_equations.hpp +0 -595
  40. netgen/include/elementbyelement.hpp +0 -195
  41. netgen/include/elementtopology.hpp +0 -1760
  42. netgen/include/elementtransformation.hpp +0 -339
  43. netgen/include/evalfunc.hpp +0 -405
  44. netgen/include/expr.hpp +0 -1655
  45. netgen/include/facetfe.hpp +0 -175
  46. netgen/include/facetfespace.hpp +0 -178
  47. netgen/include/facethofe.hpp +0 -111
  48. netgen/include/facetsurffespace.hpp +0 -112
  49. netgen/include/fe_interfaces.hpp +0 -32
  50. netgen/include/fem.hpp +0 -87
  51. netgen/include/fesconvert.hpp +0 -14
  52. netgen/include/fespace.hpp +0 -1445
  53. netgen/include/finiteelement.hpp +0 -286
  54. netgen/include/globalinterfacespace.hpp +0 -77
  55. netgen/include/globalspace.hpp +0 -115
  56. netgen/include/gridfunction.hpp +0 -525
  57. netgen/include/h1amg.hpp +0 -41
  58. netgen/include/h1hofe.hpp +0 -188
  59. netgen/include/h1hofe_impl.hpp +0 -1262
  60. netgen/include/h1hofefo.hpp +0 -148
  61. netgen/include/h1hofefo_impl.hpp +0 -185
  62. netgen/include/h1hofespace.hpp +0 -167
  63. netgen/include/h1lofe.hpp +0 -1237
  64. netgen/include/h1lumping.hpp +0 -35
  65. netgen/include/hcurl_equations.hpp +0 -1352
  66. netgen/include/hcurlcurlfe.hpp +0 -2221
  67. netgen/include/hcurlcurlfespace.hpp +0 -78
  68. netgen/include/hcurlfe.hpp +0 -259
  69. netgen/include/hcurlfe_utils.hpp +0 -107
  70. netgen/include/hcurlhdiv_dshape.hpp +0 -857
  71. netgen/include/hcurlhdivfes.hpp +0 -308
  72. netgen/include/hcurlhofe.hpp +0 -175
  73. netgen/include/hcurlhofe_impl.hpp +0 -1871
  74. netgen/include/hcurlhofespace.hpp +0 -193
  75. netgen/include/hcurllofe.hpp +0 -1146
  76. netgen/include/hdiv_equations.hpp +0 -865
  77. netgen/include/hdivdivfe.hpp +0 -2923
  78. netgen/include/hdivdivsurfacespace.hpp +0 -76
  79. netgen/include/hdivfe.hpp +0 -206
  80. netgen/include/hdivfe_utils.hpp +0 -716
  81. netgen/include/hdivfes.hpp +0 -75
  82. netgen/include/hdivhofe.hpp +0 -447
  83. netgen/include/hdivhofe_impl.hpp +0 -1107
  84. netgen/include/hdivhofefo.hpp +0 -229
  85. netgen/include/hdivhofespace.hpp +0 -175
  86. netgen/include/hdivhosurfacefespace.hpp +0 -106
  87. netgen/include/hdivlofe.hpp +0 -773
  88. netgen/include/hidden.hpp +0 -74
  89. netgen/include/householder.hpp +0 -181
  90. netgen/include/hypre_ams_precond.hpp +0 -123
  91. netgen/include/hypre_precond.hpp +0 -73
  92. netgen/include/integrator.hpp +0 -2024
  93. netgen/include/integratorcf.hpp +0 -253
  94. netgen/include/interpolate.hpp +0 -49
  95. netgen/include/intrule.hpp +0 -2541
  96. netgen/include/irspace.hpp +0 -49
  97. netgen/include/jacobi.hpp +0 -136
  98. netgen/include/l2hofe.hpp +0 -193
  99. netgen/include/l2hofe_impl.hpp +0 -564
  100. netgen/include/l2hofefo.hpp +0 -542
  101. netgen/include/l2hofespace.hpp +0 -344
  102. netgen/include/la.hpp +0 -38
  103. netgen/include/linearform.hpp +0 -266
  104. netgen/include/matrix.hpp +0 -2140
  105. netgen/include/memusage.hpp +0 -41
  106. netgen/include/meshaccess.hpp +0 -1358
  107. netgen/include/mgpre.hpp +0 -204
  108. netgen/include/mptools.hpp +0 -2145
  109. netgen/include/multigrid.hpp +0 -42
  110. netgen/include/multivector.hpp +0 -447
  111. netgen/include/mumpsinverse.hpp +0 -187
  112. netgen/include/mycomplex.hpp +0 -361
  113. netgen/include/ng_lapack.hpp +0 -1661
  114. netgen/include/ngblas.hpp +0 -1099
  115. netgen/include/ngs_defines.hpp +0 -30
  116. netgen/include/ngs_stdcpp_include.hpp +0 -106
  117. netgen/include/ngs_utils.hpp +0 -121
  118. netgen/include/ngsobject.hpp +0 -1019
  119. netgen/include/ngsstream.hpp +0 -113
  120. netgen/include/ngstd.hpp +0 -72
  121. netgen/include/nodalhofe.hpp +0 -96
  122. netgen/include/nodalhofe_impl.hpp +0 -141
  123. netgen/include/normalfacetfe.hpp +0 -223
  124. netgen/include/normalfacetfespace.hpp +0 -98
  125. netgen/include/normalfacetsurfacefespace.hpp +0 -84
  126. netgen/include/order.hpp +0 -251
  127. netgen/include/parallel_matrices.hpp +0 -222
  128. netgen/include/paralleldofs.hpp +0 -340
  129. netgen/include/parallelngs.hpp +0 -23
  130. netgen/include/parallelvector.hpp +0 -269
  131. netgen/include/pardisoinverse.hpp +0 -200
  132. netgen/include/periodic.hpp +0 -125
  133. netgen/include/plateaufespace.hpp +0 -25
  134. netgen/include/pml.hpp +0 -275
  135. netgen/include/pmltrafo.hpp +0 -631
  136. netgen/include/postproc.hpp +0 -142
  137. netgen/include/precomp.hpp +0 -60
  138. netgen/include/preconditioner.hpp +0 -602
  139. netgen/include/prolongation.hpp +0 -235
  140. netgen/include/python_comp.hpp +0 -107
  141. netgen/include/python_fem.hpp +0 -89
  142. netgen/include/python_linalg.hpp +0 -58
  143. netgen/include/python_ngstd.hpp +0 -385
  144. netgen/include/recursive_pol.hpp +0 -4844
  145. netgen/include/recursive_pol_tet.hpp +0 -395
  146. netgen/include/recursive_pol_trig.hpp +0 -492
  147. netgen/include/reorderedfespace.hpp +0 -81
  148. netgen/include/sample_sort.hpp +0 -105
  149. netgen/include/scalarfe.hpp +0 -335
  150. netgen/include/shapefunction_utils.hpp +0 -113
  151. netgen/include/simd_complex.hpp +0 -284
  152. netgen/include/smoother.hpp +0 -253
  153. netgen/include/solve.hpp +0 -89
  154. netgen/include/sparsecholesky.hpp +0 -313
  155. netgen/include/sparsematrix.hpp +0 -1038
  156. netgen/include/sparsematrix_dyn.hpp +0 -91
  157. netgen/include/sparsematrix_impl.hpp +0 -920
  158. netgen/include/special_matrix.hpp +0 -461
  159. netgen/include/specialelement.hpp +0 -125
  160. netgen/include/statushandler.hpp +0 -33
  161. netgen/include/stringops.hpp +0 -12
  162. netgen/include/superluinverse.hpp +0 -136
  163. netgen/include/symbolicintegrator.hpp +0 -849
  164. netgen/include/symmetricmatrix.hpp +0 -144
  165. netgen/include/tangentialfacetfe.hpp +0 -224
  166. netgen/include/tangentialfacetfespace.hpp +0 -106
  167. netgen/include/tensor.hpp +0 -522
  168. netgen/include/tensorcoefficient.hpp +0 -446
  169. netgen/include/tensorproductintegrator.hpp +0 -113
  170. netgen/include/thcurlfe.hpp +0 -128
  171. netgen/include/thcurlfe_impl.hpp +0 -380
  172. netgen/include/thdivfe.hpp +0 -80
  173. netgen/include/thdivfe_impl.hpp +0 -426
  174. netgen/include/tpdiffop.hpp +0 -461
  175. netgen/include/tpfes.hpp +0 -133
  176. netgen/include/tpintrule.hpp +0 -224
  177. netgen/include/triangular.hpp +0 -465
  178. netgen/include/tscalarfe.hpp +0 -245
  179. netgen/include/tscalarfe_impl.hpp +0 -1029
  180. netgen/include/umfpackinverse.hpp +0 -148
  181. netgen/include/vector.hpp +0 -1219
  182. netgen/include/voxelcoefficientfunction.hpp +0 -41
  183. netgen/include/vtkoutput.hpp +0 -198
  184. netgen/include/vvector.hpp +0 -208
  185. netgen/include/webgui.hpp +0 -92
  186. netgen/libngbla.dylib +0 -0
  187. netgen/libngcomp.dylib +0 -0
  188. netgen/libngfem.dylib +0 -0
  189. netgen/libngla.dylib +0 -0
  190. netgen/libngsolve.dylib +0 -0
  191. netgen/libngstd.dylib +0 -0
  192. ngsolve/__init__.pyi +0 -231
  193. ngsolve/bla.pyi +0 -1139
  194. ngsolve/bvp.pyi +0 -32
  195. ngsolve/cmake/NGSolveConfig.cmake +0 -102
  196. ngsolve/cmake/ngsolve-targets-release.cmake +0 -69
  197. ngsolve/cmake/ngsolve-targets.cmake +0 -163
  198. ngsolve/comp/__init__.pyi +0 -5382
  199. ngsolve/comp/pml.pyi +0 -89
  200. ngsolve/config/__init__.py +0 -1
  201. ngsolve/config/__init__.pyi +0 -43
  202. ngsolve/config/__main__.py +0 -4
  203. ngsolve/config/config.py +0 -60
  204. ngsolve/config/config.pyi +0 -45
  205. ngsolve/demos/TensorProduct/__init__.py +0 -0
  206. ngsolve/demos/TensorProduct/tp_dg_1d_1d.py +0 -80
  207. ngsolve/demos/TensorProduct/tp_dg_1d_2d.py +0 -73
  208. ngsolve/demos/TensorProduct/tp_dg_2d_1d.py +0 -72
  209. ngsolve/demos/TensorProduct/tp_dg_2d_2d.py +0 -66
  210. ngsolve/demos/__init__.py +0 -0
  211. ngsolve/demos/howto/__init__.py +0 -0
  212. ngsolve/demos/howto/hhj.py +0 -44
  213. ngsolve/demos/howto/hybrid_dg.py +0 -53
  214. ngsolve/demos/howto/mixed.py +0 -30
  215. ngsolve/demos/howto/nonlin.py +0 -29
  216. ngsolve/demos/howto/pickling.py +0 -26
  217. ngsolve/demos/howto/pml.py +0 -31
  218. ngsolve/demos/howto/taskmanager.py +0 -20
  219. ngsolve/demos/howto/tdnns.py +0 -47
  220. ngsolve/demos/howto/timeDG-skeleton.py +0 -45
  221. ngsolve/demos/howto/timeDG.py +0 -38
  222. ngsolve/demos/howto/timeDGlap.py +0 -42
  223. ngsolve/demos/howto/timeDGwave.py +0 -61
  224. ngsolve/demos/intro/__init__.py +0 -0
  225. ngsolve/demos/intro/adaptive.py +0 -123
  226. ngsolve/demos/intro/cmagnet.py +0 -62
  227. ngsolve/demos/intro/elasticity.py +0 -76
  228. ngsolve/demos/intro/navierstokes.py +0 -74
  229. ngsolve/demos/intro/poisson.ipynb +0 -170
  230. ngsolve/demos/intro/poisson.py +0 -41
  231. ngsolve/demos/mpi/__init__.py +0 -0
  232. ngsolve/demos/mpi/mpi_cmagnet.py +0 -87
  233. ngsolve/demos/mpi/mpi_navierstokes.py +0 -117
  234. ngsolve/demos/mpi/mpi_poisson.py +0 -89
  235. ngsolve/demos/mpi/mpi_timeDG.py +0 -82
  236. ngsolve/directsolvers.pyi +0 -18
  237. ngsolve/eigenvalues.pyi +0 -30
  238. ngsolve/fem.pyi +0 -1707
  239. ngsolve/krylovspace.pyi +0 -309
  240. ngsolve/la.pyi +0 -1218
  241. ngsolve/ngslib.so +0 -0
  242. ngsolve/ngstd.pyi +0 -58
  243. ngsolve/nonlinearsolvers.pyi +0 -98
  244. ngsolve/preconditioners.pyi +0 -6
  245. ngsolve/solve.pyi +0 -108
  246. ngsolve/solvers.pyi +0 -14
  247. ngsolve/timestepping.pyi +0 -34
  248. ngsolve/timing.pyi +0 -57
  249. ngsolve/utils.pyi +0 -279
  250. ngsolve-6.2.2501.post16.dev1.data/data/Netgen.icns +0 -0
  251. ngsolve-6.2.2501.post16.dev1.data/data/bin/ngscxx +0 -17
  252. ngsolve-6.2.2501.post16.dev1.data/data/bin/ngsld +0 -13
  253. ngsolve-6.2.2501.post16.dev1.data/data/bin/ngsolve.tcl +0 -648
  254. ngsolve-6.2.2501.post16.dev1.data/data/bin/ngspy +0 -2
  255. ngsolve-6.2.2501.post16.dev1.data/data/share/ngsolve/beam.geo +0 -17
  256. ngsolve-6.2.2501.post16.dev1.data/data/share/ngsolve/beam.vol +0 -240
  257. ngsolve-6.2.2501.post16.dev1.data/data/share/ngsolve/chip.in2d +0 -41
  258. ngsolve-6.2.2501.post16.dev1.data/data/share/ngsolve/chip.vol +0 -614
  259. ngsolve-6.2.2501.post16.dev1.data/data/share/ngsolve/coil.geo +0 -12
  260. ngsolve-6.2.2501.post16.dev1.data/data/share/ngsolve/coil.vol +0 -2560
  261. ngsolve-6.2.2501.post16.dev1.data/data/share/ngsolve/coilshield.geo +0 -24
  262. ngsolve-6.2.2501.post16.dev1.data/data/share/ngsolve/coilshield.vol +0 -3179
  263. ngsolve-6.2.2501.post16.dev1.data/data/share/ngsolve/cube.geo +0 -19
  264. ngsolve-6.2.2501.post16.dev1.data/data/share/ngsolve/cube.vol +0 -1832
  265. ngsolve-6.2.2501.post16.dev1.data/data/share/ngsolve/d10_DGdoubleglazing.pde +0 -50
  266. ngsolve-6.2.2501.post16.dev1.data/data/share/ngsolve/d11_chip_nitsche.pde +0 -40
  267. ngsolve-6.2.2501.post16.dev1.data/data/share/ngsolve/d1_square.pde +0 -43
  268. ngsolve-6.2.2501.post16.dev1.data/data/share/ngsolve/d2_chip.pde +0 -35
  269. ngsolve-6.2.2501.post16.dev1.data/data/share/ngsolve/d3_helmholtz.pde +0 -22
  270. ngsolve-6.2.2501.post16.dev1.data/data/share/ngsolve/d4_cube.pde +0 -46
  271. ngsolve-6.2.2501.post16.dev1.data/data/share/ngsolve/d5_beam.pde +0 -74
  272. ngsolve-6.2.2501.post16.dev1.data/data/share/ngsolve/d6_shaft.pde +0 -73
  273. ngsolve-6.2.2501.post16.dev1.data/data/share/ngsolve/d7_coil.pde +0 -50
  274. ngsolve-6.2.2501.post16.dev1.data/data/share/ngsolve/d8_coilshield.pde +0 -49
  275. ngsolve-6.2.2501.post16.dev1.data/data/share/ngsolve/d9_hybridDG.pde +0 -72
  276. ngsolve-6.2.2501.post16.dev1.data/data/share/ngsolve/doubleglazing.in2d +0 -27
  277. ngsolve-6.2.2501.post16.dev1.data/data/share/ngsolve/doubleglazing.vol +0 -737
  278. ngsolve-6.2.2501.post16.dev1.data/data/share/ngsolve/piezo2d40round4.vol.gz +0 -0
  279. ngsolve-6.2.2501.post16.dev1.data/data/share/ngsolve/shaft.geo +0 -73
  280. ngsolve-6.2.2501.post16.dev1.data/data/share/ngsolve/shaft.vol +0 -4291
  281. ngsolve-6.2.2501.post16.dev1.data/data/share/ngsolve/square.in2d +0 -17
  282. ngsolve-6.2.2501.post16.dev1.data/data/share/ngsolve/square.vol +0 -149
  283. ngsolve-6.2.2501.post16.dev1.dist-info/RECORD +0 -304
  284. {ngsolve-6.2.2501.post16.dev1.dist-info → ngsolve-6.2.2501.post34.dev1.dist-info}/LICENSE +0 -0
  285. {ngsolve-6.2.2501.post16.dev1.dist-info → ngsolve-6.2.2501.post34.dev1.dist-info}/WHEEL +0 -0
  286. {ngsolve-6.2.2501.post16.dev1.dist-info → ngsolve-6.2.2501.post34.dev1.dist-info}/top_level.txt +0 -0
netgen/include/expr.hpp DELETED
@@ -1,1655 +0,0 @@
1
- #ifndef FILE_NGBLA_EXPR
2
- #define FILE_NGBLA_EXPR
3
-
4
- /**************************************************************************/
5
- /* File: expr.hpp */
6
- /* Author: Joachim Schoeberl */
7
- /* Date: 01. Jan. 02 */
8
- /**************************************************************************/
9
-
10
- #include <core/array.hpp>
11
- #include <core/localheap.hpp>
12
- #include <core/exception.hpp>
13
-
14
- #include <cstddef>
15
- #include <ngs_stdcpp_include.hpp> // for INLINE
16
- #include "complex_wrapper.hpp"
17
-
18
-
19
- #if defined(NETGEN_ENABLE_CHECK_RANGE) && !defined(__CUDA_ARCH__)
20
- #define NETGEN_CHECK_SHAPE(a,b) \
21
- { if(a.Shape() != b.Shape()) \
22
- ngcore::ThrowException(__FILE__ ":" NETGEN_CORE_NGEXEPTION_STR(__LINE__) "\t: shapes don't match"); }
23
- #else // defined(NETGEN_ENABLE_CHECK_RANGE) && !defined(__CUDA_ARCH__)
24
- #define NETGEN_CHECK_SHAPE(a,b)
25
- #endif // defined(NETGEN_ENABLE_CHECK_RANGE) && !defined(__CUDA_ARCH__)
26
-
27
-
28
- template <typename T>
29
- struct SafeIndex
30
- {
31
- T i;
32
- INLINE SafeIndex(T ai) : i(ai) { };
33
- INLINE operator T() const { return i; }
34
- INLINE auto operator++() { return ++i; }
35
- INLINE auto operator++(int) { return i++; }
36
- };
37
-
38
- namespace ngcore
39
- {
40
- template <typename T>
41
- struct IsSafe<SafeIndex<T>> {
42
- constexpr operator bool() const { return true; } };
43
- } // namespace ngcore
44
-
45
- /*
46
- namespace std {
47
- template <typename T>
48
- struct is_integral<SafeIndex<T>> {
49
- static constexpr bool value = true;
50
- };
51
- }
52
- */
53
-
54
- namespace ngbla
55
- {
56
- using namespace std;
57
- using namespace ngcore;
58
- using namespace ngstd;
59
-
60
-
61
- enum ORDERING { ColMajor, RowMajor };
62
-
63
-
64
- struct unused_dist
65
- {
66
- unused_dist () = default;
67
- unused_dist (size_t d) { };
68
- template <int S>
69
- unused_dist (IC<S> d) { };
70
- };
71
-
72
- template <typename T = double, ORDERING ORD = RowMajor, typename TH=size_t, typename TW=size_t, typename TDIST=size_t>
73
- class MatrixView;
74
-
75
- template <typename T = double, ORDERING ORD = RowMajor>
76
- using FlatMatrix = MatrixView<T,ORD,size_t, size_t, unused_dist>;
77
-
78
-
79
- // template <typename T = double, ORDERING ORD = RowMajor> class FlatMatrix;
80
- template <typename T = double, ORDERING ORD = RowMajor> class Matrix;
81
-
82
-
83
- template <int H, int W, typename T> class Mat;
84
- template <int H, typename T> class DiagMat;
85
- template <int S, typename T> class Vec;
86
-
87
-
88
- template <typename T>
89
- struct is_scalar_type { static constexpr bool value = false; };
90
-
91
- template <typename T>
92
- constexpr bool IsScalar ()
93
- {
94
- return is_scalar_type<T>::value;
95
- }
96
-
97
-
98
-
99
-
100
-
101
- /*
102
- Matrix expression templates
103
- */
104
-
105
-
106
- template <typename TM, enable_if_t<!IsScalar<TM>(),bool> = true>
107
- inline auto Access (const TM & mat, int i, int j)
108
- {
109
- return mat(i,j);
110
- }
111
-
112
- template <typename TM, enable_if_t<IsScalar<TM>(),bool> = true>
113
- inline auto Access (const TM & mat, int i, int j)
114
- {
115
- return mat;
116
- }
117
-
118
-
119
-
120
-
121
- template <typename T> struct is_scalar_type;
122
-
123
- template<> struct is_scalar_type<int> { static constexpr bool value = true; };
124
- template<> struct is_scalar_type<double> { static constexpr bool value = true; };
125
- template<> struct is_scalar_type<Complex> { static constexpr bool value = true; };
126
-
127
-
128
-
129
- /**
130
- Trait to obtain vector and scalar types for given matrix types.
131
- Is specified for double, Complex, AutoDiff<doube>, AutoDiff<Complex>
132
- */
133
-
134
-
135
-
136
-
137
- template <class T> class mat_traits;
138
-
139
- template <class T>
140
- class mat_traits
141
- {
142
- public:
143
- /// matrix element
144
- typedef T TELEM;
145
- /// field of matrix element
146
- typedef T TSCAL;
147
- /// type of column vector
148
- typedef T TV_COL;
149
- /// type of row vector
150
- typedef T TV_ROW;
151
- /// matrix height
152
- // enum { HEIGHT = 1 };
153
- /// matrix with
154
- // enum { WIDTH = 1 };
155
- // static constexpr int HEIGHT = 1;
156
- // static constexpr int WIDTH = 1;
157
- ///
158
- // enum { IS_COMPLEX = 0 };
159
- };
160
-
161
- template <class T>
162
- class mat_traits<const T> : public mat_traits<T> { };
163
- template <class T>
164
- class mat_traits<T&> : public mat_traits<T> { };
165
-
166
-
167
- /*
168
- template <int D>
169
- class mat_traits<ngcore::INT<D> >
170
- {
171
- public:
172
- typedef int TELEM;
173
- typedef int TSCAL;
174
- typedef int TV_COL;
175
- typedef int TV_ROW;
176
- // enum { HEIGHT = D };
177
- // enum { WIDTH = 1 };
178
- // enum { IS_COMPLEX = 0 };
179
- };
180
- */
181
-
182
- template <>
183
- class mat_traits<Complex>
184
- {
185
- public:
186
- typedef Complex TELEM;
187
- typedef Complex TSCAL;
188
- typedef Complex TV_COL;
189
- typedef Complex TV_ROW;
190
- // static constexpr int HEIGHT = 1;
191
- // static constexpr int WIDTH = 1;
192
- // enum { IS_COMPLEX = 1 };
193
- };
194
-
195
-
196
-
197
- /// Height of matrix
198
- template <class TM>
199
- inline auto Height (const TM & m)
200
- {
201
- return m.Height();
202
- }
203
-
204
- /// Width of matrix
205
- template <class TM>
206
- inline auto Width (const TM & m)
207
- {
208
- return m.Width();
209
- }
210
-
211
- template <> inline constexpr auto Height<double> (const double&) { return 1; }
212
- template <> inline constexpr auto Height<Complex> (const Complex&) { return 1; }
213
- template <> inline constexpr auto Width<double> (const double&) { return 1; }
214
- template <> inline constexpr auto Width<Complex> (const Complex&) { return 1; }
215
-
216
- /*
217
- template <class TM>
218
- inline constexpr size_t Height () { return Height(TM()); }
219
- template <class TM>
220
- inline constexpr size_t Width () { return Width(TM()); }
221
- */
222
-
223
- template <class TM>
224
- inline constexpr auto Height () { return TM::Height(); }
225
- template <class TM>
226
- inline constexpr auto Width () { return TM::Width(); }
227
-
228
- template <> inline constexpr auto Height<double> () { return 1; }
229
- template <> inline constexpr auto Height<Complex> () { return 1; }
230
- template <> inline constexpr auto Width<double> () { return 1; }
231
- template <> inline constexpr auto Width<Complex> () { return 1; }
232
-
233
-
234
- template <class TM>
235
- inline constexpr bool IsComplex () { return IsComplex<typename mat_traits<TM>::TSCAL>(); }
236
- template <> inline constexpr bool IsComplex<double> () { return false; }
237
- template <> inline constexpr bool IsComplex<Complex> () { return true; }
238
-
239
-
240
-
241
- template <class TA> class RowsArrayExpr;
242
- template <class TA> class ColsArrayExpr;
243
- template <class TA> class SubMatrixExpr;
244
- template <class TA> class RowExpr;
245
- template <class TA> class ColExpr;
246
-
247
-
248
-
249
-
250
- /**
251
- Expr is the base class for all matrix template expressions.
252
- Barton and Nackman Trick for template polymorphism, function Spec.
253
-
254
- provides Height and Width of matrix.
255
- IsLinear allows linear matrix element access.
256
- */
257
-
258
- #ifdef NETGEN_ENABLE_CHECK_RANGE
259
- struct undefined_size
260
- {
261
- size_t size;
262
-
263
- undefined_size() = default;
264
- constexpr undefined_size(size_t s) : size(s) { }
265
- template <int S>
266
- explicit constexpr undefined_size(IC<S> s) : size(s) { }
267
- explicit constexpr operator size_t() const { return size; }
268
- explicit constexpr operator int() const { return size; }
269
- explicit constexpr operator ptrdiff_t() const { return size; }
270
- };
271
-
272
-
273
- inline ostream & operator<< (ostream & ost, undefined_size s) { ost << "undefined("<<size_t(s)<<")"; return ost; }
274
- inline constexpr auto operator/ (undefined_size ud, size_t i) { return undefined_size(size_t(ud)/i); }
275
- inline constexpr auto operator- (undefined_size ud, size_t i) { return undefined_size(size_t(ud)-i); }
276
- inline constexpr auto operator+ (undefined_size ud, size_t i) { return undefined_size(size_t(ud)+i); }
277
- inline constexpr auto operator* (undefined_size ud, size_t i) { return undefined_size(size_t(ud)*i); }
278
- inline constexpr auto operator* (size_t i, undefined_size ud) { return undefined_size(size_t(ud)*i); }
279
- inline constexpr bool operator< (size_t i, undefined_size ud) { return i < size_t(ud); }
280
- inline constexpr bool operator< (undefined_size ud, size_t i) { return size_t(ud) < i; }
281
- inline constexpr bool operator>= (size_t i, undefined_size ud) { return i >= size_t(ud); }
282
- inline constexpr bool operator>= (undefined_size ud, size_t i) { return size_t(ud) >= i; }
283
- inline constexpr bool operator== (size_t i, undefined_size ud) { return i == size_t(ud); }
284
- inline constexpr bool operator== (undefined_size ud, size_t i) { return size_t(ud) == i; }
285
- inline constexpr bool operator== (undefined_size ud, undefined_size ud2) { return size_t(ud) == size_t(ud2); }
286
- inline constexpr bool operator!= (size_t i, undefined_size ud) { return i != size_t(ud); }
287
- inline constexpr bool operator!= (undefined_size ud, size_t i) { return size_t(ud) != i; }
288
- inline constexpr bool operator!= (undefined_size ud, undefined_size ud2) { return size_t(ud) != size_t(ud2); }
289
-
290
- #else
291
- struct undefined_size
292
- {
293
- undefined_size() = default;
294
- undefined_size(size_t s) { }
295
- template <int S>
296
- explicit constexpr undefined_size(IC<S> s) { }
297
- };
298
-
299
- inline ostream & operator<< (ostream & ost, undefined_size s) { ost << "undefined"; return ost; }
300
- inline auto operator/ (undefined_size ud, size_t i) { return ud; }
301
- inline auto operator- (undefined_size ud, size_t i) { return ud; }
302
- inline auto operator+ (undefined_size ud, size_t i) { return ud; }
303
- #endif
304
-
305
-
306
- INLINE constexpr auto CombinedSize(undefined_size s1, undefined_size s2) {
307
- NETGEN_CHECK_SAME(size_t(s1), size_t(s2)); return s1; }
308
- INLINE constexpr auto CombinedSize(undefined_size s1, size_t s2) {
309
- NETGEN_CHECK_SAME(size_t(s1), size_t(s2)); return s2; }
310
- INLINE constexpr auto CombinedSize(size_t s1, undefined_size s2) {
311
- NETGEN_CHECK_SAME(size_t(s1), size_t(s2)); return s1; }
312
- INLINE constexpr auto CombinedSize(size_t s1, size_t s2) {
313
- NETGEN_CHECK_SAME(size_t(s1), size_t(s2)); return s1; }
314
- template <int S1> INLINE constexpr auto CombinedSize(IC<S1> s1, undefined_size s2) {
315
- NETGEN_CHECK_SAME(size_t(s1), size_t(s2)); return s1; }
316
- template <int S1> INLINE constexpr auto CombinedSize(IC<S1> s1, size_t s2) {
317
- NETGEN_CHECK_SAME(size_t(s1), size_t(s2)); return s1; }
318
- template <int S1, int S2> INLINE constexpr auto CombinedSize(IC<S1> s1, IC<S2> s2) {
319
- NETGEN_CHECK_SAME(size_t(s1), size_t(s2)); return s1; }
320
- template <int S2> INLINE constexpr auto CombinedSize(undefined_size s1, IC<S2> s2) {
321
- NETGEN_CHECK_SAME(size_t(s1), size_t(s2)); return s2; }
322
- template <int S2> INLINE constexpr auto CombinedSize(size_t s1, IC<S2> s2) {
323
- NETGEN_CHECK_SAME(size_t(s1), size_t(s2)); return s2; }
324
-
325
- template <typename T1, typename T2>
326
- INLINE constexpr auto CombinedSize(tuple<T1> tup1, tuple<T2> tup2)
327
- { return tuple(CombinedSize(get<0>(tup1), get<0>(tup2))); }
328
-
329
- template <typename T11, typename T12, typename T21, typename T22>
330
- INLINE constexpr auto CombinedSize(tuple<T11,T12> tup1, tuple<T21,T22> tup2)
331
- { return tuple(CombinedSize(get<0>(tup1), get<0>(tup2)),
332
- CombinedSize(get<1>(tup1), get<1>(tup2))); }
333
-
334
-
335
-
336
-
337
-
338
-
339
- template <typename T>
340
- class Expr
341
- {
342
- public:
343
- constexpr Expr () = default;
344
-
345
- /// cast to specific type
346
- INLINE T & Spec() { return static_cast<T&> (*this); }
347
-
348
- /// cast to specific type
349
- INLINE const T & Spec() const { return static_cast<const T&> (*this); }
350
-
351
- INLINE auto View() const { return static_cast<const T&> (*this).View(); }
352
- INLINE decltype(auto) ViewRW() { return static_cast<T&>(*this).ViewRW(); }
353
- INLINE auto Shape() const { return Spec().T::Shape(); }
354
-
355
-
356
- INLINE auto Height() const { return Spec().T::Height(); }
357
- INLINE auto Width() const { return Spec().T::Width(); }
358
-
359
-
360
- void Dump (ostream & ost) const { Spec().T::Dump(ost); }
361
-
362
-
363
- INLINE auto Row (size_t r) const
364
- {
365
- // return RowExpr<const T> (static_cast<const T&> (*this), r);
366
- return RowExpr<const T> (this->View(), r);
367
- }
368
-
369
- INLINE auto Col (size_t r) const
370
- {
371
- // return ColExpr<const T> (static_cast<const T&> (*this), r);
372
- return ColExpr<const T> (this->View(), r);
373
- }
374
-
375
-
376
- INLINE SubMatrixExpr<T>
377
- Rows (size_t first, size_t next) const
378
- {
379
- // return SubMatrixExpr<T> (static_cast<T&> (*this), first, 0, next-first, Width());
380
- return SubMatrixExpr<T> (this->View(), first, 0, next-first, Width());
381
- }
382
-
383
- INLINE SubMatrixExpr<T>
384
- Cols (size_t first, size_t next) const
385
- {
386
- // return SubMatrixExpr<T> (static_cast<T&> (*this), 0, first, Height(), next-first);
387
- return SubMatrixExpr<T> (this->View(), 0, first, Height(), next-first);
388
- }
389
-
390
- INLINE SubMatrixExpr<T>
391
- Rows (IntRange range) const
392
- {
393
- return Rows (range.First(), range.Next());
394
- }
395
-
396
- INLINE SubMatrixExpr<T>
397
- Cols (IntRange range) const
398
- {
399
- return Cols (range.First(), range.Next());
400
- }
401
-
402
-
403
- INLINE RowsArrayExpr<T>
404
- Rows (FlatArray<int> rows) const
405
- {
406
- return RowsArrayExpr<T> (static_cast<const T&> (*this), rows);
407
- }
408
-
409
- INLINE ColsArrayExpr<T>
410
- Cols (FlatArray<int> cols) const
411
- {
412
- return ColsArrayExpr<T> (static_cast<const T&> (*this), cols);
413
- }
414
-
415
- };
416
-
417
-
418
-
419
-
420
-
421
-
422
-
423
-
424
-
425
- /**
426
- Caller knows that matrix expression is a symmetric matrix.
427
- Thus, only one half of the matrix needs to be computed.
428
- */
429
- template <typename T>
430
- class SymExpr : public Expr<SymExpr<T> >
431
- {
432
- T a;
433
- public:
434
-
435
- SymExpr (T aa) : a(aa) { ; }
436
-
437
- INLINE auto operator() (size_t i) const { return a(i); }
438
- INLINE auto operator() (size_t i, size_t j) const { return a(i,j); }
439
- INLINE auto Height() const { return a.Height(); }
440
- INLINE auto Width() const { return a.Width(); }
441
-
442
- auto View() const { return *this; }
443
- auto Shape() const { return a.Shape(); }
444
-
445
- static constexpr bool IsLinear() { return T::IsLinear(); }
446
- void Dump (ostream & ost) const
447
- { ost << "Sym ("; a.Dump(ost); ost << ")"; }
448
- };
449
-
450
-
451
- /**
452
- Declare that matrix expression is symmetric
453
- */
454
- template <typename T>
455
- inline SymExpr<T> Symmetric (const Expr<T> & a)
456
- {
457
- return SymExpr<T> (a.View());
458
- }
459
-
460
-
461
-
462
-
463
- template <typename TA>
464
- class LocalHeapExpr : public Expr<LocalHeapExpr<TA> >
465
- {
466
- const TA & a;
467
- LocalHeap * lh;
468
- public:
469
- INLINE LocalHeapExpr (const TA & aa, LocalHeap & alh) : a(aa), lh(&alh) { ; }
470
- INLINE const TA & A() const { return a; }
471
- INLINE auto Height() const { return a.Height(); }
472
- INLINE auto Width() const { return a.Width(); }
473
- INLINE LocalHeap & GetLocalHeap() const { return *lh; }
474
- };
475
-
476
- template <typename TA>
477
- INLINE LocalHeapExpr<TA> operator| (const Expr<TA> & a, LocalHeap & lh)
478
- {
479
- return LocalHeapExpr<TA> (a.Spec(), lh);
480
- }
481
-
482
-
483
- template <class TA> class MatExpr;
484
- template <class TA, class TB> class MultExpr;
485
- template <class TA> class MinusExpr;
486
- template <class TA> class TransExpr;
487
- template <class TA, class TS> class ScaleExpr;
488
-
489
-
490
-
491
- template <typename TOP, typename T, typename TB, typename Enable=int>
492
- class assign_trait
493
- {
494
- public:
495
- static INLINE T & Assign (MatExpr<T> & self, const Expr<TB> & v)
496
- {
497
- // NETGEN_CHECK_RANGE(self.Height(), v.Height(), v.Height()+1);
498
- // NETGEN_CHECK_RANGE(self.Width(), v.Width(), v.Width()+1);
499
- // NETGEN_CHECK_SHAPE(self.Spec(), v);
500
-
501
-
502
- auto src = v.View();
503
- decltype(auto) dest = self.ViewRW();
504
-
505
- auto h = CombinedSize (src.Height(), dest.Height()); // checks if same
506
- auto w = CombinedSize (src.Width(), dest.Width()); // checks if same
507
-
508
- if (T::COL_MAJOR)
509
- {
510
- if (h > 0)
511
- for (size_t j = 0; j < w; j++)
512
- for (size_t i = 0; i < h; i++)
513
- TOP()(dest(i,j), src(i,j));
514
- return self.Spec();
515
- }
516
-
517
-
518
- if (TB::IsLinear())
519
- {
520
- if (T::IsLinear())
521
- {
522
- auto hw = h*w;
523
- for (SafeIndex<size_t> i : Range(hw))
524
- TOP()(dest(i), src(i));
525
- }
526
- else
527
- {
528
- if (w > 0)
529
- for (SafeIndex<size_t> i = 0, k = 0; i < h; i++)
530
- for (SafeIndex<size_t> j = 0; j < w; j++, k++)
531
- TOP() (dest(i,j), src(k));
532
- }
533
- }
534
- else
535
- {
536
- if (w > 0)
537
- {
538
- if (T::IsLinear())
539
- for (SafeIndex<size_t> i = 0, k = 0; i < h; i++)
540
- for (SafeIndex<size_t> j = 0; j < w; j++, k++)
541
- TOP() (dest(k), src(i,j));
542
- else
543
- {
544
- for (SafeIndex<size_t> i = 0; i < h; i++)
545
- for (SafeIndex<size_t> j = 0; j < w; j++)
546
- TOP() (dest(i,j), src(i,j));
547
- }
548
- }
549
- }
550
- return self.Spec();
551
-
552
- }
553
- };
554
-
555
-
556
-
557
-
558
-
559
-
560
- /**
561
- The base class for matrices.
562
- */
563
- template <class T>
564
- class MatExpr : public Expr<T>
565
- {
566
- public:
567
-
568
- constexpr MatExpr () = default;
569
-
570
- using Expr<T>::Spec;
571
- using Expr<T>::Height;
572
- using Expr<T>::Width;
573
-
574
- enum { COL_MAJOR = 0 }; // matrix is stored col-major
575
-
576
- void Dump (ostream & ost) const { ost << "Matrix"; }
577
-
578
-
579
-
580
- template<typename TOP, typename TB>
581
- INLINE auto & Assign (const Expr<TB> & v)
582
- {
583
- return assign_trait<TOP, T, TB>::Assign (*this, v);
584
- }
585
-
586
-
587
- class As
588
- {
589
- public:
590
- template <typename T1, typename T2>
591
- INLINE void operator() (T1 && v1, const T2 & v2) { v1 = v2; }
592
- static constexpr bool IsPos() { return true; }
593
- static constexpr bool IsAdd() { return false; }
594
- };
595
- class AsAdd
596
- {
597
- public:
598
- template <typename T1, typename T2>
599
- INLINE void operator() (T1 && v1, const T2 & v2) { v1 += v2; }
600
- static constexpr bool IsPos() { return true; }
601
- static constexpr bool IsAdd() { return true; }
602
- };
603
- class AsSub
604
- {
605
- public:
606
- template <typename T1, typename T2>
607
- INLINE void operator() (T1 && v1, const T2 & v2) { v1 -= v2; }
608
- static constexpr bool IsPos() { return false; }
609
- static constexpr bool IsAdd() { return true; }
610
- };
611
-
612
-
613
-
614
-
615
-
616
- /*
617
- TODO: move to traits ...
618
-
619
- // x += s*y
620
- template <typename OP, typename TA,
621
- enable_if_t<std::is_same<OP,AsAdd>::value,bool> = true,
622
- enable_if_t<is_constructible_v<SliceVector<double>,typename pair<T,TA>::first_type>,bool> = true,
623
- enable_if_t<is_constructible_v<SliceVector<double>,TA>,bool> = true>
624
- INLINE T & Assign (const Expr<ScaleExpr<TA,double>> & scaled)
625
- {
626
- AddVector (scaled.View().S(),
627
- make_SliceVector(scaled.View().A()),
628
- make_SliceVector(this->Spec()));
629
- return Spec();
630
- }
631
-
632
-
633
- // x += s*(m*y)
634
- template <typename OP, typename TA, typename TB,
635
- enable_if_t<std::is_same_v<OP,AsAdd>,bool> = true,
636
- enable_if_t<IsConvertibleToSliceMatrix<TA,double>(),bool> = true,
637
- enable_if_t<is_convertible_v<TB,FlatVector<double>>,bool> = true,
638
- enable_if_t<is_convertible<typename pair<T,TB>::first_type,FlatVector<double>>::value,bool> = true>
639
- INLINE T & Assign (const Expr<ScaleExpr<MultExpr<TA, TB>,double>> & prod)
640
- {
641
- MultAddMatVec (prod.Spec().S(),
642
- make_SliceMatrix(prod.Spec().A().A()),
643
- prod.Spec().A().B(),
644
- Spec());
645
- return Spec();
646
- }
647
-
648
- // x += (s*m)*y
649
- template <typename OP, typename TA, typename TB,
650
- typename enable_if<std::is_same<OP,AsAdd>::value,int>::type = 0,
651
- typename enable_if<IsConvertibleToSliceMatrix<TA,double>(),int>::type = 0,
652
- typename enable_if<is_convertible<TB,FlatVector<double>>::value,int>::type = 0,
653
- typename enable_if<is_convertible<typename pair<T,TB>::first_type,FlatVector<double>>::value,int>::type = 0>
654
- INLINE T & Assign (const Expr<MultExpr<ScaleExpr<TA,double>, TB>> & prod)
655
- {
656
- MultAddMatVec (prod.Spec().A().S(),
657
- make_SliceMatrix(prod.Spec().A().A()),
658
- prod.Spec().B(),
659
- Spec());
660
- return Spec();
661
- }
662
- */
663
-
664
-
665
- template<typename TB>
666
- INLINE T & operator= (const Expr<TB> & v)
667
- {
668
- Assign<As> (v);
669
- return Spec();
670
- }
671
-
672
- INLINE T & operator= (const T & v)
673
- {
674
- Assign<As> (v);
675
- return Spec();
676
- }
677
-
678
- template<typename TB>
679
- INLINE T & operator+= (const Expr<TB> & v)
680
- {
681
- Assign<AsAdd> (v);
682
- return Spec();
683
- }
684
-
685
- template<typename TB>
686
- INLINE MatExpr<T> & operator-= (const Expr<TB> & v)
687
- {
688
- Assign<AsSub> (v);
689
- return Spec();
690
- }
691
-
692
-
693
-
694
-
695
- template<typename TB>
696
- INLINE T & operator+= (const Expr<SymExpr<TB> > & v)
697
- {
698
- NETGEN_CHECK_RANGE(Height(), v.Height(), v.Height()+1);
699
- NETGEN_CHECK_RANGE(Width(), v.Width(), v.Width()+1);
700
- size_t h = Height();
701
- for (size_t i = 0; i < h; i++)
702
- {
703
- for (size_t j = 0; j < i; j++)
704
- {
705
- double val = v.Spec()(i,j);
706
- Spec()(i,j) += val;
707
- Spec()(j,i) += val;
708
- }
709
- Spec()(i,i) += v.Spec()(i,i);
710
- }
711
- return Spec();
712
- }
713
-
714
-
715
-
716
- template <class SCAL2>
717
- INLINE T & operator*= (SCAL2 s)
718
- {
719
- if (T::IsLinear())
720
- {
721
- size_t hw = Height() * Width();
722
- for (size_t i = 0; i < hw; i++)
723
- Spec()(i) *= s;
724
- }
725
- else
726
- for (size_t i = 0; i < Height(); i++)
727
- for (size_t j = 0; j < Width(); j++)
728
- Spec()(i,j) *= s;
729
-
730
- return Spec();
731
- }
732
-
733
- template <class SCAL2>
734
- INLINE T & operator/= (SCAL2 s)
735
- {
736
- return (*this) *= (1./s);
737
- }
738
- };
739
-
740
-
741
-
742
-
743
-
744
-
745
-
746
- /* *************************** SumExpr **************************** */
747
-
748
- /**
749
- Sum of 2 matrix expressions
750
- */
751
-
752
- template <class TA, class TB>
753
- class SumExpr : public Expr<SumExpr<TA,TB> >
754
- {
755
- TA a;
756
- TB b;
757
- public:
758
-
759
- static constexpr bool IsLinear() { return TA::IsLinear() && TB::IsLinear(); }
760
-
761
- INLINE SumExpr (TA aa, TB ab) : a(aa), b(ab) { ; }
762
-
763
- template <typename ...I>
764
- INLINE auto operator() (I... i) const { return a(i...)+b(i...); }
765
-
766
- INLINE auto Height() const { return CombinedSize(a.Height(), b.Height()); }
767
- INLINE auto Width() const { return CombinedSize(a.Width(), b.Width()); }
768
-
769
- INLINE auto View() const { return SumExpr(a,b); }
770
- INLINE auto Shape() const { return CombinedSize(a.Shape(), b.Shape()); }
771
-
772
- void Dump (ostream & ost) const
773
- { ost << "("; a.Dump(ost); ost << ") + ("; b.Dump(ost); ost << ")"; }
774
- };
775
-
776
- template <typename TA, typename TB>
777
- INLINE auto
778
- operator+ (const Expr<TA> & a, const Expr<TB> & b)
779
- {
780
- NETGEN_CHECK_SHAPE(a, b);
781
- return SumExpr(a.View(), b.View());
782
- }
783
-
784
-
785
-
786
-
787
- /* *************************** SubExpr **************************** */
788
-
789
-
790
- /**
791
- Matrix-expr minus Matrix-expr
792
- */
793
-
794
- template <class TA, class TB>
795
- class SubExpr : public Expr<SubExpr<TA,TB> >
796
- {
797
- TA a;
798
- TB b;
799
- public:
800
-
801
- static constexpr bool IsLinear() { return TA::IsLinear() && TB::IsLinear(); }
802
-
803
- INLINE SubExpr (TA aa, TB ab) : a(aa), b(ab) { ; }
804
-
805
- template <typename ...I>
806
- INLINE auto operator() (I... i) const { return a(i...)-b(i...); }
807
-
808
- INLINE auto View() const { return SubExpr(a,b); }
809
- INLINE auto Shape() const { return CombinedSize(a.Shape(), b.Shape()); }
810
-
811
- INLINE auto Height() const { return CombinedSize(a.Height(), b.Height()); }
812
- INLINE auto Width() const { return CombinedSize(a.Width(), b.Width()); }
813
- };
814
-
815
-
816
- template <typename TA, typename TB>
817
- inline auto operator- (const Expr<TA> & a, const Expr<TB> & b)
818
- {
819
- NETGEN_CHECK_SHAPE(a, b);
820
- return SubExpr(a.View(), b.View());
821
- }
822
-
823
-
824
-
825
-
826
-
827
-
828
-
829
- /* *************************** MinusExpr **************************** */
830
-
831
-
832
- /**
833
- minus Matrix-expr
834
- */
835
-
836
- template <class TA>
837
- class MinusExpr : public Expr<MinusExpr<TA> >
838
- {
839
- TA a;
840
- public:
841
- MinusExpr (TA aa) : a(aa) { ; }
842
-
843
- template <typename ...I>
844
- INLINE auto operator() (I... i) const { return -a(i...); }
845
-
846
- INLINE auto View() const { return MinusExpr(a); }
847
- INLINE auto Shape() const { return a.Shape(); }
848
-
849
- INLINE auto Height() const { return a.Height(); }
850
- INLINE auto Width() const { return a.Width(); }
851
- INLINE TA A() const { return a; }
852
-
853
- static constexpr bool IsLinear() { return TA::IsLinear(); }
854
- };
855
-
856
- template <typename TA>
857
- INLINE auto operator- (const Expr<TA> & a)
858
- {
859
- return MinusExpr (a.View());
860
- }
861
-
862
-
863
- /* *************************** PW_Mult_Expr **************************** */
864
-
865
- template <class TA, class TB>
866
- class PW_Mult_Expr : public Expr<PW_Mult_Expr<TA,TB> >
867
- {
868
- TA a;
869
- TB b;
870
- public:
871
- static constexpr bool IsLinear() { return TA::IsLinear() && TB::IsLinear(); }
872
-
873
- INLINE PW_Mult_Expr (TA aa, TB ab) : a(aa), b(ab) { ; }
874
-
875
- INLINE auto operator() (size_t i) const { return a(i)*b(i); }
876
- INLINE auto operator() (size_t i, size_t j) const { return a(i,j)*b(i,j); }
877
-
878
- INLINE auto Height() const { return a.Height(); }
879
- INLINE auto Width() const { return a.Width(); }
880
-
881
- INLINE auto View() const { return *this; }
882
- INLINE auto Shape() const { return CombinedSize(a.Shape(), b.Shape()); }
883
- void Dump (ostream & ost) const
884
- { ost << "("; a.Dump(ost); ost << ") + ("; b.Dump(ost); ost << ")"; }
885
- };
886
-
887
- template <typename TA, typename TB>
888
- INLINE auto pw_mult (const Expr<TA> & a, const Expr<TB> & b)
889
- {
890
- NETGEN_CHECK_SHAPE(a, b);
891
- return PW_Mult_Expr (a.View(), b.View());
892
- }
893
-
894
-
895
- /* *************************** PW_Inv_Expr **************************** */
896
-
897
- template <class TA>
898
- class PW_Inv_Expr : public Expr<PW_Inv_Expr<TA> >
899
- {
900
- TA a;
901
- public:
902
- static constexpr bool IsLinear() { return TA::IsLinear(); }
903
- INLINE PW_Inv_Expr (TA aa) : a(aa) { ; }
904
-
905
- INLINE auto operator() (size_t i) const { return 1.0/a(i); }
906
- INLINE auto operator() (size_t i, size_t j) const { return 1.0/a(i,j); }
907
-
908
- INLINE size_t Height() const { return a.Height(); }
909
- INLINE size_t Width() const { return a.Width(); }
910
- INLINE auto View () const { return *this; }
911
- void Dump (ostream & ost) const
912
- { ost << "1/("; a.Dump(ost); ost << ")"; }
913
- };
914
-
915
- template <typename TA>
916
- INLINE auto pw_inv (const Expr<TA> & a)
917
- {
918
- return PW_Inv_Expr (a.View());
919
- }
920
-
921
-
922
-
923
- /* *************************** ScaleExpr **************************** */
924
-
925
-
926
- /**
927
- Scalar times Matrix-expr
928
- */
929
- template <class TA, class TS>
930
- class ScaleExpr : public Expr<ScaleExpr<TA,TS> >
931
- {
932
- TA a;
933
- TS s;
934
- public:
935
- static constexpr bool IsLinear() { return TA::IsLinear(); }
936
-
937
- INLINE ScaleExpr (TA aa, TS as) : a(aa), s(as) { ; }
938
-
939
- // INLINE auto operator() (size_t i) const { return s * a(i); }
940
- // INLINE auto operator() (size_t i, size_t j) const { return s * a(i,j); }
941
-
942
- template <typename ...I>
943
- INLINE auto operator() (I... i) const { return s*a(i...); }
944
-
945
- INLINE auto Height() const { return a.Height(); }
946
- INLINE auto Width() const { return a.Width(); }
947
-
948
- INLINE auto View() const { return *this; }
949
- INLINE auto Shape() const { return a.Shape(); }
950
-
951
- INLINE TA A() const { return a; }
952
- INLINE TS S() const { return s; }
953
-
954
- void Dump (ostream & ost) const
955
- { ost << "Scale, s=" << s << " * "; a.Dump(ost); }
956
- };
957
-
958
-
959
- template <typename TS, typename TA,
960
- typename enable_if<IsScalar<TS>(),int>::type = 0>
961
- INLINE auto operator* (TS s, const Expr<TA> & a)
962
- {
963
- return ScaleExpr (a.View(), s);
964
- }
965
-
966
-
967
-
968
- /* ************************* MultExpr ************************* */
969
-
970
-
971
- /**
972
- Matrix-expr timex Matrix-expr
973
- */
974
- template <class TA, class TB> class MultExpr : public Expr<MultExpr<TA,TB> >
975
- {
976
- TA a;
977
- TB b;
978
- public:
979
-
980
- INLINE MultExpr (TA aa, TB ab) : a(aa), b(ab) { ; }
981
-
982
- /*
983
- INLINE auto operator() (size_t i) const
984
- { return operator()(i,0); }
985
-
986
- INLINE auto operator() (size_t i, size_t j) const // -> decltype (a(0,0)*b(0,0))
987
- {
988
- size_t wa = a.Width();
989
-
990
- if (wa >= 1)
991
- {
992
- auto sum = a(i,0) * b(0,j);
993
- for (size_t k = 1; k < wa; k++)
994
- sum += a(i,k) * b(k,j);
995
- return sum;
996
- }
997
-
998
- decltype (a(0,0)*b(0,0)) sum (0);
999
- return sum;
1000
- }
1001
- */
1002
- template <typename ...J>
1003
- INLINE auto operator() (size_t i, J... j) const
1004
- {
1005
- size_t wa = a.Width();
1006
-
1007
- if (wa >= 1)
1008
- {
1009
- auto sum = a(i,SafeIndex(0)) * b(0,j...);
1010
- for (size_t k = 1; k < wa; k++)
1011
- sum += a(i,SafeIndex(k)) * b(k,j...);
1012
- return sum;
1013
- }
1014
-
1015
- decltype (a(0,0)*b(0,j...)) sum (0);
1016
- return sum;
1017
- }
1018
-
1019
- INLINE auto View() const { return MultExpr(a,b); }
1020
- INLINE auto Shape() const
1021
- {
1022
- if constexpr (tuple_size<decltype(b.Shape())>() == 1)
1023
- return tuple(get<0>(a.Shape()));
1024
- else
1025
- return tuple(get<0>(a.Shape()), get<1>(b.Shape()));
1026
- /*
1027
- // too complicated ?
1028
- return tuple_cat(tuple(get<0>(a.Shape())),
1029
- std::apply([](auto&&, const auto&... args) {return std::tie(args...);}, b.Shape()) );
1030
- */
1031
- }
1032
-
1033
- INLINE TA A() const { return a; }
1034
- INLINE TB B() const { return b; }
1035
- INLINE auto Height() const { return a.Height(); }
1036
- INLINE auto Width() const { return b.Width(); }
1037
- static constexpr bool IsLinear() { return false; }
1038
- };
1039
-
1040
-
1041
- template <int H, typename SCALA, class TB> class MultExpr<DiagMat<H,SCALA>,TB>
1042
- : public Expr<MultExpr<DiagMat<H,SCALA>,TB> >
1043
- {
1044
- DiagMat<H,SCALA> a;
1045
- TB b;
1046
- public:
1047
-
1048
- MultExpr (DiagMat<H,SCALA> aa, TB ab) : a(aa), b(ab) { ; }
1049
-
1050
- INLINE auto operator() (size_t i) const { return a[i] * b(i); }
1051
- INLINE auto operator() (size_t i, size_t j) const { return a[i] * b(i,j); }
1052
-
1053
- INLINE auto View() const { return *this; }
1054
- INLINE auto Shape() const
1055
- {
1056
- typedef decltype(b.Shape()) TBSHAPE;
1057
- if constexpr (tuple_size<TBSHAPE>() == 1)
1058
- return tuple<size_t> (H);
1059
- else
1060
- return tuple<size_t,size_t> (H, b.Width());
1061
- }
1062
-
1063
- INLINE const auto A() const { return a; }
1064
- INLINE const auto B() const { return b; }
1065
- INLINE auto Height() const { return a.Height(); }
1066
- INLINE auto Width() const { return b.Width(); }
1067
-
1068
- static constexpr bool IsLinear() { return false; }
1069
- };
1070
-
1071
-
1072
- template <typename TA, typename TB>
1073
- INLINE auto operator* (const Expr<TA> & a, const Expr<TB> & b)
1074
- {
1075
- return MultExpr (a.View(), b.View());
1076
- }
1077
-
1078
-
1079
- /* ************************** Trans *************************** */
1080
-
1081
- template <typename TA,
1082
- typename enable_if<IsScalar<TA>(),int>::type = 0>
1083
- INLINE auto Trans (TA a) { return a; }
1084
-
1085
-
1086
- /**
1087
- Transpose of Matrix-expr
1088
- */
1089
- template <class TA> class TransExpr : public MatExpr<TransExpr<TA> >
1090
- {
1091
- TA a;
1092
- public:
1093
- INLINE TransExpr (TA aa) : a(aa) { ; }
1094
-
1095
- INLINE auto Height() const { return a.Width(); }
1096
- INLINE auto Width() const { return a.Height(); }
1097
-
1098
- INLINE auto operator() (size_t i, size_t j) const { return Trans (a(j,i)); }
1099
- INLINE auto operator() (size_t i) const { return Trans(a(0,0)); }
1100
- // auto Row (int i) const -> decltype (a.Col(i)) { return a.Col(i); }
1101
- // auto Col (int i) const -> decltype (a.Row(i)) { return a.Row(i); }
1102
-
1103
- INLINE auto View() const { return *this; }
1104
- INLINE auto Shape() const { return tuple (a.Width(), a.Height()); }
1105
-
1106
- static constexpr bool IsLinear() { return false; }
1107
- INLINE const TA & A() const { return a; }
1108
- };
1109
-
1110
-
1111
- /// Transpose
1112
- template <typename TA>
1113
- INLINE auto Trans (const Expr<TA> & a)
1114
- {
1115
- return TransExpr (a.View());
1116
- }
1117
-
1118
- template <typename TA, typename TB>
1119
- INLINE auto Trans (const Expr<MultExpr<TA,TB>> & expr)
1120
- {
1121
- return Trans(expr.Spec().B()) * Trans(expr.Spec().A());
1122
- }
1123
-
1124
- template <typename TA>
1125
- INLINE auto Trans (const Expr<TransExpr<TA>> & expr)
1126
- {
1127
- return expr.Spec().A();
1128
- }
1129
-
1130
- /* ************************* Real/Imag ************************ */
1131
-
1132
- INLINE double Real(double a) { return a; }
1133
- INLINE double Imag(double a) { return 0; }
1134
-
1135
- INLINE double Real(Complex a) { return a.real(); }
1136
- INLINE double Imag(Complex a) { return a.imag(); }
1137
-
1138
- template <class TA>
1139
- class RealExpr : public Expr<RealExpr<TA> >
1140
- {
1141
- TA a;
1142
- public:
1143
- RealExpr (TA aa) : a(aa) { ; }
1144
-
1145
- INLINE auto operator() (size_t i) const { return Real(a(i)); }
1146
- INLINE auto operator() (size_t i, size_t j) const { return Real(a(i,j)); }
1147
- INLINE auto Height() const { return a.Height(); }
1148
- INLINE auto Width() const { return a.Width(); }
1149
- INLINE auto View() const { return *this; }
1150
- INLINE auto Shape() const { return a.Shape(); }
1151
- static constexpr bool IsLinear() { return TA::IsLinear(); }
1152
- };
1153
-
1154
- template <typename TA>
1155
- INLINE auto Real(const Expr<TA> & a)
1156
- {
1157
- return RealExpr(a.View());
1158
- }
1159
-
1160
-
1161
- template <class TA>
1162
- class ImagExpr : public Expr<ImagExpr<TA> >
1163
- {
1164
- TA a;
1165
- public:
1166
- ImagExpr (TA aa) : a(aa) { ; }
1167
-
1168
- INLINE auto operator() (size_t i) const { return Imag(a(i)); }
1169
- INLINE auto operator() (size_t i, size_t j) const { return Imag(a(i,j)); }
1170
- INLINE auto Height() const { return a.Height(); }
1171
- INLINE auto Width() const { return a.Width(); }
1172
- INLINE auto View() const { return *this; }
1173
- INLINE auto Shape() const { return a.Shape(); }
1174
- static constexpr bool IsLinear() { return TA::IsLinear(); }
1175
- };
1176
-
1177
- template <typename TA>
1178
- INLINE auto Imag(const Expr<TA> & a)
1179
- {
1180
- return ImagExpr (a.View());
1181
- }
1182
-
1183
-
1184
-
1185
- /* ************************* SubMatrix ************************ */
1186
-
1187
- template <class TA>
1188
- class SubMatrixExpr : public MatExpr<SubMatrixExpr<TA> >
1189
- {
1190
- TA a;
1191
- size_t first_row, first_col;
1192
- size_t height, width;
1193
- public:
1194
- SubMatrixExpr (TA aa, size_t fr, size_t fc, size_t ah, size_t aw)
1195
- : a(aa), first_row(fr), first_col(fc), height(ah), width(aw) { ; }
1196
-
1197
- INLINE size_t Height() const { return height; }
1198
- INLINE size_t Width() const { return width; }
1199
-
1200
- // auto operator() (size_t i, size_t j) { return a(i+first_row, j+first_col); }
1201
- // auto operator() (size_t i) { return a(i+first_row); }
1202
- INLINE decltype(auto) operator() (size_t i, int j) const { return a(i+first_row, j+first_col); }
1203
- INLINE decltype(auto) operator() (size_t i) const { return a(i+first_row); }
1204
-
1205
- typedef typename TA::TELEM TELEM;
1206
- typedef typename TA::TSCAL TSCAL;
1207
-
1208
- static constexpr bool IsLinear() { return false; }
1209
-
1210
- enum { COL_MAJOR = TA::COL_MAJOR };
1211
-
1212
- template<typename TB>
1213
- INLINE const SubMatrixExpr & operator= (const Expr<TB> & m)
1214
- {
1215
- MatExpr<SubMatrixExpr<TA> >::operator= (m);
1216
- return *this;
1217
- }
1218
-
1219
- INLINE auto View() const { return SubMatrixExpr(a, first_row, first_col, height, width); }
1220
- INLINE auto ViewRW() { return SubMatrixExpr(a, first_row, first_col, height, width); }
1221
- INLINE tuple<size_t,size_t> Shape() const { return { height, width }; }
1222
- };
1223
-
1224
-
1225
- template <class TA>
1226
- class RowExpr : public MatExpr<RowExpr<TA> >
1227
- {
1228
- TA a;
1229
- size_t row;
1230
- public:
1231
- RowExpr (TA aa, size_t r)
1232
- : a(aa), row(r) { ; }
1233
-
1234
- INLINE size_t Height() const { return 1; }
1235
- INLINE size_t Width() const { return a.Width(); }
1236
-
1237
- INLINE auto operator() (size_t i, size_t j) -> decltype(a(0,0)) { return a(row,i); }
1238
- INLINE auto operator() (size_t i) -> decltype(a(0,0)) { return a(row,i); }
1239
- INLINE auto operator() (size_t i, size_t j) const { return a(row,i); }
1240
- INLINE auto operator() (size_t i) const { return a(row,i); }
1241
-
1242
- static constexpr bool IsLinear() { return false; }
1243
-
1244
- template<typename TB>
1245
- INLINE const RowExpr & operator= (const Expr<TB> & m)
1246
- {
1247
- MatExpr<RowExpr<TA> >::operator= (m);
1248
- return *this;
1249
- }
1250
-
1251
- INLINE auto View() const { return *this; }
1252
- INLINE tuple<size_t> Shape() const { return a.Width(); }
1253
- };
1254
-
1255
-
1256
-
1257
- template <class TA>
1258
- class ColExpr : public MatExpr<ColExpr<TA> >
1259
- {
1260
- TA a;
1261
- size_t col;
1262
- public:
1263
- ColExpr (TA aa, size_t c)
1264
- : a(aa), col(c) { ; }
1265
-
1266
- INLINE size_t Height() const { return a.Height(); }
1267
- INLINE size_t Width() const { return 1; }
1268
-
1269
- INLINE auto operator() (size_t i, size_t j) -> decltype(a(0,0)) { return a(i,col); }
1270
- INLINE auto operator() (size_t i) -> decltype(a(0,0)) { return a(i,col); }
1271
- INLINE auto operator() (size_t i, size_t j) const { return a(i,col); }
1272
- INLINE auto operator() (size_t i) const { return a(i,col); }
1273
-
1274
- static constexpr bool IsLinear() { return false; }
1275
-
1276
- template<typename TB>
1277
- INLINE const ColExpr & operator= (const Expr<TB> & m)
1278
- {
1279
- MatExpr<ColExpr<TA> >::operator= (m);
1280
- return *this;
1281
- }
1282
-
1283
- INLINE auto View() const { return *this; }
1284
- INLINE tuple<size_t> Shape() const { return a.Height(); }
1285
- };
1286
-
1287
-
1288
-
1289
-
1290
-
1291
- /* ************************* RowsArray ************************ */
1292
-
1293
- /**
1294
- RowsArray
1295
- */
1296
- template <class TA> class RowsArrayExpr : public MatExpr<RowsArrayExpr<TA> >
1297
- {
1298
- const TA & a;
1299
- FlatArray<int> rows;
1300
- public:
1301
- typedef typename TA::TELEM TELEM;
1302
- typedef typename TA::TSCAL TSCAL;
1303
- static constexpr bool IsLinear() { return false; }
1304
-
1305
- INLINE RowsArrayExpr (const TA & aa, FlatArray<int> arows) : a(aa), rows(arows) { ; }
1306
-
1307
- INLINE auto Height() const { return rows.Size(); }
1308
- INLINE auto Width() const { return a.Width(); }
1309
-
1310
- INLINE auto operator() (size_t i, size_t j) const-> decltype(a(rows[i],j)) { return a(rows[i], j); }
1311
- INLINE auto operator() (size_t i) const-> decltype(a(rows[i])) { return a(rows[i]); }
1312
-
1313
- INLINE auto Row (size_t i) const { return a.Row(rows[i]); }
1314
- INLINE auto View() const { return RowsArrayExpr(a, rows); }
1315
- INLINE auto ViewRW() { return RowsArrayExpr(a, rows); }
1316
- INLINE auto Shape() const
1317
- {
1318
- typedef decltype(a.Shape()) TASHAPE;
1319
- if constexpr (tuple_size<TASHAPE>() == 1)
1320
- return tuple<size_t> (rows.Size());
1321
- else
1322
- return tuple<size_t,size_t> (rows.Size(), a.Width());
1323
- }
1324
-
1325
- template<typename TB>
1326
- INLINE const RowsArrayExpr & operator= (const Expr<TB> & m)
1327
- {
1328
- MatExpr<RowsArrayExpr<TA> >::operator= (m);
1329
- return *this;
1330
- }
1331
-
1332
- INLINE const RowsArrayExpr & operator= (const RowsArrayExpr & m)
1333
- {
1334
- MatExpr<RowsArrayExpr<TA> >::operator= (m);
1335
- return *this;
1336
- }
1337
- };
1338
-
1339
-
1340
- /**
1341
- ColsArray
1342
- */
1343
- template <class TA> class ColsArrayExpr : public MatExpr<ColsArrayExpr<TA> >
1344
- {
1345
- const TA & a;
1346
- FlatArray<int> cols;
1347
- public:
1348
- typedef typename TA::TELEM TELEM;
1349
- static constexpr bool IsLinear() { return false; }
1350
- typedef typename TA::TSCAL TSCAL;
1351
-
1352
- INLINE ColsArrayExpr (const TA & aa, FlatArray<int> acols) : a(aa), cols(acols) { ; }
1353
-
1354
- INLINE size_t Height() const { return a.Height(); }
1355
- INLINE size_t Width() const { return cols.Size(); }
1356
-
1357
- INLINE auto operator() (size_t i, size_t j) const -> decltype(a(i, cols[j])) { return a(i, cols[j]); }
1358
- INLINE auto operator() (size_t i) const -> decltype(a(i, cols[0])) { return a(i, cols[0]); }
1359
-
1360
- INLINE auto View() const { return *this; }
1361
- INLINE auto ViewRW() { return *this; }
1362
- INLINE tuple<size_t,size_t> Shape() const { return { a.Height(), cols.Size() }; }
1363
-
1364
- template<typename TB>
1365
- INLINE const ColsArrayExpr & operator= (const Expr<TB> & m)
1366
- {
1367
- MatExpr<ColsArrayExpr<TA> >::operator= (m);
1368
- return *this;
1369
- }
1370
-
1371
- };
1372
-
1373
-
1374
-
1375
-
1376
- /* ************************* Conjugate *********************** */
1377
-
1378
-
1379
- INLINE double Conj (double a)
1380
- {
1381
- return a;
1382
- }
1383
-
1384
- INLINE Complex Conj (Complex a)
1385
- {
1386
- return conj(a);
1387
- }
1388
-
1389
- /**
1390
- Conjugate of Matrix-expr
1391
- */
1392
- // Attention NOT transpose !!! elemwise conjugate !!!
1393
- template <class TA> class ConjExpr : public Expr<ConjExpr<TA> >
1394
- {
1395
- TA a;
1396
- public:
1397
- // typedef typename TA::TELEM TELEM;
1398
- // typedef typename TA::TSCAL TSCAL;
1399
-
1400
- INLINE ConjExpr (TA aa) : a(aa) { ; }
1401
-
1402
- INLINE auto Height() const { return a.Height(); }
1403
- INLINE auto Width() const { return a.Width(); }
1404
-
1405
- INLINE auto View() const { return *this; }
1406
- INLINE auto Shape() const { return a.Shape(); }
1407
-
1408
- INLINE auto operator() (size_t i, size_t j) const { return Conj(a(i,j)); }
1409
- INLINE auto operator() (size_t i) const { return Conj(a(i)); }
1410
-
1411
- static constexpr bool IsLinear() { return TA::IsLinear(); }
1412
- };
1413
-
1414
-
1415
- /// Conjugate
1416
- template <typename TA>
1417
- INLINE auto Conj (const Expr<TA> & a)
1418
- {
1419
- if constexpr (IsComplex<decltype(a.Spec()(0))>())
1420
- return ConjExpr (a.View());
1421
- else
1422
- return a.View();
1423
- }
1424
-
1425
-
1426
-
1427
- /* ************************* Truncate ************************* */
1428
-
1429
- INLINE double Truncate (double v, double eps = 1e-12)
1430
- {
1431
- return (fabs(v) < eps) ? 0 : v;
1432
- }
1433
-
1434
- INLINE Complex Truncate (Complex v, double eps = 1e-12)
1435
- {
1436
- return Complex(Truncate(Real(v), eps), Truncate(Imag(v),eps));
1437
- }
1438
-
1439
- template <class TA> class TruncateExpr : public Expr<TruncateExpr<TA> >
1440
- {
1441
- TA a;
1442
- double eps;
1443
- public:
1444
- INLINE TruncateExpr (TA aa, double aeps) : a(aa), eps(aeps) { ; }
1445
-
1446
- INLINE auto Height() const { return a.Height(); }
1447
- INLINE auto Width() const { return a.Width(); }
1448
-
1449
- INLINE auto operator() (size_t i, size_t j) const { return Truncate(a(i,j), eps); }
1450
- INLINE auto operator() (size_t i) const { return Truncate(a(i), eps); }
1451
- INLINE auto View() const { return *this; }
1452
-
1453
- static constexpr bool IsLinear() { return TA::IsLinear(); }
1454
- };
1455
-
1456
- /// Conjugate
1457
- template <typename TA>
1458
- INLINE TruncateExpr<TA>
1459
- Truncate (const Expr<TA> & a, double eps = 1e-12)
1460
- {
1461
- return TruncateExpr<TA> (a.View(), eps);
1462
- }
1463
-
1464
-
1465
- /* ************************* InnerProduct ********************** */
1466
-
1467
- template <typename TA, typename TB,
1468
- typename enable_if<IsScalar<TA>(),int>::type = 0,
1469
- typename enable_if<IsScalar<TB>(),int>::type = 0>
1470
- INLINE auto InnerProduct (TA a, TB b) { return a*b; }
1471
-
1472
-
1473
-
1474
-
1475
- /**
1476
- Inner product
1477
- */
1478
-
1479
- template <class TA, class TB>
1480
- INLINE auto InnerProduct (const Expr<TA> & a, const Expr<TB> & b)
1481
- -> decltype (InnerProduct(a.Spec()(0), b.Spec()(0)))
1482
- {
1483
- auto h = CombinedSize(a.Height(), b.Height());
1484
- auto w = CombinedSize(a.Width(), b.Width());
1485
-
1486
- if (h*w == 0) return 0;
1487
-
1488
- auto sum = InnerProduct (a.Spec()(0), b.Spec()(0));
1489
- for (size_t i = 1; i < h*w; i++)
1490
- sum += InnerProduct (a.Spec()(i), b.Spec()(i));
1491
- return sum;
1492
- }
1493
-
1494
-
1495
-
1496
-
1497
-
1498
-
1499
-
1500
- /* **************************** Trace **************************** */
1501
-
1502
-
1503
- /**
1504
- Calculates the trace of a matrix expression.
1505
- */
1506
- template <class TA>
1507
- INLINE auto Trace (const Expr<TA> & a) // -> decltype (a.Spec()(0,0))
1508
- {
1509
- typedef decltype( RemoveConst(a.Spec()(0,0)) ) TRES;
1510
- TRES sum = 0;
1511
- for (size_t i = 0; i < Height(a); i++)
1512
- sum += a.Spec()(i,i);
1513
- return sum;
1514
- }
1515
-
1516
- /* **************************** L2Norm **************************** */
1517
-
1518
- /// Euclidean norm squared
1519
- INLINE double L2Norm2 (double v)
1520
- {
1521
- return v*v;
1522
- }
1523
-
1524
- INLINE double L2Norm2 (Complex v)
1525
- {
1526
- return v.real()*v.real()+v.imag()*v.imag();
1527
- }
1528
-
1529
- template <class TA>
1530
- INLINE auto L2Norm2 (const Expr<TA> & v)
1531
- {
1532
- decltype(L2Norm2(v.Spec()(0))) sum = 0.0;
1533
- if (TA::IsLinear())
1534
- for (size_t i = 0; i < v.Height()*v.Width(); i++)
1535
- sum += L2Norm2 (v.Spec()(i));
1536
- else
1537
- for (size_t i = 0; i < v.Height(); i++)
1538
- for (size_t j = 0; j < v.Width(); j++)
1539
- sum += L2Norm2 (v.Spec()(i,j));
1540
-
1541
- return sum;
1542
- }
1543
-
1544
- /**
1545
- Calculates the Euclidean norm
1546
- */
1547
- template <class TA>
1548
- INLINE auto L2Norm (const Expr<TA> & v) // -> decltype(L2Norm2(v))
1549
- {
1550
- return sqrt (L2Norm2(v));
1551
- }
1552
-
1553
-
1554
-
1555
- /* **************************** MaxNorm **************************** */
1556
-
1557
- /// Euclidean norm squared
1558
- INLINE double MaxNorm (double v)
1559
- {
1560
- return fabs(v);
1561
- }
1562
-
1563
- INLINE double MaxNorm (Complex v)
1564
- {
1565
- return fabs(v);
1566
- }
1567
-
1568
-
1569
- template <class TA>
1570
- INLINE double MaxNorm (const Expr<TA> & v)
1571
- {
1572
- double sum = 0;
1573
-
1574
- if constexpr (TA::IsLinear())
1575
- for (size_t i = 0; i < v.Height()*v.Width(); i++)
1576
- sum = max(sum, MaxNorm( v.Spec()(i)) );
1577
- else
1578
- for (size_t i = 0; i < v.Height(); i++)
1579
- for (size_t j = 0; j < v.Width(); j++)
1580
- sum = max(sum, MaxNorm ( v.Spec()(i,j)) );
1581
-
1582
- return sum;
1583
- }
1584
-
1585
-
1586
- /* *************************** Output ****************************** */
1587
-
1588
-
1589
-
1590
- /// Print matrix-expr
1591
- template<typename T>
1592
- ostream & operator<< (ostream & s, const Expr<T> & v)
1593
- {
1594
- int width = s.width();
1595
- if (width == 0) width = 8;
1596
- s.width(0);
1597
- for (size_t i = 0; i < v.Height(); i++)
1598
- {
1599
- for (size_t j = 0 ; j < v.Width(); j++)
1600
- s << " " << setw(width-1) << v.Spec()(i,j);
1601
- s << endl;
1602
- }
1603
- return s;
1604
- }
1605
-
1606
-
1607
-
1608
-
1609
-
1610
- template <typename TA,
1611
- enable_if_t<IsScalar<TA>(),bool> = true>
1612
- INLINE auto Inv (TA val) { return 1.0/val; }
1613
-
1614
-
1615
-
1616
- /* ********************** Determinant *********************** */
1617
-
1618
-
1619
- /**
1620
- Calculates the determinant of a Matrix.
1621
- */
1622
-
1623
- template <class T>
1624
- inline typename T::TELEM Det (const MatExpr<T> & m)
1625
- {
1626
- const T & sm = m.Spec();
1627
- switch (sm.Height())
1628
- {
1629
- case 1:
1630
- {
1631
- return sm(0,0);
1632
- }
1633
- case 2:
1634
- {
1635
- return ( sm(0,0)*sm(1,1) - sm(0,1)*sm(1,0) );
1636
- }
1637
- case 3:
1638
- {
1639
- return
1640
- sm(0) * (sm(4) * sm(8) - sm(5) * sm(7)) +
1641
- sm(1) * (sm(5) * sm(6) - sm(3) * sm(8)) +
1642
- sm(2) * (sm(3) * sm(7) - sm(4) * sm(6));
1643
- }
1644
- default:
1645
- {
1646
- cerr << "general det not implemented" << endl;
1647
- }
1648
- }
1649
-
1650
- return typename T::TELEM (0);
1651
- }
1652
-
1653
- }
1654
-
1655
- #endif