[Numpy-discussion] Difference in the number of elements in a fromfile() between Windows and Linux

David M. Cooke cookedm at physics.mcmaster.ca
Fri May 4 18:52:53 EDT 2007


On Sat, May 05, 2007 at 12:34:30AM +0200, Stefan van der Walt wrote:
> On Fri, May 04, 2007 at 09:44:02AM -0700, Christopher Barker wrote:
> > Matthieu Brucher wrote:
> > > Example of the first line of my data file :
> > > 0.0 inf 13.9040914426 14.7406669444 inf 4.41783247603 inf inf 
> > > 6.05071515635 inf inf inf 15.6925185021 inf inf inf inf inf inf inf
> > 
> > I'm pretty sure fromfile() is using the standard C fscanf(). That means 
> > that whether in understands "inf" depends on the C lib. I'm guessing 
> > that the MS libc doesn't understand the same spelling of "inf" that the 
> > gcc one does. There may indeed be no literal for the IEEE Inf.
> 
> It would be interesting to see how Inf and NaN (vs. inf and nan) are
> interpreted under Windows.
> 
> Are there any free fscanf implementations out there that we can
> include with numpy?

There's no need; all that fscanf is being used for is with the single
format string "%d" (and variants for each type). So that's easily
replaced with type-specific functions (strtol, strtod, etc.). For the
floating-point types, checking first if the string matches inf or nan
patterns would be sufficient.

There's a bug in fromfile anyways: because it passes the separator
directly to fscanf to skip over it, using a % in your separator will not
work.

-- 
|>|\/|<
/--------------------------------------------------------------------------\
|David M. Cooke                      http://arbutus.physics.mcmaster.ca/dmc/
|cookedm at physics.mcmaster.ca



More information about the NumPy-Discussion mailing list