xref: /petsc/src/mat/impls/python/pythonmat.c (revision af0996ce37bc06907c37d8d91773840993d61e62)
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 
27   PetscFunctionBegin;
28   PetscValidHeaderSpecific(mat,MAT_CLASSID,1);
29   PetscValidCharPointer(pyname,2);
30   ierr = PetscTryMethod(mat,"MatPythonSetType_C",(Mat, const char[]),(mat,pyname));CHKERRQ(ierr);
31   PetscFunctionReturn(0);
32 }
33 
34 
35 /*@C
36    MatPythonCreate - Create a Mat object implemented in Python.
37 
38    Collective on Mat
39 
40    Input Parameters:
41 +  comm - MPI communicator
42 .  m - number of local rows (or PETSC_DECIDE to have calculated if M is given)
43 .  n - number of local columns (or PETSC_DECIDE to have calculated if N is given)
44 .  M - number of global rows (or PETSC_DECIDE to have calculated if m is given)
45 .  N - number of global columns (or PETSC_DECIDE to have calculated if n is given)
46 -  pyname - full dotted Python name [package].module[.{class|function}]
47 
48    Output Parameter:
49 .  A - the matrix
50 
51    Level: intermediate
52 
53 .keywords: Mat, Python
54 
55 .seealso: MATPYTHON, MatPythonSetType(), PetscPythonInitialize()
56 
57 @*/
58 #undef __FUNCT__
59 #define __FUNCT__ "MatPythonCreate"
60 PetscErrorCode  MatPythonCreate(MPI_Comm comm,PetscInt m,PetscInt n,PetscInt M,PetscInt N,const char pyname[],Mat *A)
61 {
62   PetscErrorCode ierr;
63 
64   PetscFunctionBegin;
65   PetscValidCharPointer(pyname,6);
66   PetscValidPointer(A,6);
67   ierr = MatCreate(comm,A);CHKERRQ(ierr);
68   ierr = MatSetSizes(*A,m,n,M,N);CHKERRQ(ierr);
69   ierr = MatSetType(*A,MATPYTHON);CHKERRQ(ierr);
70   ierr = MatPythonSetType(*A,pyname);CHKERRQ(ierr);
71   PetscFunctionReturn(0);
72 }
73