[petsc-users] PetscBinaryIO.py: readVec fails to read 0-length Vec

Barry Smith bsmith at petsc.dev
Mon Jul 29 08:51:03 CDT 2024


https://urldefense.us/v3/__https://gitlab.com/petsc/petsc/-/merge_requests/7724__;!!G_uCfscf7eWS!c2pUfXzQgwy7S-LHON8g6ZH69NclYWSFtbeLLrMTZC_ubB8ziO9UykEAHS_ZMauViQm7pXW9lC06zLXAFT_v52Q$ 


> On Jul 27, 2024, at 12:49 PM, Nick OBrien via petsc-users <petsc-users at mcs.anl.gov> wrote:
> 
> This Message Is From an External Sender
> This message came from outside your organization.
> PetscBinaryIO errors when reading a Vec with zero elements.  The
> following python script demonstrates the issue:
> 
> --8<---------------cut here---------------start------------->8---
> import PetscBinaryIO
> import numpy as np
> 
> io = PetscBinaryIO.PetscBinaryIO()
> v = np.array([], np.float32).view(PetscBinaryIO.Vec)
> io.writeBinaryFile("test.bin", (v,))
> io.readBinaryFile("test.bin")
> --8<---------------cut here---------------end--------------->8---
> 
> --8<---------------cut here---------------start------------->8---
> [...]
>   File "/[...]/lib/petsc/bin/PetscBinaryIO.py", line 258, in readVec
>     raise IOError('Inconsistent or invalid Vec data in file')
> OSError: Inconsistent or invalid Vec data in file
> --8<---------------cut here---------------end--------------->8---
> 
> Tested on 3.20.5.  readVec errors if `len(vals) == 0`, but maybe the
> check should be `len(vals) != nz`?
> 
> -- 
> Nick OBrien
> 
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20240729/eee29cfb/attachment-0001.html>


More information about the petsc-users mailing list