Skip to content

Commit ba59ac1

Browse files
Move some linear algebra/matrix operations to internal API (#1165)
* Move unoptimized matrix operations to internal API * Minor docstring formatting in ceed-basis.c * Update Julia/Python/Fortran APIs for removed public functions * Fix include for tests * Fixes for removed Python API functions
1 parent 4c289bd commit ba59ac1

File tree

12 files changed

+599
-1050
lines changed

12 files changed

+599
-1050
lines changed

examples/python/tutorial-3-basis.ipynb

-105
Original file line numberDiff line numberDiff line change
@@ -312,111 +312,6 @@
312312
" # Check that (1' * G * u - u' * (G' * 1)) is numerically zero\n",
313313
" print('1T * G * u - uT * (GT * 1) =', np.abs(sum1 - sum2))"
314314
]
315-
},
316-
{
317-
"cell_type": "markdown",
318-
"metadata": {},
319-
"source": [
320-
"### Advanced topics"
321-
]
322-
},
323-
{
324-
"cell_type": "markdown",
325-
"metadata": {},
326-
"source": [
327-
"* In the following example, we demonstrate the QR factorization of a basis matrix.\n",
328-
"The representation is similar to LAPACK's [`dgeqrf`](https://www.netlib.org/lapack/explore-html/dd/d9a/group__double_g_ecomputational_ga3766ea903391b5cf9008132f7440ec7b.html#ga3766ea903391b5cf9008132f7440ec7b), with elementary reflectors in the lower triangular block, scaled by `tau`."
329-
]
330-
},
331-
{
332-
"cell_type": "code",
333-
"execution_count": null,
334-
"metadata": {},
335-
"outputs": [],
336-
"source": [
337-
"qr = np.array([1, -1, 4, 1, 4, -2, 1, 4, 2, 1, -1, 0], dtype=\"float64\")\n",
338-
"tau = np.empty(3, dtype=\"float64\")\n",
339-
"\n",
340-
"qr, tau = ceed.qr_factorization(qr, tau, 4, 3)\n",
341-
"\n",
342-
"print('qr =')\n",
343-
"print(qr.reshape(4, 3))\n",
344-
"\n",
345-
"print('tau =')\n",
346-
"print(tau)"
347-
]
348-
},
349-
{
350-
"cell_type": "markdown",
351-
"metadata": {},
352-
"source": [
353-
"* In the following example, we demonstrate the symmetric Schur decomposition of a basis matrix"
354-
]
355-
},
356-
{
357-
"cell_type": "code",
358-
"execution_count": null,
359-
"metadata": {},
360-
"outputs": [],
361-
"source": [
362-
"A = np.array([0.19996678, 0.0745459, -0.07448852, 0.0332866,\n",
363-
" 0.0745459, 1., 0.16666509, -0.07448852,\n",
364-
" -0.07448852, 0.16666509, 1., 0.0745459,\n",
365-
" 0.0332866, -0.07448852, 0.0745459, 0.19996678], dtype=\"float64\")\n",
366-
"\n",
367-
"lam = ceed.symmetric_schur_decomposition(A, 4)\n",
368-
"\n",
369-
"print(\"Q =\")\n",
370-
"for i in range(4):\n",
371-
" for j in range(4):\n",
372-
" if A[j+4*i] <= 1E-14 and A[j+4*i] >= -1E-14:\n",
373-
" A[j+4*i] = 0\n",
374-
" print(\"%12.8f\"%A[j+4*i])\n",
375-
"\n",
376-
"print(\"lambda =\")\n",
377-
"for i in range(4):\n",
378-
" if lam[i] <= 1E-14 and lam[i] >= -1E-14:\n",
379-
" lam[i] = 0\n",
380-
" print(\"%12.8f\"%lam[i])"
381-
]
382-
},
383-
{
384-
"cell_type": "markdown",
385-
"metadata": {},
386-
"source": [
387-
"* In the following example, we demonstrate the simultaneous diagonalization of a basis matrix"
388-
]
389-
},
390-
{
391-
"cell_type": "code",
392-
"execution_count": null,
393-
"metadata": {},
394-
"outputs": [],
395-
"source": [
396-
"M = np.array([0.19996678, 0.0745459, -0.07448852, 0.0332866,\n",
397-
" 0.0745459, 1., 0.16666509, -0.07448852,\n",
398-
" -0.07448852, 0.16666509, 1., 0.0745459,\n",
399-
" 0.0332866, -0.07448852, 0.0745459, 0.19996678], dtype=\"float64\")\n",
400-
"K = np.array([3.03344425, -3.41501767, 0.49824435, -0.11667092,\n",
401-
" -3.41501767, 5.83354662, -2.9167733, 0.49824435,\n",
402-
" 0.49824435, -2.9167733, 5.83354662, -3.41501767,\n",
403-
" -0.11667092, 0.49824435, -3.41501767, 3.03344425], dtype=\"float64\")\n",
404-
"\n",
405-
"x, lam = ceed.simultaneous_diagonalization(K, M, 4)\n",
406-
"\n",
407-
"print(\"x =\")\n",
408-
"for i in range(4):\n",
409-
" for j in range(4):\n",
410-
" if x[j+4*i] <= 1E-14 and x[j+4*i] >= -1E-14:\n",
411-
" x[j+4*i] = 0\n",
412-
" print(\"%12.8f\"%x[j+4*i])\n",
413-
"\n",
414-
"print(\"lambda =\")\n",
415-
"for i in range(4):\n",
416-
" if lam[i] <= 1E-14 and lam[i] >= -1E-14:\n",
417-
" lam[i] = 0\n",
418-
" print(\"%12.8f\"%lam[i])"
419-
]
420315
}
421316
],
422317
"metadata": {

include/ceed/backend.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,6 @@ typedef enum {
181181
CEED_EXTERN const char *const CeedFESpaces[];
182182

183183
CEED_EXTERN int CeedBasisGetCollocatedGrad(CeedBasis basis, CeedScalar *colo_grad_1d);
184-
CEED_EXTERN int CeedHouseholderApplyQ(CeedScalar *A, const CeedScalar *Q, const CeedScalar *tau, CeedTransposeMode t_mode, CeedInt m, CeedInt n,
185-
CeedInt k, CeedInt row, CeedInt col);
186184
CEED_EXTERN int CeedBasisIsTensor(CeedBasis basis, bool *is_tensor);
187185
CEED_EXTERN int CeedBasisGetData(CeedBasis basis, void *data);
188186
CEED_EXTERN int CeedBasisSetData(CeedBasis basis, void *data);
@@ -282,5 +280,10 @@ CEED_EXTERN int CeedOperatorSetSetupDone(CeedOperator op);
282280

283281
CEED_INTERN int CeedMatrixMatrixMultiply(Ceed ceed, const CeedScalar *mat_A, const CeedScalar *mat_B, CeedScalar *mat_C, CeedInt m, CeedInt n,
284282
CeedInt kk);
283+
CEED_EXTERN int CeedQRFactorization(Ceed ceed, CeedScalar *mat, CeedScalar *tau, CeedInt m, CeedInt n);
284+
CEED_EXTERN int CeedHouseholderApplyQ(CeedScalar *mat_A, const CeedScalar *mat_Q, const CeedScalar *tau, CeedTransposeMode t_mode, CeedInt m,
285+
CeedInt n, CeedInt k, CeedInt row, CeedInt col);
286+
CEED_EXTERN int CeedSymmetricSchurDecomposition(Ceed ceed, CeedScalar *mat, CeedScalar *lambda, CeedInt n);
287+
CEED_EXTERN int CeedSimultaneousDiagonalization(Ceed ceed, CeedScalar *mat_A, CeedScalar *mat_B, CeedScalar *x, CeedScalar *lambda, CeedInt n);
285288

286289
#endif

include/ceed/ceed.h

-3
Original file line numberDiff line numberDiff line change
@@ -388,9 +388,6 @@ CEED_EXTERN int CeedBasisDestroy(CeedBasis *basis);
388388

389389
CEED_EXTERN int CeedGaussQuadrature(CeedInt Q, CeedScalar *q_ref_1d, CeedScalar *q_weight_1d);
390390
CEED_EXTERN int CeedLobattoQuadrature(CeedInt Q, CeedScalar *q_ref_1d, CeedScalar *q_weight_1d);
391-
CEED_EXTERN int CeedQRFactorization(Ceed ceed, CeedScalar *mat, CeedScalar *tau, CeedInt m, CeedInt n);
392-
CEED_EXTERN int CeedSymmetricSchurDecomposition(Ceed ceed, CeedScalar *mat, CeedScalar *lambda, CeedInt n);
393-
CEED_EXTERN int CeedSimultaneousDiagonalization(Ceed ceed, CeedScalar *mat_A, CeedScalar *mat_B, CeedScalar *x, CeedScalar *lambda, CeedInt n);
394391

395392
/** Handle for the user provided CeedQFunction callback function
396393

0 commit comments

Comments
 (0)