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