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 MatPythonGetType - Get the type of a Mat object implemented in Python. 30 31 Not collective 32 33 Input Parameter: 34 . mat - the matrix object 35 36 Output Parameter: 37 . pyname - full dotted Python name [package].module[.{class|function}] 38 39 Level: intermediate 40 41 .seealso: `MatCreate()`, `MatSetType()`, `MATPYTHON`, `PetscPythonInitialize()`, `MatPythonSetType()` 42 @*/ 43 PetscErrorCode MatPythonGetType(Mat mat,const char *pyname[]) 44 { 45 PetscFunctionBegin; 46 PetscValidHeaderSpecific(mat,MAT_CLASSID,1); 47 PetscValidPointer(pyname,2); 48 PetscUseMethod(mat,"MatPythonGetType_C",(Mat, const char*[]),(mat,pyname)); 49 PetscFunctionReturn(0); 50 } 51 52 /*@C 53 MatPythonCreate - Create a Mat object implemented in Python. 54 55 Collective on Mat 56 57 Input Parameters: 58 + comm - MPI communicator 59 . m - number of local rows (or PETSC_DECIDE to have calculated if M is given) 60 . n - number of local columns (or PETSC_DECIDE to have calculated if N is given) 61 . M - number of global rows (or PETSC_DECIDE to have calculated if m is given) 62 . N - number of global columns (or PETSC_DECIDE to have calculated if n is given) 63 - pyname - full dotted Python name [package].module[.{class|function}] 64 65 Output Parameter: 66 . A - the matrix 67 68 Level: intermediate 69 70 .seealso: `MATPYTHON`, `MatPythonSetType()`, `PetscPythonInitialize()` 71 72 @*/ 73 PetscErrorCode MatPythonCreate(MPI_Comm comm,PetscInt m,PetscInt n,PetscInt M,PetscInt N,const char pyname[],Mat *A) 74 { 75 PetscFunctionBegin; 76 PetscValidCharPointer(pyname,6); 77 PetscValidPointer(A,6); 78 PetscCall(MatCreate(comm,A)); 79 PetscCall(MatSetSizes(*A,m,n,M,N)); 80 PetscCall(MatSetType(*A,MATPYTHON)); 81 PetscCall(MatPythonSetType(*A,pyname)); 82 PetscCall(MatBindToCPU(*A,PETSC_FALSE)); 83 PetscFunctionReturn(0); 84 } 85