1 #include <petsc/private/matimpl.h> /*I "petscmat.h" I*/ 2 3 /*@C 4 MatPythonSetType - Initialize a Mat object implemented in Python. 5 6 Collective on Mat 7 8 Input Parameters: 9 + mat - the matrix (Mat) object. 10 - pyname - full dotted Python name [package].module[.{class|function}] 11 12 Options Database Key: 13 . -mat_python_type <pyname> - python class 14 15 Level: intermediate 16 17 .seealso: `MatCreate()`, `MatSetType()`, `MATPYTHON`, `PetscPythonInitialize()` 18 @*/ 19 PetscErrorCode MatPythonSetType(Mat mat,const char pyname[]) 20 { 21 PetscFunctionBegin; 22 PetscValidHeaderSpecific(mat,MAT_CLASSID,1); 23 PetscValidCharPointer(pyname,2); 24 PetscTryMethod(mat,"MatPythonSetType_C",(Mat, const char[]),(mat,pyname)); 25 PetscFunctionReturn(0); 26 } 27 28 /*@C 29 MatPythonCreate - Create a Mat object implemented in Python. 30 31 Collective on Mat 32 33 Input Parameters: 34 + comm - MPI communicator 35 . m - number of local rows (or PETSC_DECIDE to have calculated if M is given) 36 . n - number of local columns (or PETSC_DECIDE to have calculated if N is given) 37 . M - number of global rows (or PETSC_DECIDE to have calculated if m is given) 38 . N - number of global columns (or PETSC_DECIDE to have calculated if n is given) 39 - pyname - full dotted Python name [package].module[.{class|function}] 40 41 Output Parameter: 42 . A - the matrix 43 44 Level: intermediate 45 46 .seealso: `MATPYTHON`, `MatPythonSetType()`, `PetscPythonInitialize()` 47 48 @*/ 49 PetscErrorCode MatPythonCreate(MPI_Comm comm,PetscInt m,PetscInt n,PetscInt M,PetscInt N,const char pyname[],Mat *A) 50 { 51 PetscFunctionBegin; 52 PetscValidCharPointer(pyname,6); 53 PetscValidPointer(A,6); 54 PetscCall(MatCreate(comm,A)); 55 PetscCall(MatSetSizes(*A,m,n,M,N)); 56 PetscCall(MatSetType(*A,MATPYTHON)); 57 PetscCall(MatPythonSetType(*A,pyname)); 58 PetscCall(MatBindToCPU(*A,PETSC_FALSE)); 59 PetscFunctionReturn(0); 60 } 61