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