12#ifndef MFEM_LINALG_KERNELS_HPP
13#define MFEM_LINALG_KERNELS_HPP
43 for (
int i = 0; i <
dim; i++) { d += (x[i]-y[i])*(x[i]-y[i]); }
52 for (
int i = 0; i < N; i++) { data[i] = 0.0; }
53 for (
int i = 0; i <
dim; i++) { data[i*(
dim+1)] = c; }
62 for (
int i = 0; i <
dim; i++) { z[i] =
a * (x[i] - y[i]); }
70 for (
int i = 0; i <
dim; i++)
73 for (
int j = 0; j <
dim; j++) { VWt[i*
dim+j] += vi * w[j]; }
77template<
int H,
int W,
typename T>
78MFEM_HOST_DEVICE
inline
82 T max_norm = 0.0, entry, fnorm2;
84 for (i = 0; i < hw; i++)
86 entry = fabs(data[i]);
95 scale_factor = scaled_fnorm2 = 0.0;
100 for (i = 0; i < hw; i++)
102 entry = data[i] / max_norm;
103 fnorm2 += entry * entry;
106 scale_factor = max_norm;
107 scaled_fnorm2 = fnorm2;
111template<
int H,
int W,
typename T>
112MFEM_HOST_DEVICE
inline
121template<
int H,
int W,
typename T>
122MFEM_HOST_DEVICE
inline
132MFEM_HOST_DEVICE
inline
135 if (0 == size) {
return 0.0; }
136 if (1 == size) {
return std::abs(data[0]); }
139 for (
int i = 0; i < size; i++)
143 const T absdata = fabs(data[i]);
144 if (scale <= absdata)
146 const T sqr_arg = scale / absdata;
147 sum = 1.0 + sum * (sqr_arg * sqr_arg);
151 const T sqr_arg = absdata / scale;
152 sum += (sqr_arg * sqr_arg);
155 return scale * sqrt(sum);
161template<
typename TA,
typename TX,
typename TY>
162MFEM_HOST_DEVICE
inline
163void Mult(
const int height,
const int width,
const TA *data,
const TX *x, TY *y)
167 for (
int row = 0; row < height; row++)
173 const TA *d_col = data;
175 for (
int row = 0; row < height; row++)
177 y[row] = x_col*d_col[row];
180 for (
int col = 1; col < width; col++)
183 for (
int row = 0; row < height; row++)
185 y[row] += x_col*d_col[row];
194template<
typename TA,
typename TX,
typename TY>
195MFEM_HOST_DEVICE
inline
201 for (
int row = 0; row < width; row++)
208 for (
int i = 0; i < width; ++i)
211 for (
int j = 0; j < height; ++j)
213 val += x[j] * data[i * height + j];
222MFEM_HOST_DEVICE
inline
225 for (
int i = 0; i < size; i++)
227 for (
int j = 0; j < i; j++)
229 const T
a = 0.5 * (data[i*size+j] + data[j*size+i]);
230 data[j*size+i] = data[i*size+j] =
a;
236template<
int dim,
typename T>
237MFEM_HOST_DEVICE
inline T
Det(
const T *data)
244template<
int dim,
typename T>
245MFEM_HOST_DEVICE
inline
249 const T det =
TAdjDetHD<T>(layout_t(), data, layout_t(), inv_data);
254template<
int dim,
typename T>
255MFEM_HOST_DEVICE
inline
264template<
typename TALPHA,
typename TA,
typename TB,
typename TC>
265MFEM_HOST_DEVICE
inline
266void Add(
const int height,
const int width,
const TALPHA
alpha,
267 const TA *Adata,
const TB *Bdata, TC *Cdata)
269 for (
int j = 0; j < width; j++)
271 for (
int i = 0; i < height; i++)
273 const int n = i*width+j;
274 Cdata[n] = Adata[n] +
alpha * Bdata[n];
281template<
typename TALPHA,
typename TBETA,
typename TA,
typename TB,
typename TC>
282MFEM_HOST_DEVICE
inline
283void Add(
const int height,
const int width,
284 const TALPHA
alpha,
const TA *Adata,
285 const TBETA
beta,
const TB *Bdata,
288 const int m = height * width;
289 for (
int i = 0; i < m; i++)
291 Cdata[i] =
alpha * Adata[i] +
beta * Bdata[i];
297template<
typename TA,
typename TB>
298MFEM_HOST_DEVICE
inline
299void Add(
const int height,
const int width,
const TA *Adata, TB *Bdata)
301 const int m = height * width;
302 for (
int i = 0; i < m; i++)
304 Bdata[i] += Adata[i];
310template<
typename TA,
typename TB>
311MFEM_HOST_DEVICE
inline
312void Add(
const int height,
const int width,
315 const int m = height * width;
316 for (
int i = 0; i < m; i++)
318 Bdata[i] +=
alpha * Adata[i];
324template<
typename TA,
typename TB>
325MFEM_HOST_DEVICE
inline
326void Set(
const int height,
const int width,
329 const int m = height * width;
330 for (
int i = 0; i < m; i++)
332 Bdata[i] =
alpha * Adata[i];
339template<
typename TA,
typename TB,
typename TC>
340MFEM_HOST_DEVICE
inline
341void Mult(
const int Aheight,
const int Awidth,
const int Bwidth,
342 const TB *Bdata,
const TC *Cdata, TA *Adata)
344 const int ah_x_aw = Aheight * Awidth;
345 for (
int i = 0; i < ah_x_aw; i++) { Adata[i] = 0.0; }
346 for (
int j = 0; j < Awidth; j++)
348 for (
int k = 0; k < Bwidth; k++)
350 for (
int i = 0; i < Aheight; i++)
352 Adata[i+j*Aheight] += Bdata[i+k*Aheight] * Cdata[k+j*Bwidth];
361template<
typename TA,
typename TB,
typename TC>
362MFEM_HOST_DEVICE
inline
363void MultABt(
const int Aheight,
const int Awidth,
const int Bheight,
364 const TA *Adata,
const TB *Bdata, TC *ABtdata)
366 const int ah_x_bh = Aheight * Bheight;
367 for (
int i = 0; i < ah_x_bh; i++) { ABtdata[i] = 0.0; }
368 for (
int k = 0; k < Awidth; k++)
371 for (
int j = 0; j < Bheight; j++)
373 const real_t bjk = Bdata[j];
374 for (
int i = 0; i < Aheight; i++)
376 c[i] += Adata[i] * bjk;
388template<
typename TA,
typename TB,
typename TC>
389MFEM_HOST_DEVICE
inline
390void MultAtB(
const int Aheight,
const int Awidth,
const int Bwidth,
391 const TA *Adata,
const TB *Bdata, TC *AtBdata)
394 for (
int i = 0; i < Bwidth; ++i)
396 for (
int j = 0; j < Awidth; ++j)
399 for (
int k = 0; k < Aheight; ++k)
401 val += Adata[j * Aheight + k] * Bdata[i * Aheight + k];
410template<
int HEIGHT,
int WIDTH> MFEM_HOST_DEVICE
416template<
int dim> MFEM_HOST_DEVICE
420template<
int dim> MFEM_HOST_DEVICE
430MFEM_HOST_DEVICE
static inline
438const real_t Epsilon = std::numeric_limits<real_t>::epsilon();
441MFEM_HOST_DEVICE
static inline
444 const real_t sqrt_1_eps = sqrt(1./Epsilon);
449 const real_t zeta = (d2 - d1)/(2*d12);
450 if (fabs(zeta) < sqrt_1_eps)
452 t = d12*copysign(1./(fabs(zeta) + sqrt(1. + zeta*zeta)), zeta);
456 t = d12*copysign(0.5/fabs(zeta), zeta);
464MFEM_HOST_DEVICE
static inline
468 const real_t sqrt_1_eps = sqrt(1./Epsilon);
478 const real_t zeta = (d2 - d1)/(2*d12);
479 const real_t azeta = fabs(zeta);
480 if (azeta < sqrt_1_eps)
482 t = copysign(1./(azeta + sqrt(1. + zeta*zeta)), zeta);
486 t = copysign(0.5/azeta, zeta);
488 c = sqrt(1./(1. +
t*
t));
498MFEM_HOST_DEVICE
static inline
504 mult = frexp(d_max, &d_exp);
505 if (d_exp == std::numeric_limits<real_t>::max_exponent)
507 mult *= std::numeric_limits<real_t>::radix;
520MFEM_HOST_DEVICE
static inline
521bool KernelVector2G(
const int &mode,
533 real_t n1 = fabs(d1) + fabs(d21);
534 real_t n2 = fabs(d2) + fabs(d12);
536 bool swap_columns = (n2 > n1);
548 if (fabs(d1) > fabs(d21))
556 if (fabs(d1) < fabs(d21))
568 if (fabs(d12) > fabs(d2))
581 if (fabs(d12) < fabs(d2))
600 mu = copysign(n1, d1);
601 n1 = -d21*(d21/(d1 +
mu));
605 if (fabs(n1) <= fabs(d21))
609 mu = (2./(1. + n1*n1))*(n1*d12 + d2);
617 mu = (2./(1. + n2*n2))*(d12 + n2*d2);
639 n2 = 1./(1. + fabs(
mu));
641 if (fabs(d1) <= n2*fabs(d2))
662MFEM_HOST_DEVICE
static inline
663void Vec_normalize3_aux(
const real_t &x1,
const real_t &x2,
669 const real_t m = fabs(x1);
673 t = sqrt(1./(
t + r*r));
674 n1 = copysign(
t, x1);
681MFEM_HOST_DEVICE
static inline
686 if (fabs(x1) >= fabs(x2))
688 if (fabs(x1) >= fabs(x3))
692 Vec_normalize3_aux(x1, x2, x3, n1, n2, n3);
701 else if (fabs(x2) >= fabs(x3))
703 Vec_normalize3_aux(x2, x1, x3, n2, n1, n3);
706 Vec_normalize3_aux(x3, x1, x2, n3, n1, n2);
710MFEM_HOST_DEVICE
static inline
711int KernelVector3G_aux(
const int &mode,
719 s1 = hypot(c21, c31);
726 mu = copysign(n1, d1);
727 n1 = -s1*(s1/(d1 +
mu));
732 if (fabs(n1) >= fabs(c21))
734 if (fabs(n1) >= fabs(c31))
739 mu = 2./(1. + s2*s2 + s3*s3);
740 n2 =
mu*(c12 + s2*d2 + s3*c32);
741 n3 =
mu*(c13 + s2*c23 + s3*d3);
751 else if (fabs(c21) >= fabs(c31))
756 mu = 2./(1. + s1*s1 + s3*s3);
757 n2 =
mu*(s1*c12 + d2 + s3*c32);
758 n3 =
mu*(s1*c13 + c23 + s3*d3);
770 mu = 2./(1. + s1*s1 + s2*s2);
771 n2 =
mu*(s1*c12 + s2*d2 + c32);
772 n3 =
mu*(s1*c13 + s2*c23 + d3);
786 if (KernelVector2G(mode, d2, c23, c32, d3))
807 d1 = -(c12*d2 + c13*d3)/d1;
811 Vec_normalize3(d1, d2, d3, d1, d2, d3);
817MFEM_HOST_DEVICE
static inline
818int KernelVector3S(
const int &mode,
const real_t &d12,
833 real_t c12 = d12, c13 = d13, c23 = d23;
838 c32 = fabs(d1) + fabs(c12) + fabs(c13);
839 c31 = fabs(d2) + fabs(c12) + fabs(c23);
840 c21 = fabs(d3) + fabs(c13) + fabs(c23);
845 col = (c32 >= c31) ? 1 : 2;
849 col = (c31 >= c21) ? 2 : 3;
881 if (fabs(d1) <= fabs(c13))
883 row = (fabs(d1) <= fabs(c12)) ? 1 : 2;
887 row = (fabs(c12) <= fabs(c13)) ? 2 : 3;
892 if (fabs(d1) >= fabs(c13))
894 row = (fabs(d1) >= fabs(c12)) ? 1 : 2;
898 row = (fabs(c12) >= fabs(c13)) ? 2 : 3;
929 row = KernelVector3G_aux(mode, d1, d2, d3, c12, c13, c23, c21, c31, c32);
945MFEM_HOST_DEVICE
static inline
946int Reduce3S(
const int &mode,
976 if (fabs(z1) <= fabs(z3))
978 k = (fabs(z1) <= fabs(z2)) ? 1 : 2;
982 k = (fabs(z2) <= fabs(z3)) ? 2 : 3;
988 if (fabs(z1) >= fabs(z3))
990 k = (fabs(z1) >= fabs(z2)) ? 1 : 2;
994 k = (fabs(z2) >= fabs(z3)) ? 2 : 3;
1021 g = copysign(1., z1);
1022 v1 = -
s*(
s/(z1 + g));
1025 if (fabs(z2) > g) { g = fabs(z2); }
1026 if (fabs(z3) > g) { g = fabs(z3); }
1030 g = 2./(v1*v1 + v2*v2 + v3*v3);
1035 w1 = g*( d1*v1 + d12*v2 + d13*v3);
1036 w2 = g*(d12*v1 + d2*v2 + d23*v3);
1037 w3 = g*(d13*v1 + d23*v2 + d3*v3);
1039 s = (g/2)*(v1*w1 + v2*w2 + v3*w3);
1046 d23 -= v2*w3 + v3*w2;
1051 s = d12 - v1*w2 - v2*w1;
1052 s = d13 - v1*w3 - v3*w1;
1071template<> MFEM_HOST_DEVICE
inline
1074 const real_t t = 1.0 / (d[0]*d[0] + d[1]*d[1]);
1075 left_inv[0] = d[0] *
t;
1076 left_inv[1] = d[1] *
t;
1079template<> MFEM_HOST_DEVICE
inline
1082 const real_t t = 1.0 / (d[0]*d[0] + d[1]*d[1] + d[2]*d[2]);
1083 left_inv[0] = d[0] *
t;
1084 left_inv[1] = d[1] *
t;
1085 left_inv[2] = d[2] *
t;
1088template<> MFEM_HOST_DEVICE
inline
1091 real_t e = d[0]*d[0] + d[1]*d[1] + d[2]*d[2];
1092 real_t g = d[3]*d[3] + d[4]*d[4] + d[5]*d[5];
1093 real_t f = d[0]*d[3] + d[1]*d[4] + d[2]*d[5];
1095 e *=
t; g *=
t;
f *=
t;
1097 left_inv[0] = d[0]*g - d[3]*
f;
1098 left_inv[1] = d[3]*e - d[0]*
f;
1099 left_inv[2] = d[1]*g - d[4]*
f;
1100 left_inv[3] = d[4]*e - d[1]*
f;
1101 left_inv[4] = d[2]*g - d[5]*
f;
1102 left_inv[5] = d[5]*e - d[2]*
f;
1110template<> MFEM_HOST_DEVICE
inline
1117 internal::Eigensystem2S(d2, d0, d3, c,
s);
1141template<> MFEM_HOST_DEVICE
inline
1153 real_t d_max = fabs(d11);
1154 if (d_max < fabs(d22)) { d_max = fabs(d22); }
1155 if (d_max < fabs(d33)) { d_max = fabs(d33); }
1156 if (d_max < fabs(d12)) { d_max = fabs(d12); }
1157 if (d_max < fabs(d13)) { d_max = fabs(d13); }
1158 if (d_max < fabs(d23)) { d_max = fabs(d23); }
1160 internal::GetScalingFactor(d_max, mult);
1163 d11 /= mult; d22 /= mult; d33 /= mult;
1164 d12 /= mult; d13 /= mult; d23 /= mult;
1166 real_t aa = (d11 + d22 + d33)/3;
1173 Q = (2*(d12*d12 + d13*d13 + d23*d23) + c1*c1 + c2*c2 + c3*c3)/6;
1174 R = (c1*(d23*d23 - c2*c3)+ d12*(d12*c3 - 2*d13*d23) + d13*d13*c2)/2;
1178 lambda[0] = lambda[1] = lambda[2] = aa;
1179 vec[0] = 1.; vec[3] = 0.; vec[6] = 0.;
1180 vec[1] = 0.; vec[4] = 1.; vec[7] = 0.;
1181 vec[2] = 0.; vec[5] = 0.; vec[8] = 1.;
1190 if (fabs(R) >= sqrtQ3)
1209 r = -2*sqrtQ*cos((acos(R) + 2.0*M_PI)/3);
1213 r = -2*sqrtQ*cos(acos(R)/3);
1237 switch (internal::KernelVector3S(mode, d12, d13, d23, c1, c2, c3))
1241 lambda[0] = lambda[1] = lambda[2] = aa;
1242 vec[0] = 1.; vec[3] = 0.; vec[6] = 0.;
1243 vec[1] = 0.; vec[4] = 1.; vec[7] = 0.;
1244 vec[2] = 0.; vec[5] = 0.; vec[8] = 1.;
1259 int k = internal::Reduce3S(mode, d11, d22, d33, d12, d13, d23,
1260 c1, c2, c3, v1, v2, v3, g);
1268 internal::Eigensystem2S(d23, d22, d33, c,
s);
1271 real_t *vec_1, *vec_2, *vec_3;
1276 lambda[0] = d11; vec_1 = vec;
1277 lambda[1] = d22; vec_2 = vec + 3;
1278 lambda[2] = d33; vec_3 = vec + 6;
1280 else if (d11 <= d33)
1282 lambda[0] = d11; vec_1 = vec;
1283 lambda[1] = d33; vec_3 = vec + 3;
1284 lambda[2] = d22; vec_2 = vec + 6;
1288 lambda[0] = d33; vec_3 = vec;
1289 lambda[1] = d11; vec_1 = vec + 3;
1290 lambda[2] = d22; vec_2 = vec + 6;
1297 lambda[0] = d22; vec_2 = vec;
1298 lambda[1] = d11; vec_1 = vec + 3;
1299 lambda[2] = d33; vec_3 = vec + 6;
1301 else if (d22 <= d33)
1303 lambda[0] = d22; vec_2 = vec;
1304 lambda[1] = d33; vec_3 = vec + 3;
1305 lambda[2] = d11; vec_1 = vec + 6;
1309 lambda[0] = d33; vec_3 = vec;
1310 lambda[1] = d22; vec_2 = vec + 3;
1311 lambda[2] = d11; vec_1 = vec + 6;
1318 d22 = g*(v2*c - v3*
s);
1319 d33 = g*(v2*
s + v3*c);
1320 vec_2[0] = - v1*d22; vec_3[0] = - v1*d33;
1321 vec_2[1] = c - v2*d22; vec_3[1] =
s - v2*d33;
1322 vec_2[2] = -
s - v3*d22; vec_3[2] = c - v3*d33;
1326 internal::Swap(vec_2[0], vec_2[1]);
1327 internal::Swap(vec_3[0], vec_3[1]);
1331 internal::Swap(vec_2[0], vec_2[2]);
1332 internal::Swap(vec_3[0], vec_3[2]);
1343template<> MFEM_HOST_DEVICE
inline
1355 if (d_max < fabs(d1)) { d_max = fabs(d1); }
1356 if (d_max < fabs(d2)) { d_max = fabs(d2); }
1357 if (d_max < fabs(d3)) { d_max = fabs(d3); }
1358 internal::GetScalingFactor(d_max, mult);
1366 real_t t = 0.5*((d0+d2)*(d0-d2)+(d1-d3)*(d1+d3));
1368 s = sqrt(0.5*(d0*d0 + d1*d1 + d2*d2 + d3*d3) + sqrt(
t*
t +
s*
s));
1374 t = fabs(d0*d3 - d1*d2) /
s;
1391template<> MFEM_HOST_DEVICE
inline
1394 real_t d0, d1, d2, d3, d4, d5, d6, d7, d8;
1395 d0 = data[0]; d3 = data[3]; d6 = data[6];
1396 d1 = data[1]; d4 = data[4]; d7 = data[7];
1397 d2 = data[2]; d5 = data[5]; d8 = data[8];
1401 if (d_max < fabs(d1)) { d_max = fabs(d1); }
1402 if (d_max < fabs(d2)) { d_max = fabs(d2); }
1403 if (d_max < fabs(d3)) { d_max = fabs(d3); }
1404 if (d_max < fabs(d4)) { d_max = fabs(d4); }
1405 if (d_max < fabs(d5)) { d_max = fabs(d5); }
1406 if (d_max < fabs(d6)) { d_max = fabs(d6); }
1407 if (d_max < fabs(d7)) { d_max = fabs(d7); }
1408 if (d_max < fabs(d8)) { d_max = fabs(d8); }
1409 internal::GetScalingFactor(d_max, mult);
1412 d0 /= mult; d1 /= mult; d2 /= mult;
1413 d3 /= mult; d4 /= mult; d5 /= mult;
1414 d6 /= mult; d7 /= mult; d8 /= mult;
1416 real_t b11 = d0*d0 + d1*d1 + d2*d2;
1417 real_t b12 = d0*d3 + d1*d4 + d2*d5;
1418 real_t b13 = d0*d6 + d1*d7 + d2*d8;
1419 real_t b22 = d3*d3 + d4*d4 + d5*d5;
1420 real_t b23 = d3*d6 + d4*d7 + d5*d8;
1421 real_t b33 = d6*d6 + d7*d7 + d8*d8;
1440 real_t aa = (b11 + b22 + b33)/3;
1446 real_t b11_b22 = ((d0-d3)*(d0+d3)+(d1-d4)*(d1+d4)+(d2-d5)*(d2+d5));
1447 real_t b22_b33 = ((d3-d6)*(d3+d6)+(d4-d7)*(d4+d7)+(d5-d8)*(d5+d8));
1448 real_t b33_b11 = ((d6-d0)*(d6+d0)+(d7-d1)*(d7+d1)+(d8-d2)*(d8+d2));
1449 c1 = (b11_b22 - b33_b11)/3;
1450 c2 = (b22_b33 - b11_b22)/3;
1451 c3 = (b33_b11 - b22_b33)/3;
1454 Q = (2*(b12*b12 + b13*b13 + b23*b23) + c1*c1 + c2*c2 + c3*c3)/6;
1455 R = (c1*(b23*b23 - c2*c3)+ b12*(b12*c3 - 2*b13*b23) +b13*b13*c2)/2;
1494 if (fabs(R) >= sqrtQ3)
1516 aa -= 2*sqrtQ*cos(acos(R)/3);
1520 aa -= 2*sqrtQ*cos((acos(R) + 2.0*M_PI)/3);
1524 aa -= 2*sqrtQ*cos((acos(R) - 2.0*M_PI)/3);
1531 r = -2*sqrtQ*cos((acos(R) + 2.0*M_PI)/3);
1540 r = -2*sqrtQ*cos(acos(R)/3);
1571 switch (internal::KernelVector3S(mode, b12, b13, b23, c1, c2, c3))
1588 internal::Reduce3S(mode, b11, b22, b33, b12, b13, b23,
1589 c1, c2, c3, v1, v2, v3, g);
1596 internal::Eigenvalues2S(b23, b22, b33);
1600 aa = fmin(fmin(b11, b22), b33);
1606 aa = (b22 <= b33) ? b22 : fmax(b11, b33);
1610 aa = (b11 <= b33) ? b11 : fmax(b33, b22);
1615 aa = fmax(fmax(b11, b22), b33);
1621 return sqrt(fabs(aa))*mult;
1637 for (
int i = 0; i < m; i++)
1639 internal::Swap<real_t>(x[i], x[ipiv[i]]);
1643 for (
int j = 0; j < m; j++)
1646 for (
int i = j + 1; i < m; i++)
1648 x[i] -= data[i + j * m] * x_j;
1653 for (
int j = m - 1; j >= 0; j--)
1655 const real_t x_j = (x[j] /= data[j + j * m]);
1656 for (
int i = 0; i < j; i++)
1658 x[i] -= data[i + j * m] * x_j;
MFEM_HOST_DEVICE void CalcInverse(const T *data, T *inv_data)
Return the inverse of a matrix with given size and data into the matrix with data inv_data.
MFEM_HOST_DEVICE real_t DistanceSquared(const real_t *x, const real_t *y)
Compute the square of the Euclidean distance to another vector.
MFEM_HOST_DEVICE real_t CalcSingularvalue< 2 >(const real_t *data, const int i)
Return the i'th singular value of the matrix of size 2 with given data.
MFEM_HOST_DEVICE void MultAtB(const int Aheight, const int Awidth, const int Bwidth, const TA *Adata, const TB *Bdata, TC *AtBdata)
Multiply the transpose of a matrix of size Aheight x Awidth and data Adata with a matrix of size Ahei...
MFEM_HOST_DEVICE void CalcEigenvalues< 2 >(const real_t *data, real_t *lambda, real_t *vec)
MFEM_HOST_DEVICE void CalcLeftInverse(const real_t *data, real_t *left_inv)
Given a matrix of size 2x1, 3x1, or 3x2, compute the left inverse.
MFEM_HOST_DEVICE void CalcAdjugate(const T *data, T *adj_data)
Return the adjugate of a matrix.
MFEM_HOST_DEVICE void Add(const int height, const int width, const TALPHA alpha, const TA *Adata, const TB *Bdata, TC *Cdata)
Compute C = A + alpha*B, where the matrices A, B and C are of size height x width with data Adata,...
MFEM_HOST_DEVICE void Mult(const int height, const int width, const TA *data, const TX *x, TY *y)
Matrix vector multiplication: y = A x, where the matrix A is of size height x width with given data,...
MFEM_HOST_DEVICE real_t Norml2(const int size, const T *data)
Returns the l2 norm of the Vector with given size and data.
MFEM_HOST_DEVICE void FNorm(real_t &scale_factor, real_t &scaled_fnorm2, const T *data)
MFEM_HOST_DEVICE void CalcLeftInverse< 2, 1 >(const real_t *d, real_t *left_inv)
MFEM_HOST_DEVICE void MultABt(const int Aheight, const int Awidth, const int Bheight, const TA *Adata, const TB *Bdata, TC *ABtdata)
Multiply a matrix of size Aheight x Awidth and data Adata with the transpose of a matrix of size Bhei...
MFEM_HOST_DEVICE void MultTranspose(const int height, const int width, const TA *data, const TX *x, TY *y)
Matrix transpose vector multiplication: y = At x, where the matrix A is of size height x width with g...
MFEM_HOST_DEVICE real_t FNorm2(const T *data)
Compute the square of the Frobenius norm of the matrix.
MFEM_HOST_DEVICE real_t CalcSingularvalue(const real_t *data, const int i)
Return the i'th singular value of the matrix of size dim with given data.
MFEM_HOST_DEVICE void Symmetrize(const int size, T *data)
Symmetrize a square matrix with given size and data: A -> (A+A^T)/2.
MFEM_HOST_DEVICE void CalcLeftInverse< 3, 2 >(const real_t *d, real_t *left_inv)
MFEM_HOST_DEVICE void AddMultVWt(const real_t *v, const real_t *w, real_t *VWt)
Dense matrix operation: VWt += v w^t.
MFEM_HOST_DEVICE void Diag(const real_t c, real_t *data)
Creates n x n diagonal matrix with diagonal elements c.
MFEM_HOST_DEVICE void Set(const int height, const int width, const real_t alpha, const TA *Adata, TB *Bdata)
Compute B = alpha*A, where the matrices A and B are of size height x width with data Adata and Bdata.
MFEM_HOST_DEVICE void CalcLeftInverse< 3, 1 >(const real_t *d, real_t *left_inv)
MFEM_HOST_DEVICE void CalcEigenvalues(const real_t *data, real_t *lambda, real_t *vec)
MFEM_HOST_DEVICE T Det(const T *data)
Compute the determinant of a square matrix of size dim with given data.
MFEM_HOST_DEVICE real_t CalcSingularvalue< 3 >(const real_t *data, const int i)
Return the i'th singular value of the matrix of size 3 with given data.
MFEM_HOST_DEVICE void CalcEigenvalues< 3 >(const real_t *data, real_t *lambda, real_t *vec)
MFEM_HOST_DEVICE void Subtract(const real_t a, const real_t *x, const real_t *y, real_t *z)
Vector subtraction operation: z = a * (x - y)
MFEM_HOST_DEVICE void LUSolve(const real_t *data, const int m, const int *ipiv, real_t *x)
Assuming L.U = P.A for a factored matrix (m x m),.
void Swap(Array< T > &, Array< T > &)
MFEM_HOST_DEVICE void TAssignHD(const A_layout_t &A_layout, A_data_t &A_data, const scalar_t value)
MFEM_HOST_DEVICE scalar_t TAdjDetHD(const A_layout_t &a, const A_data_t &A, const B_layout_t &b, B_data_t &B)
MFEM_HOST_DEVICE scalar_t TDetHD(const layout_t &a, const data_t &A)
std::function< real_t(const Vector &)> f(real_t mass_coeff)
MFEM_HOST_DEVICE void TAdjugateHD(const A_layout_t &a, const A_data_t &A, const B_layout_t &b, B_data_t &B)