|
From: Xaver W. <xav...@we...> - 2009-03-04 15:46:37
|
Hi,
basically, I agree, we probably don't need to raise an exception. However,
isinstance(m, numpy.ndarray)
returns 'True' for any valid numpy array, which includes e. g. string arrays,
and for a non-gnuplot compatible array the error message with your code is
gnuplot> plot "/tmp/tmpndt27x.gnuplot/fifo" notitle
^
line 0: Bad data on line 1
..not very helpful. I'd propose to rather have explicitly permitted array
types, like
if m.dtype.name in ('float64','float32','int32',int64'):
return m
else:
return numpy.array(m,dtype=numpy.float32)
whereas the 'else' clause serves mainly for having a defined error message,
maybe intercepted by a 'try...except'.
This might also eliminate the redundant conversion from float32 to float32 (if
python/numpy is not intelligent enough to not do that). What about int32 /
int64 arrays? It would be just fine to not convert them as well, right? Saves
memory, I guess...
Xaver
P.S.:
Is
diff --context oldfile.py oldfile_new.py >> mypatch.py.patch
the right way to make a patch file for the tracker? I've never done that
before...
Am Dienstag, 3. März 2009 14:40:51 schrieb Alan G Isaac:
> You are correct: the try clause now succeeds
>
> because downcasting is allowed:
> >>> x = np.random.random((5,))
> >>> x.dtype
>
> dtype('float64')
>
> >>> x32 = x.astype(np.float32)
> >>> x32.dtype
>
> dtype('float32')
>
> How about returning any ndarray untouched?
>
> if isinstance(m, numpy.ndarray):
> return m
> else:
> return numpy.array(m,dtype=numpy.float32)
>
> I see no need to print an error message:
> NumPy will report appropriately.
>
> Alan Isaac
>
>
>
> ---------------------------------------------------------------------------
>--- Open Source Business Conference (OSBC), March 24-25, 2009, San
> Francisco, CA -OSBC tackles the biggest issue in open source: Open Sourcing
> the Enterprise -Strategies to boost innovation and cut costs with open
> source participation -Receive a $600 discount off the registration fee with
> the source code: SFAD http://p.sf.net/sfu/XcvMzF8H
> _______________________________________________
> Gnuplot-py-users mailing list
> Gnu...@li...
> https://lists.sourceforge.net/lists/listinfo/gnuplot-py-users
|