Re: [Numpy-discussion] numpy log and exceptions

2014-10-22 Thread Daniel Hyams
Julian Taylor  googlemail.com> writes:

> What platform are you using?
> whether you get exceptions or not depends on your math library.
> 

Windows 7.


___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] numpy log and exceptions

2014-10-21 Thread Daniel Hyams

I would have thought that this snippet would raise an exception:

import numpy
numpy.seterr(all='raise')
a = numpy.array([1.0,0.0,-1.0])
b = numpy.log(a)

I get as a result (in b): [0, -Inf, NaN]

It's basically the same issue as:

http://numpy-discussion.10968.n7.nabble.com/numpy-log-does-not-raise-
exceptions-td5854.html

Except that I have explicitly set the error flags to raise exceptions.  It 
works fine for sqrt(), but not for log().  I've checked numpy 1.4.0 and 
1.7.1 and both have the same behavior.

Is there a way to force the log (and log10) function to raise an exception 
on invalid input?

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Bug in pickling an ndarray?

2012-06-30 Thread Daniel Hyams
Thanks Travis and Robert for the clarification; it is much more clear
what is going on now.

As the demo code shows, also a.flags['OWNDATA'] is different on its
way out of the pickle; which also makes sense now.  So using that flag
instead of checking a.base for None is equivalent, at least in this
situation.

So is it a bug, then, that, on Windows, .base is set to None (of
course, this may be something that was fixed in later versions of
numpy; I was only able to test Windows with numpy 1.4.1).

I'll just make a copy and discard the original to work around the
situation (which is what I already had done, but the inconsistent
behavior across versions and platforms made me think it was a bug).

Thanks again for the clear explanation of what is going on.


On Sat, Jun 30, 2012 at 6:33 PM, Daniel Hyams  wrote:

> Hmmm, I wouldn't think that it is correct behavior; I would think that
> *any* ndarray arising from pickling would have its .base attribute set to
> None.  If not, then who is really the one that owns the data?
>
> It was my understanding that .base should hold a reference to another
> ndarray that the data is really coming from, or it's None.  It certainly
> shouldn't be some random string, should it?
>
> And yes, it is causing a problem for me, which is why I noticed it.  In my
> application, ndarrays can come from various sources, pickling being one of
> them.  Later in the app, I was wanting to resize the array, which you
> cannot do if the data is not really owned by that array...I had explicit
> check for myarray.base==None, which it is not when I get the ndarray from a
> pickle.
>
>
> --
> Daniel Hyams
> dhy...@gmail.com
>



-- 
Daniel Hyams
dhy...@gmail.com
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Bug in pickling an ndarray?

2012-06-30 Thread Daniel Hyams
Hmmm, I wouldn't think that it is correct behavior; I would think that
*any* ndarray arising from pickling would have its .base attribute set to
None.  If not, then who is really the one that owns the data?

It was my understanding that .base should hold a reference to another
ndarray that the data is really coming from, or it's None.  It certainly
shouldn't be some random string, should it?

And yes, it is causing a problem for me, which is why I noticed it.  In my
application, ndarrays can come from various sources, pickling being one of
them.  Later in the app, I was wanting to resize the array, which you
cannot do if the data is not really owned by that array...I had explicit
check for myarray.base==None, which it is not when I get the ndarray from a
pickle.


-- 
Daniel Hyams
dhy...@gmail.com
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] Bug in pickling an ndarray?

2012-06-30 Thread Daniel Hyams
I am having trouble pickling (and then unpickling) an ndarray. Upon
unpickling, the "base" attribute of the ndarray is set to some very strange
string ("base" was None when the ndarray was pickled, so it should remain
None).

I have tried on various platforms and versions of numpy, with inconclusive
results:

# tested: Linux (Suse 11.1), numpy 1.5.1   BUG
# Linux (Suse 11,0), numpy 1.6.1   OK
# Linux (Mint Debian), numpy 1.6.1 BUG
# Linux (Mint Debian), numpy 1.6.2 BUG
# OSX (Snow Leopard),  numpy 1.5.1rc1  BUG
# OSX (Snow Leopard),  numpy 1.6.2 BUG
# Windows 7,   numpy 1.4.1 OK

I have attached a script below that can be used to check for the problem; I
suppose that this is a bug report, unless I'm doing something terribly
wrong or my expectations for the base attribute are off.

 cut here -
# this little demo shows a problem with the base attribute of an ndarray,
when
# pickling.  Before pickling, dset.base is None, but after pickling, it is
some
# strange string.

import cPickle as pickle
import numpy
print numpy.__version__
#import pickle

dset = numpy.ones((2,2))

print "BEFORE PICKLING"
print dset
print "base = ",dset.base
print dset.flags

# pickle.
s = pickle.dumps(dset)

# now unpickle.
dset = pickle.loads(s)

print "AFTER PICKLING AND THEN IMMEDIATELY UNPICKLING"
print dset
print "base = ",dset.base
print dset.flags


-- 
Daniel Hyams
dhy...@gmail.com
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] Taking a large number of dot products at once

2011-03-03 Thread Daniel Hyams
This is probably so easy, I'm embarrassed to ask it...but I've been casting
around trying things to no avail for the last hour and a half, so here
goes...

I have a lot of dot products to take.  The length-3 vectors that I want to
dot are stacked in a 2D array like this:

U = [u1 u2 u3]

and

V = [v1 v2 v3]

So both of these arrays, are, say, 3x100 each.  I just want to take the dot
product of each of the corresponding vectors, so that the result is

[u1.v1 u2.v2  u3.v3 ]

which would be a 1x100 array in this case.

Which function do I need to use?  I thought tensordot() was the one, but I
couldn't make it workpure user error I'm sure.
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion