Actual source code: pythonmat.c
1: #include <petsc/private/matimpl.h>
3: /*@C
4: MatPythonSetType - Initialize a `Mat` object implemented in Python.
6: Collective
8: Input Parameters:
9: + mat - the matrix object.
10: - pyname - full dotted Python name [package].module[.{class|function}]
12: Options Database Key:
13: . -mat_python_type <pyname> - python class
15: Level: intermediate
17: .seealso: `Mat`, `MatType`, `MatCreate()`, `MatSetType()`, `MATPYTHON`, `PetscPythonInitialize()`
18: @*/
19: PetscErrorCode MatPythonSetType(Mat mat, const char pyname[])
20: {
23: PetscTryMethod(mat, "MatPythonSetType_C", (Mat, const char[]), (mat, pyname));
24: return 0;
25: }
27: /*@C
28: MatPythonGetType - Get the type of a `Mat` object implemented in Python.
30: Not collective
32: Input Parameter:
33: . mat - the matrix
35: Output Parameter:
36: . pyname - full dotted Python name [package].module[.{class|function}]
38: Level: intermediate
40: .seealso: `Mat`, `MatType`, `MatCreate()`, `MatSetType()`, `MATPYTHON`, `PetscPythonInitialize()`, `MatPythonSetType()`
41: @*/
42: PetscErrorCode MatPythonGetType(Mat mat, const char *pyname[])
43: {
46: PetscUseMethod(mat, "MatPythonGetType_C", (Mat, const char *[]), (mat, pyname));
47: return 0;
48: }
50: /*@C
51: MatPythonCreate - Create a `Mat` object implemented in Python.
53: Collective
55: Input Parameters:
56: + comm - MPI communicator
57: . m - number of local rows (or `PETSC_DECIDE` to have calculated if M is given)
58: . n - number of local columns (or `PETSC_DECIDE` to have calculated if N is given)
59: . M - number of global rows (or `PETSC_DECIDE` to have calculated if m is given)
60: . N - number of global columns (or `PETSC_DECIDE` to have calculated if n is given)
61: - pyname - full dotted Python name [package].module[.{class|function}]
63: Output Parameter:
64: . A - the matrix
66: Level: intermediate
68: .seealso: `Mat`, `MatType`, `MATPYTHON`, `MatPythonSetType()`, `PetscPythonInitialize()`
69: @*/
70: PetscErrorCode MatPythonCreate(MPI_Comm comm, PetscInt m, PetscInt n, PetscInt M, PetscInt N, const char pyname[], Mat *A)
71: {
74: MatCreate(comm, A);
75: MatSetSizes(*A, m, n, M, N);
76: MatSetType(*A, MATPYTHON);
77: MatPythonSetType(*A, pyname);
78: MatBindToCPU(*A, PETSC_FALSE);
79: return 0;
80: }