@@ -386,7 +386,7 @@ def _read(cls, fileobj, header, buffer_size=4):
386
386
"""
387
387
dtype = header ["_dtype" ]
388
388
389
- #align batch_size to be multiple of 3 within the specified buffer size
389
+ # Align batch_size to be multiple of 3 within the specified buffer size
390
390
batch_size = int (buffer_size * MEGABYTE / dtype .itemsize / 3 ) * 3
391
391
392
392
with Opener (fileobj ) as f :
@@ -397,38 +397,36 @@ def _read(cls, fileobj, header, buffer_size=4):
397
397
398
398
eof = False
399
399
n_streams = 0
400
- leftover = np .empty ((0 ,3 ), dtype = '<f4' )
400
+ leftover = np .empty ((0 , 3 ), dtype = '<f4' )
401
401
while not eof :
402
402
403
403
# read raw files from file
404
404
raw_values = np .fromfile (f .fobj , dtype , batch_size )
405
405
if len (raw_values ) < batch_size :
406
406
eof = True
407
407
408
- # Convert raw_values into a list of little-endian tuples (for x,y,z coord)
409
- coords = raw_values .astype ('<f4' , copy = False ).reshape ([ - 1 , 3 ] )
408
+ # Convert raw_values into a list of little-endian triples (for x,y,z coord)
409
+ coords = raw_values .astype ('<f4' , copy = False ).reshape (( - 1 , 3 ) )
410
410
411
- # find stream delimiter locations (all NaNs)
412
- delims = np .where (np .all (np .isnan (coords ), axis = 1 ))[0 ]
411
+ # Find stream delimiter locations (all NaNs)
412
+ delims = np .where (np .isnan (coords ).all (axis = 1 ))[0 ]
413
+
414
+ if leftover .size :
415
+ delims += leftover .shape [0 ]
416
+ coords = np .vstack ((leftover , coords ))
413
417
414
- # for each delimiters, yeild new streams
415
418
begin = 0
416
- for i in range (0 , len (delims )):
417
- end = delims [i ]
418
- if i == 0 :
419
- stream = np .vstack ((leftover , coords [begin :end ]))
420
- else :
421
- stream = coords [begin :end ]
422
- leftover = np .empty ((0 ,3 ), dtype = '<f4' )
423
- yield stream
424
- n_streams += 1
425
-
426
- begin = end + 1 #skip the delimiter
419
+ for delim in delims :
420
+ pts = coords [begin :delim ]
421
+ if pts .size :
422
+ yield coords [begin :delim ]
423
+ n_streams += 1
424
+ begin = delim + 1
427
425
428
426
# the rest gets appended to the leftover
429
- leftover = np . vstack (( leftover , coords [begin :]))
427
+ leftover = coords [begin :]
430
428
431
- if not np .all ( np . isinf (leftover ), axis = 1 ):
429
+ if not np .isinf (leftover ). all ( ):
432
430
raise DataError ("Expecting end-of-file marker 'inf inf inf'" )
433
431
434
432
# In case the 'count' field was not provided.
0 commit comments