ngsolve 6.2.2501.post47.dev1__cp313-cp313-macosx_10_15_universal2.whl → 6.2.2501.post48.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 (285) hide show
  1. netgen/include/arnoldi.hpp +55 -0
  2. netgen/include/bandmatrix.hpp +334 -0
  3. netgen/include/basematrix.hpp +957 -0
  4. netgen/include/basevector.hpp +1268 -0
  5. netgen/include/bdbequations.hpp +2752 -0
  6. netgen/include/bdbintegrator.hpp +1660 -0
  7. netgen/include/bessel.hpp +1064 -0
  8. netgen/include/bilinearform.hpp +963 -0
  9. netgen/include/bla.hpp +29 -0
  10. netgen/include/blockalloc.hpp +95 -0
  11. netgen/include/blockjacobi.hpp +316 -0
  12. netgen/include/bspline.hpp +114 -0
  13. netgen/include/calcinverse.hpp +141 -0
  14. netgen/include/cg.hpp +368 -0
  15. netgen/include/chebyshev.hpp +44 -0
  16. netgen/include/cholesky.hpp +720 -0
  17. netgen/include/clapack.h +7254 -0
  18. netgen/include/code_generation.hpp +296 -0
  19. netgen/include/coefficient.hpp +2033 -0
  20. netgen/include/coefficient_impl.hpp +19 -0
  21. netgen/include/coefficient_stdmath.hpp +167 -0
  22. netgen/include/commutingAMG.hpp +106 -0
  23. netgen/include/comp.hpp +79 -0
  24. netgen/include/compatibility.hpp +41 -0
  25. netgen/include/complex_wrapper.hpp +73 -0
  26. netgen/include/compressedfespace.hpp +110 -0
  27. netgen/include/contact.hpp +231 -0
  28. netgen/include/diagonalmatrix.hpp +154 -0
  29. netgen/include/differentialoperator.hpp +276 -0
  30. netgen/include/diffop.hpp +1286 -0
  31. netgen/include/diffop_impl.hpp +326 -0
  32. netgen/include/discontinuous.hpp +84 -0
  33. netgen/include/dump.hpp +949 -0
  34. netgen/include/eigen.hpp +60 -0
  35. netgen/include/eigensystem.hpp +18 -0
  36. netgen/include/elasticity_equations.hpp +595 -0
  37. netgen/include/elementbyelement.hpp +195 -0
  38. netgen/include/elementtopology.hpp +1760 -0
  39. netgen/include/elementtransformation.hpp +339 -0
  40. netgen/include/evalfunc.hpp +405 -0
  41. netgen/include/expr.hpp +1655 -0
  42. netgen/include/facetfe.hpp +175 -0
  43. netgen/include/facetfespace.hpp +178 -0
  44. netgen/include/facethofe.hpp +111 -0
  45. netgen/include/facetsurffespace.hpp +112 -0
  46. netgen/include/fe_interfaces.hpp +32 -0
  47. netgen/include/fem.hpp +87 -0
  48. netgen/include/fesconvert.hpp +14 -0
  49. netgen/include/fespace.hpp +1445 -0
  50. netgen/include/finiteelement.hpp +286 -0
  51. netgen/include/globalinterfacespace.hpp +77 -0
  52. netgen/include/globalspace.hpp +115 -0
  53. netgen/include/gridfunction.hpp +525 -0
  54. netgen/include/h1amg.hpp +41 -0
  55. netgen/include/h1hofe.hpp +188 -0
  56. netgen/include/h1hofe_impl.hpp +1262 -0
  57. netgen/include/h1hofefo.hpp +148 -0
  58. netgen/include/h1hofefo_impl.hpp +185 -0
  59. netgen/include/h1hofespace.hpp +167 -0
  60. netgen/include/h1lofe.hpp +1237 -0
  61. netgen/include/h1lumping.hpp +35 -0
  62. netgen/include/hcurl_equations.hpp +1352 -0
  63. netgen/include/hcurlcurlfe.hpp +2221 -0
  64. netgen/include/hcurlcurlfespace.hpp +78 -0
  65. netgen/include/hcurlfe.hpp +259 -0
  66. netgen/include/hcurlfe_utils.hpp +107 -0
  67. netgen/include/hcurlhdiv_dshape.hpp +857 -0
  68. netgen/include/hcurlhdivfes.hpp +308 -0
  69. netgen/include/hcurlhofe.hpp +175 -0
  70. netgen/include/hcurlhofe_impl.hpp +1871 -0
  71. netgen/include/hcurlhofespace.hpp +193 -0
  72. netgen/include/hcurllofe.hpp +1146 -0
  73. netgen/include/hdiv_equations.hpp +865 -0
  74. netgen/include/hdivdivfe.hpp +2923 -0
  75. netgen/include/hdivdivsurfacespace.hpp +76 -0
  76. netgen/include/hdivfe.hpp +206 -0
  77. netgen/include/hdivfe_utils.hpp +716 -0
  78. netgen/include/hdivfes.hpp +75 -0
  79. netgen/include/hdivhofe.hpp +447 -0
  80. netgen/include/hdivhofe_impl.hpp +1107 -0
  81. netgen/include/hdivhofefo.hpp +229 -0
  82. netgen/include/hdivhofespace.hpp +175 -0
  83. netgen/include/hdivhosurfacefespace.hpp +106 -0
  84. netgen/include/hdivlofe.hpp +773 -0
  85. netgen/include/hidden.hpp +74 -0
  86. netgen/include/householder.hpp +181 -0
  87. netgen/include/hypre_ams_precond.hpp +123 -0
  88. netgen/include/hypre_precond.hpp +73 -0
  89. netgen/include/integrator.hpp +2024 -0
  90. netgen/include/integratorcf.hpp +253 -0
  91. netgen/include/interpolate.hpp +49 -0
  92. netgen/include/intrule.hpp +2541 -0
  93. netgen/include/irspace.hpp +49 -0
  94. netgen/include/jacobi.hpp +136 -0
  95. netgen/include/l2hofe.hpp +193 -0
  96. netgen/include/l2hofe_impl.hpp +564 -0
  97. netgen/include/l2hofefo.hpp +542 -0
  98. netgen/include/l2hofespace.hpp +344 -0
  99. netgen/include/la.hpp +38 -0
  100. netgen/include/linearform.hpp +266 -0
  101. netgen/include/matrix.hpp +2140 -0
  102. netgen/include/memusage.hpp +41 -0
  103. netgen/include/meshaccess.hpp +1358 -0
  104. netgen/include/mgpre.hpp +204 -0
  105. netgen/include/mptools.hpp +2145 -0
  106. netgen/include/multigrid.hpp +42 -0
  107. netgen/include/multivector.hpp +447 -0
  108. netgen/include/mumpsinverse.hpp +187 -0
  109. netgen/include/mycomplex.hpp +361 -0
  110. netgen/include/ng_lapack.hpp +1661 -0
  111. netgen/include/ngblas.hpp +1099 -0
  112. netgen/include/ngs_defines.hpp +30 -0
  113. netgen/include/ngs_stdcpp_include.hpp +106 -0
  114. netgen/include/ngs_utils.hpp +121 -0
  115. netgen/include/ngsobject.hpp +1019 -0
  116. netgen/include/ngsstream.hpp +113 -0
  117. netgen/include/ngstd.hpp +72 -0
  118. netgen/include/nodalhofe.hpp +96 -0
  119. netgen/include/nodalhofe_impl.hpp +141 -0
  120. netgen/include/normalfacetfe.hpp +223 -0
  121. netgen/include/normalfacetfespace.hpp +98 -0
  122. netgen/include/normalfacetsurfacefespace.hpp +84 -0
  123. netgen/include/order.hpp +251 -0
  124. netgen/include/parallel_matrices.hpp +222 -0
  125. netgen/include/paralleldofs.hpp +340 -0
  126. netgen/include/parallelngs.hpp +23 -0
  127. netgen/include/parallelvector.hpp +269 -0
  128. netgen/include/pardisoinverse.hpp +200 -0
  129. netgen/include/periodic.hpp +125 -0
  130. netgen/include/plateaufespace.hpp +25 -0
  131. netgen/include/pml.hpp +275 -0
  132. netgen/include/pmltrafo.hpp +631 -0
  133. netgen/include/postproc.hpp +142 -0
  134. netgen/include/precomp.hpp +60 -0
  135. netgen/include/preconditioner.hpp +602 -0
  136. netgen/include/prolongation.hpp +235 -0
  137. netgen/include/python_comp.hpp +107 -0
  138. netgen/include/python_fem.hpp +89 -0
  139. netgen/include/python_linalg.hpp +58 -0
  140. netgen/include/python_ngstd.hpp +385 -0
  141. netgen/include/recursive_pol.hpp +4844 -0
  142. netgen/include/recursive_pol_tet.hpp +395 -0
  143. netgen/include/recursive_pol_trig.hpp +492 -0
  144. netgen/include/reorderedfespace.hpp +81 -0
  145. netgen/include/sample_sort.hpp +105 -0
  146. netgen/include/scalarfe.hpp +335 -0
  147. netgen/include/shapefunction_utils.hpp +113 -0
  148. netgen/include/simd_complex.hpp +284 -0
  149. netgen/include/smoother.hpp +253 -0
  150. netgen/include/solve.hpp +89 -0
  151. netgen/include/sparsecholesky.hpp +313 -0
  152. netgen/include/sparsematrix.hpp +1038 -0
  153. netgen/include/sparsematrix_dyn.hpp +91 -0
  154. netgen/include/sparsematrix_impl.hpp +920 -0
  155. netgen/include/special_matrix.hpp +461 -0
  156. netgen/include/specialelement.hpp +125 -0
  157. netgen/include/statushandler.hpp +33 -0
  158. netgen/include/stringops.hpp +12 -0
  159. netgen/include/superluinverse.hpp +136 -0
  160. netgen/include/symbolicintegrator.hpp +849 -0
  161. netgen/include/symmetricmatrix.hpp +144 -0
  162. netgen/include/tangentialfacetfe.hpp +224 -0
  163. netgen/include/tangentialfacetfespace.hpp +106 -0
  164. netgen/include/tensor.hpp +522 -0
  165. netgen/include/tensorcoefficient.hpp +446 -0
  166. netgen/include/tensorproductintegrator.hpp +113 -0
  167. netgen/include/thcurlfe.hpp +128 -0
  168. netgen/include/thcurlfe_impl.hpp +380 -0
  169. netgen/include/thdivfe.hpp +80 -0
  170. netgen/include/thdivfe_impl.hpp +426 -0
  171. netgen/include/tpdiffop.hpp +461 -0
  172. netgen/include/tpfes.hpp +133 -0
  173. netgen/include/tpintrule.hpp +224 -0
  174. netgen/include/triangular.hpp +465 -0
  175. netgen/include/tscalarfe.hpp +245 -0
  176. netgen/include/tscalarfe_impl.hpp +1029 -0
  177. netgen/include/umfpackinverse.hpp +148 -0
  178. netgen/include/vector.hpp +1219 -0
  179. netgen/include/voxelcoefficientfunction.hpp +41 -0
  180. netgen/include/vtkoutput.hpp +198 -0
  181. netgen/include/vvector.hpp +208 -0
  182. netgen/include/webgui.hpp +92 -0
  183. netgen/libngbla.dylib +0 -0
  184. netgen/libngcomp.dylib +0 -0
  185. netgen/libngfem.dylib +0 -0
  186. netgen/libngla.dylib +0 -0
  187. netgen/libngsolve.dylib +0 -0
  188. netgen/libngstd.dylib +0 -0
  189. ngsolve/__init__.pyi +231 -0
  190. ngsolve/bla.pyi +1139 -0
  191. ngsolve/bvp.pyi +32 -0
  192. ngsolve/cmake/NGSolveConfig.cmake +102 -0
  193. ngsolve/cmake/ngsolve-targets-release.cmake +69 -0
  194. ngsolve/cmake/ngsolve-targets.cmake +163 -0
  195. ngsolve/comp/__init__.pyi +5382 -0
  196. ngsolve/comp/pml.pyi +89 -0
  197. ngsolve/config/__init__.py +1 -0
  198. ngsolve/config/__init__.pyi +43 -0
  199. ngsolve/config/__main__.py +4 -0
  200. ngsolve/config/config.py +60 -0
  201. ngsolve/config/config.pyi +45 -0
  202. ngsolve/demos/TensorProduct/__init__.py +0 -0
  203. ngsolve/demos/TensorProduct/tp_dg_1d_1d.py +80 -0
  204. ngsolve/demos/TensorProduct/tp_dg_1d_2d.py +73 -0
  205. ngsolve/demos/TensorProduct/tp_dg_2d_1d.py +72 -0
  206. ngsolve/demos/TensorProduct/tp_dg_2d_2d.py +66 -0
  207. ngsolve/demos/__init__.py +0 -0
  208. ngsolve/demos/howto/__init__.py +0 -0
  209. ngsolve/demos/howto/hhj.py +44 -0
  210. ngsolve/demos/howto/hybrid_dg.py +53 -0
  211. ngsolve/demos/howto/mixed.py +30 -0
  212. ngsolve/demos/howto/nonlin.py +29 -0
  213. ngsolve/demos/howto/pickling.py +26 -0
  214. ngsolve/demos/howto/pml.py +31 -0
  215. ngsolve/demos/howto/taskmanager.py +20 -0
  216. ngsolve/demos/howto/tdnns.py +47 -0
  217. ngsolve/demos/howto/timeDG-skeleton.py +45 -0
  218. ngsolve/demos/howto/timeDG.py +38 -0
  219. ngsolve/demos/howto/timeDGlap.py +42 -0
  220. ngsolve/demos/howto/timeDGwave.py +61 -0
  221. ngsolve/demos/intro/__init__.py +0 -0
  222. ngsolve/demos/intro/adaptive.py +123 -0
  223. ngsolve/demos/intro/cmagnet.py +62 -0
  224. ngsolve/demos/intro/elasticity.py +76 -0
  225. ngsolve/demos/intro/navierstokes.py +74 -0
  226. ngsolve/demos/intro/poisson.ipynb +170 -0
  227. ngsolve/demos/intro/poisson.py +41 -0
  228. ngsolve/demos/mpi/__init__.py +0 -0
  229. ngsolve/demos/mpi/mpi_cmagnet.py +87 -0
  230. ngsolve/demos/mpi/mpi_navierstokes.py +117 -0
  231. ngsolve/demos/mpi/mpi_poisson.py +89 -0
  232. ngsolve/demos/mpi/mpi_timeDG.py +82 -0
  233. ngsolve/directsolvers.pyi +18 -0
  234. ngsolve/eigenvalues.pyi +30 -0
  235. ngsolve/fem.pyi +1707 -0
  236. ngsolve/krylovspace.pyi +309 -0
  237. ngsolve/la.pyi +1218 -0
  238. ngsolve/ngslib.so +0 -0
  239. ngsolve/ngstd.pyi +58 -0
  240. ngsolve/nonlinearsolvers.pyi +98 -0
  241. ngsolve/preconditioners.pyi +6 -0
  242. ngsolve/solve.pyi +108 -0
  243. ngsolve/solvers.pyi +14 -0
  244. ngsolve/timestepping.pyi +34 -0
  245. ngsolve/timing.pyi +57 -0
  246. ngsolve/utils.pyi +279 -0
  247. ngsolve-6.2.2501.post48.dev1.data/data/Netgen.icns +0 -0
  248. ngsolve-6.2.2501.post48.dev1.data/data/bin/ngscxx +17 -0
  249. ngsolve-6.2.2501.post48.dev1.data/data/bin/ngsld +13 -0
  250. ngsolve-6.2.2501.post48.dev1.data/data/bin/ngsolve.tcl +648 -0
  251. ngsolve-6.2.2501.post48.dev1.data/data/bin/ngspy +2 -0
  252. ngsolve-6.2.2501.post48.dev1.data/data/share/ngsolve/beam.geo +17 -0
  253. ngsolve-6.2.2501.post48.dev1.data/data/share/ngsolve/beam.vol +240 -0
  254. ngsolve-6.2.2501.post48.dev1.data/data/share/ngsolve/chip.in2d +41 -0
  255. ngsolve-6.2.2501.post48.dev1.data/data/share/ngsolve/chip.vol +614 -0
  256. ngsolve-6.2.2501.post48.dev1.data/data/share/ngsolve/coil.geo +12 -0
  257. ngsolve-6.2.2501.post48.dev1.data/data/share/ngsolve/coil.vol +2560 -0
  258. ngsolve-6.2.2501.post48.dev1.data/data/share/ngsolve/coilshield.geo +24 -0
  259. ngsolve-6.2.2501.post48.dev1.data/data/share/ngsolve/coilshield.vol +3179 -0
  260. ngsolve-6.2.2501.post48.dev1.data/data/share/ngsolve/cube.geo +19 -0
  261. ngsolve-6.2.2501.post48.dev1.data/data/share/ngsolve/cube.vol +1832 -0
  262. ngsolve-6.2.2501.post48.dev1.data/data/share/ngsolve/d10_DGdoubleglazing.pde +50 -0
  263. ngsolve-6.2.2501.post48.dev1.data/data/share/ngsolve/d11_chip_nitsche.pde +40 -0
  264. ngsolve-6.2.2501.post48.dev1.data/data/share/ngsolve/d1_square.pde +43 -0
  265. ngsolve-6.2.2501.post48.dev1.data/data/share/ngsolve/d2_chip.pde +35 -0
  266. ngsolve-6.2.2501.post48.dev1.data/data/share/ngsolve/d3_helmholtz.pde +22 -0
  267. ngsolve-6.2.2501.post48.dev1.data/data/share/ngsolve/d4_cube.pde +46 -0
  268. ngsolve-6.2.2501.post48.dev1.data/data/share/ngsolve/d5_beam.pde +74 -0
  269. ngsolve-6.2.2501.post48.dev1.data/data/share/ngsolve/d6_shaft.pde +73 -0
  270. ngsolve-6.2.2501.post48.dev1.data/data/share/ngsolve/d7_coil.pde +50 -0
  271. ngsolve-6.2.2501.post48.dev1.data/data/share/ngsolve/d8_coilshield.pde +49 -0
  272. ngsolve-6.2.2501.post48.dev1.data/data/share/ngsolve/d9_hybridDG.pde +72 -0
  273. ngsolve-6.2.2501.post48.dev1.data/data/share/ngsolve/doubleglazing.in2d +27 -0
  274. ngsolve-6.2.2501.post48.dev1.data/data/share/ngsolve/doubleglazing.vol +737 -0
  275. ngsolve-6.2.2501.post48.dev1.data/data/share/ngsolve/piezo2d40round4.vol.gz +0 -0
  276. ngsolve-6.2.2501.post48.dev1.data/data/share/ngsolve/shaft.geo +73 -0
  277. ngsolve-6.2.2501.post48.dev1.data/data/share/ngsolve/shaft.vol +4291 -0
  278. ngsolve-6.2.2501.post48.dev1.data/data/share/ngsolve/square.in2d +17 -0
  279. ngsolve-6.2.2501.post48.dev1.data/data/share/ngsolve/square.vol +149 -0
  280. {ngsolve-6.2.2501.post47.dev1.dist-info → ngsolve-6.2.2501.post48.dev1.dist-info}/METADATA +1 -1
  281. ngsolve-6.2.2501.post48.dev1.dist-info/RECORD +304 -0
  282. ngsolve-6.2.2501.post47.dev1.dist-info/RECORD +0 -25
  283. {ngsolve-6.2.2501.post47.dev1.dist-info → ngsolve-6.2.2501.post48.dev1.dist-info}/LICENSE +0 -0
  284. {ngsolve-6.2.2501.post47.dev1.dist-info → ngsolve-6.2.2501.post48.dev1.dist-info}/WHEEL +0 -0
  285. {ngsolve-6.2.2501.post47.dev1.dist-info → ngsolve-6.2.2501.post48.dev1.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,1219 @@
1
+ #ifndef FILE_VECTOR_EXPR
2
+ #define FILE_VECTOR_EXPR
3
+
4
+ /**************************************************************************/
5
+ /* File: vector.hpp */
6
+ /* Author: Joachim Schoeberl */
7
+ /* Date: 01. Jan. 02 */
8
+ /**************************************************************************/
9
+
10
+ #include "expr.hpp"
11
+ #include <core/hashtable.hpp> // for SparseVector
12
+
13
+ namespace ngbla
14
+ {
15
+
16
+ template <typename T=double, typename TS=size_t, typename TDIST=IC<1>> class VectorView;
17
+
18
+
19
+ template <typename T, typename ...Args>
20
+ INLINE void SetVector (typename mat_traits<T>::TSCAL val, VectorView<T,Args...> vec) NETGEN_NOEXCEPT
21
+ {
22
+ for (size_t i : Range(vec))
23
+ vec[i] = val;
24
+ }
25
+
26
+
27
+
28
+ template <typename T = double>
29
+ using FlatVector = VectorView<T,size_t,IC<1>>;
30
+
31
+ template <typename T, typename TELEM=typename T::TELEM>
32
+ constexpr bool IsConvertibleToFlatVector () {
33
+ return is_constructible_v<FlatVector<TELEM>,T>;
34
+ }
35
+
36
+ template <typename T, typename TELEM=typename T::TELEM>
37
+ auto make_FlatVector (const T & v) {
38
+ return FlatVector<TELEM> (v);
39
+ }
40
+
41
+
42
+
43
+ template <typename T = double>
44
+ using SliceVector = VectorView<T,size_t,size_t>;
45
+
46
+ template <typename T, typename TELEM=typename T::TELEM>
47
+ constexpr bool IsConvertibleToSliceVector () {
48
+ return is_constructible_v<SliceVector<TELEM>,T>;
49
+ }
50
+
51
+ template <typename T, typename TELEM=typename T::TELEM>
52
+ auto make_SliceVector (const T & v) {
53
+ return SliceVector<TELEM> (v);
54
+ }
55
+
56
+
57
+
58
+
59
+ template <typename T = double>
60
+ using BareSliceVector = VectorView<T,undefined_size,size_t>;
61
+
62
+ template <typename T, typename TELEM=typename T::TELEM>
63
+ constexpr bool IsConvertibleToBareSliceVector () {
64
+ return is_constructible_v<BareSliceVector<TELEM>,T>;
65
+ }
66
+
67
+ template <typename T, typename TELEM=typename T::TELEM>
68
+ auto make_BareSliceVector (const T & v) {
69
+ return BareSliceVector<TELEM> (v);
70
+ }
71
+
72
+
73
+
74
+ template <typename T = double>
75
+ using BareVector = VectorView<T,undefined_size,IC<1>>;
76
+
77
+ template <typename T, typename TELEM=typename T::TELEM>
78
+ constexpr bool IsConvertibleToBareVector () {
79
+ return is_constructible_v<BareVector<TELEM>,T>;
80
+ }
81
+
82
+ template <typename T, typename TELEM=typename T::TELEM>
83
+ auto make_BareVector (const T & v) {
84
+ return BareVector<TELEM> (v);
85
+ }
86
+
87
+
88
+ template <typename T, typename TS>
89
+ using LinearVector = VectorView<T,TS,IC<1>>;
90
+
91
+
92
+
93
+
94
+
95
+
96
+ template <int S, class T> class Vec;
97
+
98
+ template <int S, typename T = double>
99
+ using FlatVec = VectorView<T,IC<S>,IC<1>>;
100
+
101
+ template <int S, int D, typename T = double>
102
+ using FlatSliceVec = VectorView<T,IC<S>,IC<D>>;
103
+
104
+ template <int D, typename T = double>
105
+ using FixSliceVec = VectorView<T,size_t,IC<D>>;
106
+
107
+
108
+
109
+ template <class T> class SysVector;
110
+ template <class T = double> class Vector;
111
+ template <int DIST, typename T> class FixSliceVector;
112
+
113
+ #ifdef WIN32
114
+ // #pragma warning( disable : 4848) // support for standard attribute 'no_unique_address' in C++17 and earlier is a vendor extension
115
+ // #define NO_UNIQUE_ADDRESS [[msvc::no_unique_address]]
116
+
117
+ // Disable this optimization with MSVC because it creates inconsistent results with different versions.
118
+ // Following code returns 8 for compilers up to MSVC version 19.31, and returns 16 from version 19.32, see https://godbolt.org/z/v6P5vsq1M
119
+ #define NO_UNIQUE_ADDRESS
120
+ /*
121
+ struct Base{};
122
+ struct Empty {};
123
+
124
+ template <typename T, typename TS>
125
+ class Class : public Base{
126
+ T* data;
127
+ [[msvc::no_unique_address]] TS size;
128
+ };
129
+
130
+ int f() {
131
+ return sizeof(Class<void, Empty>);
132
+ }
133
+ */
134
+
135
+ #else
136
+ #define NO_UNIQUE_ADDRESS [[no_unique_address]]
137
+ #endif
138
+
139
+ template <typename T, typename TS, typename TDIST>
140
+ class VectorView : public MatExpr<VectorView<T,TS,TDIST>>
141
+ {
142
+ protected:
143
+ typedef MatExpr<VectorView> BASE;
144
+ T * __restrict data;
145
+ NO_UNIQUE_ADDRESS TS size;
146
+ NO_UNIQUE_ADDRESS TDIST dist;
147
+ public:
148
+ typedef T TELEM;
149
+ typedef typename mat_traits<T>::TSCAL TSCAL;
150
+ typedef TDIST type_dist;
151
+
152
+ /// linear element access ?
153
+ static constexpr bool IsLinear() { return std::is_same<type_dist,IC<1>>(); }
154
+
155
+ INLINE VectorView () = default;
156
+ INLINE VectorView (const VectorView&) = default;
157
+ INLINE VectorView (VectorView&&) = default;
158
+
159
+ template <typename T2, typename TS2, typename TDIST2,
160
+ enable_if_t<is_convertible<T2*,T*>::value, int> =0,
161
+ enable_if_t<is_constructible<TS,TS2>::value, int> =0,
162
+ enable_if_t<is_constructible<TDIST,TDIST2>::value, int> =0>
163
+ INLINE VectorView (const VectorView<T2,TS2,TDIST2> & v2)
164
+ : data{v2.Data()}, size{TS(v2.Size())}, dist{TDIST(v2.Dist())} { }
165
+
166
+ INLINE explicit VectorView (T * adata)
167
+ : data(adata)
168
+ {
169
+ ; // static_assert(std::is_same<type_dist,IC<1>>());
170
+ }
171
+ INLINE VectorView (TS asize, T * adata)
172
+ : data(adata), size(asize)
173
+ {
174
+ static_assert(std::is_same<type_dist,IC<1>>());
175
+ }
176
+ INLINE VectorView (TS asize, TDIST adist, T * adata)
177
+ : data(adata), size(asize), dist(adist) { }
178
+
179
+ /// allocate FlatVector on local heap
180
+ INLINE VectorView (size_t as, LocalHeap & lh)
181
+ : data(lh.Alloc<T> (as)), size(as), dist(IC<1>()) { }
182
+
183
+ template <typename EXPR>
184
+ INLINE VectorView(LocalHeapExpr<EXPR>&& lhe)
185
+ : VectorView(lhe.Height(), lhe.GetLocalHeap())
186
+ {
187
+ *this = lhe.A();
188
+ }
189
+
190
+ /// put FlatVector over fixed size vector
191
+
192
+ template <int S>
193
+ INLINE VectorView (Vec<S,T> & v)
194
+ : data(v.Data()), size(v.Size()), dist(IC<1>()) { }
195
+
196
+
197
+ /*
198
+ template <int S>
199
+ INLINE VectorView (Vec<S,T> & v)
200
+ : data(const_cast<T*>(v.Data())), size(v.Size()), dist(IC<1>()) { }
201
+ */
202
+ template <int S>
203
+ INLINE VectorView (const Vec<S,T> & v)
204
+ : data(const_cast<T*>(v.Data())), size(v.Size()), dist(IC<1>()) { }
205
+ /*
206
+ template <int S>
207
+ INLINE VectorView (Vec<S,const T> & v)
208
+ : data(const_cast<T*>(v.Data())), size(v.Size()), dist(IC<1>()) { }
209
+ template <int S>
210
+ INLINE VectorView (const Vec<S,const T> & v)
211
+ : data(const_cast<T*>(v.Data())), size(v.Size()), dist(IC<1>()) { }
212
+ */
213
+
214
+ INLINE auto Size() const { return size; }
215
+ INLINE auto Dist() const { return dist; }
216
+ INLINE auto Shape() const { return tuple(size); }
217
+
218
+
219
+ INLINE auto Height () const { return size; }
220
+ INLINE auto Width () const { return IC<1>(); }
221
+
222
+ INLINE auto Range () const { return IntRange (0, size); }
223
+
224
+ INLINE T * Addr(size_t i) const { return data+i*dist; }
225
+ INLINE T * Data() const { return data; }
226
+
227
+ INLINE auto View() const { return VectorView(*this); }
228
+ INLINE auto ViewRW() { return this->View(); }
229
+
230
+
231
+
232
+ /// assign memory for vector on local heap
233
+ INLINE void AssignMemory (size_t as, LocalHeap & lh)
234
+ {
235
+ size = as;
236
+ dist = IC<1>();
237
+ data = lh.Alloc<T>(size);
238
+ }
239
+
240
+ /// assign memory for vector
241
+ void AssignMemory (size_t as, T * mem)
242
+ {
243
+ size = as;
244
+ dist = IC<1>();
245
+ data = mem;
246
+ }
247
+
248
+ INLINE auto & operator= (const VectorView & v)
249
+ {
250
+ /*
251
+ auto cs = CombinedSize(this->Size(), v.Size());
252
+ for (size_t i = 0; i < cs; i++)
253
+ data[i*dist] = v(i);
254
+ */
255
+ this->template Assign<typename BASE::As> (v);
256
+ return *this;
257
+ }
258
+ INLINE auto & operator= (VectorView && v)
259
+ {
260
+ /*
261
+ auto cs = CombinedSize(this->Size(), v.Size());
262
+ for (size_t i = 0; i < cs; i++)
263
+ data[i*dist] = v(i);
264
+ */
265
+ this->template Assign<typename BASE::As> (v);
266
+ return *this;
267
+ }
268
+
269
+ /// copy vector. sizes must match
270
+ template <typename ...Args>
271
+ INLINE auto & operator= (const VectorView<Args...> & v)
272
+ {
273
+ // BASE::operator= (v);
274
+ this->template Assign<typename BASE::As> (v);
275
+ return *this;
276
+ }
277
+
278
+ template<typename TB>
279
+ INLINE auto & operator= (const Expr<TB> & v)
280
+ {
281
+ // BASE::operator= (v);
282
+ this->template Assign<typename BASE::As> (v);
283
+ return *this;
284
+ }
285
+
286
+ /// assign constant value
287
+ INLINE auto & operator= (TSCAL scal) const
288
+ {
289
+ SetVector (scal, *this);
290
+ return *this;
291
+ }
292
+
293
+ template <int D, typename TSCAL2>
294
+ INLINE auto & operator= (const Vec<D,TSCAL2> & v)
295
+ {
296
+ NETGEN_CHECK_RANGE(D,0,Size()+1);
297
+ for (int i = 0; i < D; i++)
298
+ data[i*dist] = v(i);
299
+ return *this;
300
+ }
301
+
302
+ /// access element
303
+ INLINE TELEM & operator[] (size_t i)
304
+ {
305
+ NETGEN_CHECK_RANGE(i,0,Size());
306
+ return data[i*dist];
307
+ }
308
+
309
+ INLINE const TELEM & operator[] (size_t i) const
310
+ {
311
+ NETGEN_CHECK_RANGE(i,0,Size());
312
+ return data[i*dist];
313
+ }
314
+
315
+
316
+ /// constant element access
317
+ // template<typename I, typename std::enable_if<std::is_integral<I>::value, int>::type = 0>
318
+ template<typename I, typename std::enable_if<std::is_convertible<I,size_t>::value, int>::type = 0>
319
+ INLINE TELEM & operator() (I i) const
320
+ {
321
+ NETGEN_CHECK_RANGE(i,0,Size());
322
+ return data[i*dist];
323
+ }
324
+
325
+ /// element access. index j is ignored
326
+ INLINE TELEM & operator() (size_t i, size_t j) const
327
+ {
328
+ NETGEN_CHECK_RANGE(i,0,Size());
329
+ return data[i*dist];
330
+ }
331
+
332
+ RowsArrayExpr<VectorView> operator() (FlatArray<int> rows) const
333
+ {
334
+ return RowsArrayExpr<VectorView> (*this, rows);
335
+ }
336
+
337
+ INLINE auto Range (size_t first, size_t next) const
338
+ {
339
+ NETGEN_CHECK_RANGE(next,first,Size()+1);
340
+ return VectorView<T,size_t,TDIST> (next-first, dist, data+first*dist);
341
+ }
342
+
343
+ INLINE auto Range (size_t next) const
344
+ {
345
+ return Range(0, next);
346
+ }
347
+
348
+ INLINE auto Range (IntRange range) const
349
+ {
350
+ return Range (range.First(), range.Next());
351
+ }
352
+
353
+ /*
354
+ template <int S>
355
+ INLINE auto Range (IC<S> r) const
356
+ {
357
+ return VectorView<T,IC<S>,TDIST> (r, Dist(), Data());
358
+ }
359
+ */
360
+
361
+ INLINE auto Slice(size_t first, size_t dist2) const
362
+ {
363
+ // return VectorView<T,decltype(declval<TS>()/size_t()), decltype(declval<TDIST>()*size_t())> (size/dist2, dist2*dist, Addr(first));
364
+ return VectorView<T,decltype(declval<TS>()/size_t()), decltype(declval<TDIST>()*size_t())> ( (size-first+dist2-1)/dist2, dist2*dist, Addr(first));
365
+ }
366
+
367
+ INLINE auto Reversed() const
368
+ {
369
+ // return VectorView { Size(), -Dist(), Addr(Size()-1) };
370
+ return VectorView<T,TS,decltype(-declval<TDIST>())> { Size(), -Dist(), Addr(Size()-1) };
371
+ }
372
+
373
+ INLINE auto operator+(int i) const { return VectorView(size-i, dist, data+i*dist); }
374
+
375
+ INLINE auto RemoveConst() const { return VectorView<typename remove_const<T>::type,TS,TDIST>(size, dist, const_cast<typename remove_const<T>::type*> (data)); }
376
+
377
+ INLINE auto AsMatrix (size_t h, size_t w) const
378
+ {
379
+ // todo: checking
380
+ static_assert(std::is_same<TDIST,IC<1>>());
381
+ return FlatMatrix<T> (h,w, data);
382
+ }
383
+
384
+ class Iterator
385
+ {
386
+ VectorView vec;
387
+ size_t ind;
388
+ public:
389
+ INLINE Iterator (VectorView avec, size_t ai) : vec(avec), ind(ai) { ; }
390
+ INLINE Iterator operator++ (int) { return Iterator(vec, ind++); }
391
+ INLINE Iterator operator++ () { return Iterator(vec, ++ind); }
392
+ INLINE TELEM operator*() const { return vec[ind]; }
393
+ INLINE TELEM & operator*() { return vec[ind]; }
394
+ INLINE bool operator != (Iterator d2) { return ind != d2.ind; }
395
+ INLINE bool operator == (Iterator d2) { return ind == d2.ind; }
396
+ };
397
+
398
+ INLINE Iterator begin() const { return Iterator (*this, 0); }
399
+ INLINE Iterator end() const { return Iterator (*this, size); }
400
+
401
+ };
402
+
403
+
404
+
405
+
406
+
407
+
408
+
409
+
410
+
411
+
412
+
413
+
414
+ /**
415
+ A Vector class with memory allocation/deallocation
416
+ */
417
+ template <typename T>
418
+ class Vector : public FlatVector<T>
419
+ {
420
+ // using FlatVector<T>::data;
421
+ // using FlatVector<T>::size;
422
+ public:
423
+ typedef typename mat_traits<T>::TSCAL TSCAL;
424
+
425
+ /// default constructor
426
+ Vector () : FlatVector<T> (0, (T*)nullptr) { ; }
427
+
428
+ /// allocate vector
429
+ explicit Vector (size_t as) : FlatVector<T> (as, new T[as]) { ; }
430
+
431
+
432
+ /// allocate and copy vector
433
+ Vector (const Vector & v2)
434
+ : FlatVector<T> (v2.Size(), new T[v2.Size()])
435
+ {
436
+ FlatVector<T>::operator= (v2);
437
+ }
438
+
439
+ Vector (Vector && v2)
440
+ : FlatVector<T> (v2.size, v2.data)
441
+ { v2.data = nullptr; v2.size = 0; }
442
+
443
+ /// allocate and compute
444
+ template<typename TB>
445
+ Vector (const Expr<TB> & v2)
446
+ : FlatVector<T> (v2.Height(), new T[v2.Height()])
447
+ {
448
+ FlatVector<T>::operator= (v2);
449
+ }
450
+
451
+
452
+ Vector (initializer_list<T> list)
453
+ : FlatVector<T> (list.size(), new T[list.size()])
454
+ {
455
+ size_t cnt = 0;
456
+ for (auto val : list)
457
+ (*this)[cnt++] = val;
458
+ }
459
+
460
+
461
+ /// deallocate vector
462
+ ~Vector() { delete [] this->data; }
463
+
464
+ /// set vector to constant values
465
+ Vector & operator= (TSCAL scal)
466
+ {
467
+ FlatVector<T>::operator= (scal);
468
+ return *this;
469
+ }
470
+
471
+ /// set vector size
472
+ void SetSize(size_t as)
473
+ {
474
+ if (this->size == as) return;
475
+ delete [] this->data;
476
+ this->size = as;
477
+ if (as != 0)
478
+ this->data = new T[this->size];
479
+ else
480
+ this->data = nullptr;
481
+ }
482
+
483
+ /// evaluate matrix expression
484
+ template<typename TB>
485
+ Vector & operator= (const Expr<TB> & v)
486
+ {
487
+ MatExpr<FlatVector<T> >::operator= (v);
488
+ return *this;
489
+ }
490
+
491
+ Vector & operator= (const Vector & v2)
492
+ {
493
+ FlatVector<T>::operator= (static_cast<FlatVector<T> >(v2));
494
+ // MatExpr<FlatVector<T> >::operator= (v2); // does not work, we don't know why
495
+ return *this;
496
+ }
497
+
498
+ Vector & operator= (Vector && v2)
499
+ {
500
+ this->size = v2.size;
501
+ Swap (this->data, v2.data);
502
+ return *this;
503
+ }
504
+
505
+ Vector & operator= (initializer_list<T> list)
506
+ {
507
+ SetSize (list.size());
508
+ size_t cnt = 0;
509
+ for (auto val : list)
510
+ (*this)[cnt++] = val;
511
+ return *this;
512
+ }
513
+
514
+ };
515
+
516
+
517
+
518
+
519
+ /**
520
+ A Vector class with memory allocation/deallocation. At
521
+ compile-time, a certain amount of vector entries is defined. If the
522
+ dynamic size fits into this memory, the vector is allocated in this memory.
523
+ Otherwise, dynamic memory is allocated.
524
+ */
525
+ template <int S, typename T = double>
526
+ class VectorMem : public FlatVector<T>
527
+ {
528
+ T mem[S];
529
+ public:
530
+ /// the scalar type
531
+ typedef typename mat_traits<T>::TSCAL TSCAL;
532
+
533
+ /** allocate vector.
534
+ If the dynamic size fits into the static size, use static memory. Otherwise use dynamic alloation
535
+ */
536
+ explicit INLINE VectorMem (size_t as) : FlatVector<T> (as, (as <= S) ?
537
+ &mem[0] : new T[as]) { ; }
538
+
539
+ /// deallocates dynamic memory
540
+ INLINE ~VectorMem() { if (this->Size() > S) delete [] this->data; }
541
+
542
+ /// assigns constant value
543
+ INLINE VectorMem & operator= (TSCAL scal)
544
+ {
545
+ FlatVector<T>::operator= (scal);
546
+ return *this;
547
+ }
548
+
549
+ /// evaluates matrix expression
550
+ template<typename TB>
551
+ INLINE VectorMem & operator= (const Expr<TB> & v)
552
+ {
553
+ MatExpr<FlatVector<T> >::operator= (v);
554
+ return *this;
555
+ }
556
+ };
557
+
558
+
559
+
560
+
561
+
562
+
563
+
564
+
565
+
566
+
567
+
568
+
569
+
570
+
571
+
572
+ // A system vector (not completely functional)
573
+ template <typename T = double>
574
+ class FlatSysVector : public MatExpr<FlatSysVector<T> >
575
+ {
576
+ protected:
577
+ size_t s;
578
+ size_t blocksize;
579
+ T * __restrict data;
580
+ public:
581
+ typedef FlatVector<T> TELEM;
582
+ typedef typename mat_traits<T>::TSCAL TSCAL;
583
+
584
+ INLINE FlatSysVector (size_t as, size_t bs, T * adata)
585
+ : s(as), blocksize(bs), data(adata) { ; }
586
+
587
+ INLINE FlatSysVector (size_t as, size_t bs, LocalHeap & lh)
588
+ : s(as), blocksize(bs), data (new (lh) T[as*bs])
589
+ { ; }
590
+
591
+ /*
592
+ FlatSysVector (const FlatSysVector<TSCAL> & sv)
593
+ : s(sv.Size()),
594
+ blocksize(sv.BlockSize()),
595
+ data (sv(0))
596
+ {
597
+ ;
598
+ }
599
+ */
600
+
601
+ INLINE FlatSysVector & operator= (const FlatSysVector & v)
602
+ {
603
+ for (size_t i = 0; i < this->s * this->blocksize; i++)
604
+ data[i] = v.data[i];
605
+ return *this;
606
+ }
607
+
608
+ template<typename TB>
609
+ INLINE FlatSysVector & operator= (const Expr<TB> & v)
610
+ {
611
+ return MatExpr<FlatSysVector>::operator= (v);
612
+ }
613
+
614
+ INLINE FlatSysVector & operator= (TSCAL s)
615
+ {
616
+ for (size_t i = 0; i < this->s*this->blocksize; i++)
617
+ data[i] = s;
618
+ return *this;
619
+ }
620
+
621
+
622
+
623
+ INLINE auto operator() (size_t i)
624
+ {
625
+ return FlatVector<T> (blocksize, &data[i*blocksize]);
626
+ }
627
+
628
+ INLINE auto operator() (size_t i) const
629
+ {
630
+ return FlatVector<T> (blocksize, &data[i*blocksize]);
631
+ }
632
+
633
+ INLINE const TELEM operator() (size_t i, size_t j) const
634
+ {
635
+ return FlatVector<T> (blocksize, &data[i*blocksize]);
636
+ }
637
+
638
+ INLINE SliceVector<T> Comp (size_t comp) const
639
+ {
640
+ return SliceVector<T> (s, blocksize, data+comp);
641
+ }
642
+
643
+ INLINE FlatSysVector<T> Range(size_t first, size_t last)
644
+ { return FlatSysVector<T> (last-first, blocksize, data+(first*blocksize)); }
645
+ INLINE /* const */ FlatSysVector<T> Range(size_t first, size_t last) const
646
+ { return FlatSysVector<T> (last-first, blocksize, data+(first*blocksize)); }
647
+
648
+ INLINE size_t Size () const { return s; }
649
+ INLINE size_t Height () const { return s; }
650
+ INLINE constexpr size_t Width () const { return 1; }
651
+ };
652
+
653
+
654
+
655
+ /**
656
+ A vector of fixed size.
657
+ Useful as entry type in system vectors.
658
+ */
659
+ template <int S, typename T = double>
660
+ class Vec : public MatExpr<Vec<S,T> > // , protected BaseVec
661
+ {
662
+ /// the values
663
+ // T data[S];
664
+ HTArray<S,T> data;
665
+ public:
666
+ /// type of the elements
667
+ typedef T TELEM;
668
+ /// is the element double or complex ?
669
+ typedef typename mat_traits<T>::TSCAL TSCAL;
670
+ static constexpr bool IsLinear() { return true; }
671
+
672
+
673
+ /// a vec is a S times 1 matrix, the according colume vector
674
+ typedef Vec<S, typename mat_traits<T>::TV_COL> TV_COL;
675
+ /// a vec is a S times 1 matrix, the according row vector
676
+ typedef Vec<1, typename mat_traits<T>::TV_ROW> TV_ROW;
677
+
678
+ enum { SIZE = S };
679
+ /// height of matrix
680
+ enum { HEIGHT = S };
681
+ /// with of matrix
682
+ enum { WIDTH = 1 };
683
+
684
+ /// constructor, no initialization
685
+ INLINE Vec () { ; }
686
+ /// copy vector
687
+ /*
688
+ INLINE Vec (const Vec & v) : MatExpr<Vec> ()
689
+ {
690
+ for (size_t i = 0; i < S; i++)
691
+ data[i] = v.data[i];
692
+ }
693
+ */
694
+
695
+ Vec (const Vec &) = default;
696
+ auto & HTData() const { return data; }
697
+ template <typename T2>
698
+ Vec (const Vec<S,T2> & v2) : data(v2.HTData()) { ; }
699
+
700
+
701
+ /// initialize with values
702
+ INLINE Vec (const TELEM & scal)
703
+ {
704
+ for (size_t i = 0; i < S; i++)
705
+ data[i] = scal;
706
+ }
707
+
708
+ /// initialize with expression
709
+ template<typename TB>
710
+ INLINE Vec (const Expr<TB> & v)
711
+ {
712
+ (*this) = v;
713
+ }
714
+
715
+ /*
716
+ template <int D>
717
+ INLINE Vec(FlatSliceVec<S,D,T> fsv)
718
+ {
719
+ for (int i = 0; i < S; i++)
720
+ data[i] = fsv(i);
721
+ }
722
+ */
723
+ template <typename T2, typename S2, typename D2>
724
+ INLINE Vec(VectorView<T2,S2,D2> fsv)
725
+ {
726
+ for (int i = 0; i < S; i++)
727
+ data[i] = fsv(i);
728
+ }
729
+
730
+
731
+ // Helper function for variadic constructor
732
+ template <int I, class... T2>
733
+ void Set(const TELEM &v, T2... rest)
734
+ {
735
+ data[I] = v;
736
+ Set<I+1>(rest...);
737
+ }
738
+
739
+ template <int I>
740
+ void Set(const TELEM &v)
741
+ {
742
+ data[I] = v;
743
+ }
744
+
745
+ template <class... T2,
746
+ enable_if_t<S==1+sizeof...(T2),bool> = true>
747
+ Vec(const TELEM &v, T2... rest) {
748
+ Set<0>(v, rest...);
749
+ }
750
+
751
+ /// copy vector
752
+ INLINE Vec & operator= (const Vec & v)
753
+ {
754
+ for (size_t i = 0; i < S; i++)
755
+ data[i] = v.data[i];
756
+ return *this;
757
+ }
758
+
759
+
760
+ /// assign scalar value
761
+ INLINE Vec & operator= (const TELEM & scal)
762
+ {
763
+ for (size_t i = 0; i < S; i++)
764
+ data[i] = scal;
765
+ return *this;
766
+ }
767
+
768
+ /// assign expression
769
+ template<typename TB>
770
+ INLINE Vec & operator= (const Expr<TB> & v)
771
+ {
772
+ for (size_t i = 0; i < S; i++)
773
+ data[i] = v.Spec()(i);
774
+ return *this;
775
+ }
776
+
777
+ // auto View() const { return FlatVec(const_cast<Vec&>(*this)); }
778
+ // auto View() const { return Vec(*this); }
779
+ INLINE auto View() const { return Vec<S,const T>{*this}; }
780
+ INLINE auto Shape() const { return tuple { IC<S>() }; }
781
+
782
+ /// access vector
783
+ INLINE TELEM & operator() (size_t i)
784
+ {
785
+ NETGEN_CHECK_RANGE(i,0,Size());
786
+ return data[i];
787
+ }
788
+
789
+ /// access vector
790
+ INLINE const TELEM & operator() (size_t i) const
791
+ {
792
+ NETGEN_CHECK_RANGE(i,0,Size());
793
+ return data[i];
794
+ }
795
+
796
+
797
+ /// access vector
798
+ INLINE TELEM & operator[] (size_t i)
799
+ {
800
+ NETGEN_CHECK_RANGE(i,0,Size());
801
+ return data[i];
802
+ }
803
+
804
+ /// access vector
805
+ INLINE const TELEM & operator[] (size_t i) const
806
+ {
807
+ NETGEN_CHECK_RANGE(i,0,Size());
808
+ return data[i];
809
+ }
810
+
811
+ /// access vector
812
+ INLINE TELEM & operator() (size_t i, size_t j)
813
+ {
814
+ NETGEN_CHECK_RANGE(i,0,Size());
815
+ return data[i];
816
+ }
817
+
818
+ /// access vector
819
+ INLINE const TELEM & operator() (size_t i, size_t j) const
820
+ {
821
+ NETGEN_CHECK_RANGE(i,0,Size());
822
+ return data[i];
823
+ }
824
+
825
+ /// vector size
826
+ INLINE auto Size () const { return IC<S>(); }
827
+ /// corresponding matrix height
828
+ INLINE constexpr size_t Height () const { return S; }
829
+ /// corresponding matrix with
830
+ INLINE constexpr size_t Width () const { return 1; }
831
+ INLINE T* Data() { return data.Ptr(); }
832
+ INLINE const T* Data() const { return data.Ptr(); }
833
+
834
+ INLINE /* const */ FlatVector<const T> Range(size_t first, size_t next) const
835
+ { return FlatVector<const T> (next-first, data+first); }
836
+
837
+ INLINE /* const */ FlatVector<T> Range(size_t first, size_t next)
838
+ { return FlatVector<T> (next-first, data+first); }
839
+
840
+ const T * begin() const { return data.Ptr(); }
841
+ const T * end() const { return data.Ptr()+S; }
842
+ T * begin() { return data.Ptr(); }
843
+ T * end() { return data.Ptr()+S; }
844
+ };
845
+
846
+
847
+
848
+ template <typename T>
849
+ class Vec<0,T> : public MatExpr<Vec<0,T> >
850
+ {
851
+ public:
852
+ static constexpr bool IsLinear() { return true; }
853
+ INLINE Vec () { }
854
+ INLINE Vec (const Vec &d) { }
855
+ INLINE Vec (T d) { }
856
+ template<typename TB>
857
+ INLINE Vec (const Expr<TB> & v) {;}
858
+ INLINE auto View() const { return Vec(*this); }
859
+ INLINE auto Shape() const { return tuple(IC<0>()); }
860
+ INLINE constexpr size_t Size() const { return 0; }
861
+ INLINE constexpr size_t Height() const { return 0; }
862
+ INLINE constexpr size_t Width() const { return 1; }
863
+ template<typename TB>
864
+ INLINE Vec & operator= (const Expr<TB> & v) { return *this;}
865
+ INLINE Vec & operator= (const T & /* scal */) { return *this; }
866
+
867
+ INLINE T & operator[] (int i) const { return *(T*)(void*)(this); }
868
+ INLINE T & operator() (int i) const { return *(T*)(void*)(this); }
869
+ INLINE T & operator() (int i, int j) const { return *(T*)(void*)(this); }
870
+ INLINE T* Data() { return nullptr; }
871
+ INLINE const T* Data() const { return nullptr; }
872
+ INLINE FlatVector<const T> Range(size_t first, size_t next) const
873
+ { return FlatVector<const T> (next-first, (T*)nullptr); }
874
+ INLINE FlatVector<T> Range(size_t first, size_t next)
875
+ { return FlatVector<T> (next-first, (T*)nullptr); }
876
+ };
877
+
878
+
879
+ template <int S, typename T>
880
+ class mat_traits<Vec<S,T>>
881
+ {
882
+ public:
883
+ /// matrix element
884
+ typedef T TELEM;
885
+ /// field of matrix element
886
+ typedef typename mat_traits<T>::TSCAL TSCAL;
887
+ /// type of column vector
888
+ typedef Vec<S, typename mat_traits<T>::TV_COL> TV_COL;
889
+ /// a vec is a S times 1 matrix, the according row vector
890
+ typedef Vec<1, typename mat_traits<T>::TV_ROW> TV_ROW;
891
+ /// matrix height
892
+ enum { HEIGHT = S };
893
+ /// matrix with
894
+ enum { WIDTH = 1 };
895
+ ///
896
+ // enum { IS_COMPLEX = mat_traits<TSCAL>::IS_COMPLEX };
897
+ };
898
+
899
+
900
+
901
+ template <typename T> struct ConstVecSize { static constexpr int VSIZE = -1; };
902
+ template <int S, typename T> struct ConstVecSize<Vec<S,T>> { static constexpr int VSIZE = S; };
903
+ template <int S, typename T> struct ConstVecSize<FlatVec<S,T>> { static constexpr int VSIZE = S; };
904
+ template <int S, int D, typename T> struct ConstVecSize<FlatSliceVec<S,D,T>> { static constexpr int VSIZE = S; };
905
+ template <typename T>
906
+ constexpr auto ConstVectorSize() { return ConstVecSize<T>::VSIZE; }
907
+
908
+ /// cross product of 3-vectors
909
+ template <typename TA, typename TB,
910
+ std::enable_if_t<ConstVecSize<TA>::VSIZE == 3, bool> = true,
911
+ std::enable_if_t<ConstVecSize<TB>::VSIZE == 3, bool> = true>
912
+ INLINE auto Cross (const TA & a, const TB & b)
913
+ {
914
+ typedef decltype (a(0)*b(0)) T;
915
+ return Vec<3,T>({ a(1)*b(2)-a(2)*b(1), a(2)*b(0)-a(0)*b(2), a(0)*b(1)-a(1)*b(0) });
916
+ }
917
+
918
+ template <typename S>
919
+ INLINE Vec<1,S> Cross (const Vec<2,S> & a, const Vec<2,S> & b)
920
+ {
921
+ return Vec<1,S> ( { a(0) * b(1) - a(1) * b(0) } );
922
+ }
923
+
924
+ template <typename S>
925
+ INLINE Vec<0,S> Cross (const Vec<1,S> & a, const Vec<1,S> & b)
926
+ {
927
+ return Vec<0,S>();
928
+ }
929
+
930
+ /// output vector
931
+ template<int S, typename T>
932
+ inline ostream & operator<< (ostream & ost, const Vec<S,T> & v)
933
+ {
934
+ for (int i = 0; i < S; i++)
935
+ ost << " " << setw(7) << v(i);
936
+ return ost;
937
+ }
938
+
939
+
940
+ template<int S, typename T, typename TB>
941
+ INLINE Vec<S,T> & operator+= (Vec<S,T> & v, const Expr<TB> & v2)
942
+ {
943
+ for (int i = 0; i < S; i++)
944
+ v(i) += v2.Spec()(i,0);
945
+ return v;
946
+ }
947
+
948
+ template<int S, typename T, typename TB>
949
+ INLINE Vec<S,T> & operator-= (Vec<S,T> & v, const Expr<TB> & v2)
950
+ {
951
+ for (int i = 0; i < S; i++)
952
+ v(i) -= v2.Spec()(i,0);
953
+ return v;
954
+ }
955
+
956
+
957
+
958
+
959
+
960
+
961
+
962
+ /// output vector.
963
+ template<int S, typename T>
964
+ inline ostream & operator<< (ostream & ost, const FlatVec<S,T> & v)
965
+ {
966
+ for (int i = 0; i < S; i++)
967
+ ost << " " << setw(7) << v(i);
968
+ return ost;
969
+ }
970
+
971
+
972
+
973
+
974
+
975
+ template <class TV, class TSCAL> class Scalar2ElemVector
976
+ {
977
+ public:
978
+ FlatVector<TSCAL> vec;
979
+ Scalar2ElemVector (FlatVector<TSCAL> avec) : vec(avec) { }
980
+
981
+ enum { H = mat_traits<TV>::HEIGHT };
982
+
983
+ FlatVec<H,TSCAL> operator() (int i) const
984
+ {
985
+ return FlatVec<H,TSCAL> (&vec(i*H));
986
+ }
987
+
988
+ };
989
+
990
+
991
+ template <class TSCAL> class Scalar2ElemVector<TSCAL,TSCAL>
992
+ {
993
+ public:
994
+ FlatVector<TSCAL> vec;
995
+ Scalar2ElemVector (FlatVector<TSCAL> avec) : vec(avec) { }
996
+
997
+
998
+ const TSCAL & operator() (int i) const
999
+ {
1000
+ return vec(i);
1001
+ }
1002
+
1003
+ TSCAL & operator() (int i)
1004
+ {
1005
+ return vec(i);
1006
+ }
1007
+
1008
+ };
1009
+
1010
+
1011
+ template <typename T=double>
1012
+ class SparseVector
1013
+ {
1014
+ size_t size;
1015
+ ClosedHashTable<size_t, T> data;
1016
+ public:
1017
+ SparseVector (size_t asize) : size(asize), data(10) { }
1018
+ size_t Size() const { return size; }
1019
+ T operator[] (size_t i) const { return data[i]; }
1020
+ T & operator[] (size_t i) { return data[i]; }
1021
+ T InnerProduct (FlatVector<T> v2) const
1022
+ {
1023
+ T sum = 0;
1024
+ for (auto [i,v] : data)
1025
+ sum += v * v2(i);
1026
+ return sum;
1027
+ }
1028
+ auto & Data() const { return data; }
1029
+ };
1030
+
1031
+ template <typename T>
1032
+ inline ostream & operator<< (ostream & ost, const SparseVector<T> & sv) {
1033
+ for (auto [i,v] : sv.Data())
1034
+ ost << i << ": " << v << ", ";
1035
+ return ost;
1036
+ }
1037
+
1038
+
1039
+ template <class T>
1040
+ class mat_traits<FlatVector<T> >
1041
+ {
1042
+ public:
1043
+ typedef T TELEM;
1044
+ typedef T TSCAL;
1045
+ };
1046
+
1047
+
1048
+ template <int S, typename T>
1049
+ INLINE auto operator* (double a, const Vec<S,T> & vec)
1050
+ {
1051
+ // typedef decltype(RemoveConst(a*vec(0))) TRES;
1052
+ typedef typename std::remove_const<decltype(a*std::declval<T>())>::type TRES;
1053
+ Vec<S, TRES> res;
1054
+ for (int i = 0; i < S; i++)
1055
+ res(i) = a * vec(i);
1056
+ return res;
1057
+ }
1058
+
1059
+ template <int S, typename T>
1060
+ INLINE auto operator* (int a, const Vec<S,T> & vec) { return double(a)*vec; }
1061
+
1062
+ template <int S, typename T>
1063
+ INLINE auto operator* (Complex a, const Vec<S,T> & vec)
1064
+ {
1065
+ // typedef decltype(RemoveConst(a*vec(0))) TRES;
1066
+ typedef typename std::remove_const<decltype(a*std::declval<T>())>::type TRES;
1067
+ Vec<S, TRES> res;
1068
+ for (int i = 0; i < S; i++)
1069
+ res(i) = a * vec(i);
1070
+ return res;
1071
+ }
1072
+
1073
+ // all other cases ...
1074
+ template <int S, typename T,
1075
+ typename enable_if<!is_convertible_v<T,Complex>,int>::type=0>
1076
+ INLINE auto operator* (T a, const Vec<S,T> & vec)
1077
+ {
1078
+ // typedef decltype(RemoveConst(a*vec(0))) TRES;
1079
+ typedef typename std::remove_const<decltype(a*std::declval<T>())>::type TRES;
1080
+ Vec<S, TRES> res;
1081
+ for (int i = 0; i < S; i++)
1082
+ res(i) = a * vec(i);
1083
+ return res;
1084
+ }
1085
+
1086
+ template <int S, typename T>
1087
+ INLINE auto operator+ (const Vec<S,T> & a, const Vec<S,T> & b)
1088
+ {
1089
+ // typedef decltype(RemoveConst(a(0))) TRES;
1090
+ typedef typename std::remove_const<T>::type TRES;
1091
+ Vec<S,TRES> res;
1092
+ for (int i = 0; i < S; i++)
1093
+ res(i) = a(i)+b(i);
1094
+ return res;
1095
+ }
1096
+
1097
+ template <int S, typename T>
1098
+ INLINE auto operator- (const Vec<S,T> & a, const Vec<S,T> & b)
1099
+ {
1100
+ // typedef decltype(RemoveConst(a(0))) TRES;
1101
+ typedef typename std::remove_const<T>::type TRES;
1102
+ Vec<S,TRES> res;
1103
+ for (int i = 0; i < S; i++)
1104
+ res(i) = a(i)-b(i);
1105
+ return res;
1106
+ }
1107
+
1108
+
1109
+ template <int S, typename T>
1110
+ INLINE auto operator* (double a, FlatVec<S,T> vec)
1111
+ // -> Vec<S, decltype(RemoveConst(a*vec(0)))>
1112
+ {
1113
+ // typedef decltype(RemoveConst(a*vec(0))) TRES;
1114
+ typedef typename std::remove_const<decltype(a*std::declval<T>())>::type TRES;
1115
+ Vec<S, TRES> res;
1116
+ for (int i = 0; i < S; i++)
1117
+ res(i) = a * vec(i);
1118
+ return res;
1119
+ }
1120
+
1121
+
1122
+ template <int S, typename T>
1123
+ INLINE auto operator* (Complex a, FlatVec<S,T> vec)
1124
+ // -> Vec<S, decltype(RemoveConst(a*vec(0)))>
1125
+ {
1126
+ // typedef decltype(RemoveConst(a*vec(0))) TRES;
1127
+ typedef typename std::remove_const<decltype(a*std::declval<T>())>::type TRES;
1128
+ Vec<S, TRES> res;
1129
+ for (int i = 0; i < S; i++)
1130
+ res(i) = a * vec(i);
1131
+ return res;
1132
+ }
1133
+
1134
+ template <int S, int D, typename T>
1135
+ INLINE auto operator* (double a, FlatSliceVec<S,D,T> vec)
1136
+ // -> Vec<S, decltype(RemoveConst(a*vec(0)))>
1137
+ {
1138
+ // typedef decltype(RemoveConst(a*vec(0))) TRES;
1139
+ typedef typename std::remove_const<decltype(a*std::declval<T>())>::type TRES;
1140
+ Vec<S, TRES> res;
1141
+ for (int i = 0; i < S; i++)
1142
+ res(i) = a * vec(i);
1143
+ return res;
1144
+ }
1145
+
1146
+
1147
+ template <int S, int D, typename T>
1148
+ INLINE auto operator* (Complex a, FlatSliceVec<S,D,T> vec)
1149
+ // -> Vec<S, decltype(RemoveConst(a*vec(0)))>
1150
+ {
1151
+ // typedef decltype(RemoveConst(a*vec(0))) TRES;
1152
+ typedef typename std::remove_const<decltype(a*std::declval<T>())>::type TRES;
1153
+ Vec<S, TRES> res;
1154
+ for (int i = 0; i < S; i++)
1155
+ res(i) = a * vec(i);
1156
+ return res;
1157
+ }
1158
+
1159
+
1160
+ template <int S, typename T>
1161
+ INLINE auto operator+ (FlatVec<S,T> x, FlatVec<S,T> y) -> Vec<S,T>
1162
+ {
1163
+ Vec<S,T> tmp = x;
1164
+ tmp += y;
1165
+ return tmp;
1166
+ }
1167
+
1168
+ template <int S, typename T>
1169
+ INLINE auto operator- (FlatVec<S,T> x, FlatVec<S,T> y) -> Vec<S,T>
1170
+ {
1171
+ Vec<S,T> tmp = x;
1172
+ tmp -= y;
1173
+ return tmp;
1174
+ }
1175
+
1176
+
1177
+
1178
+ template <int DIM, typename SCAL, typename TANY>
1179
+ inline void AtomicAdd (Vec<DIM,SCAL> & x, TANY y)
1180
+ {
1181
+ for (int i = 0; i < DIM; i++)
1182
+ AtomicAdd (x(i), y(i));
1183
+ }
1184
+
1185
+ template <int DIM, typename SCAL, typename TANY>
1186
+ inline void AtomicAdd (FlatVec<DIM,SCAL> x, TANY y)
1187
+ {
1188
+ for (int i = 0; i < DIM; i++)
1189
+ AtomicAdd (x(i), y(i));
1190
+ }
1191
+
1192
+
1193
+ }
1194
+
1195
+ namespace ngstd
1196
+ {
1197
+ template <typename ARCHIVE, int S, typename T>
1198
+ inline auto & operator& (ARCHIVE & ar, ngbla::Vec<S,T> & v)
1199
+ {
1200
+ for (int i = 0; i < S; i++)
1201
+ ar & v(i);
1202
+ return ar;
1203
+ }
1204
+ }
1205
+
1206
+
1207
+ namespace ngcore
1208
+ {
1209
+ template<typename T> struct MPI_typetrait;
1210
+
1211
+ template<int S, typename T>
1212
+ struct MPI_typetrait<ngbla::Vec<S, T> > {
1213
+ static auto MPIType () {
1214
+ return MPI_typetrait<std::array<T,S>>::MPIType();
1215
+ }
1216
+ };
1217
+ }
1218
+
1219
+ #endif