[petsc-users] petsc4py bool type

Barry Smith bsmith at mcs.anl.gov
Tue Apr 25 13:45:05 CDT 2017


> On Apr 25, 2017, at 1:36 PM, Zhang, Hong <hongzhang at anl.gov> wrote:
> 
> PetscBool is indeed an int. So there is nothing wrong. PETSc does not use bool in order to support C89.

  Yes, but in Python using a bool is more natural. For example in Fortran PETSc uses the Fortran logical as the PetscBool

   Barry

> 
> Hong (Mr.)
> 
>> On Apr 25, 2017, at 11:48 AM, Garth N. Wells <gnw20 at cam.ac.uk> wrote:
>> 
>> I'm seeing some behaviour with bool types in petsc4py that I didn't
>> expect. In the Python interface, returned Booleans have type '<class
>> 'int'>', where I expected them to have type ' <class 'bool'>'. Below
>> program illustrates issue. Seems to be related to bint in cython. Am I
>> doing something wrong?
>> 
>> Garth
>> 
>> 
>> from petsc4py import PETSc
>> A = PETSc.Mat()
>> A.createAIJ((2, 2))
>> A.setOption(PETSc.Mat.Option.SYMMETRIC, True)
>> symm = A.isSymmetricKnown()
>> print("Symmetry set:", symm[0] is True)
>> print("Symmetry set:", symm[0] == True)
>> print("Bool type:", type(symm[0]))
> 



More information about the petsc-users mailing list