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