Hi, a colleague made me aware of a speed issue with numpy.identity. Since he was using numpy.diag(numpy.ones(N)) before, he expected identity to be at least as fast as diag. But that is not the case. We found that there was a discussion on the list (July, 20th; "My identity" by Keith Goodman). The presented solution was much faster. Someone wondered if the change was already made in the svn. But I got something different: In [1]:import numpy In [2]:numpy.__version__ Out[2]:'1.4.0.dev7301' In [3]:numpy.identity?? [...] def identity(n, dtype=None): """ [...] """ a = array([1]+n*[0],dtype=dtype) b = empty((n,n),dtype=dtype) # Note that this assignment depends on the convention that since the a # array is shorter than the flattened b array, then the a array will # be repeated until it is the appropriate size. Given a's construction, # this nicely sets the diagonal to all ones. b.flat = a return b instead of (mail by Keith Goodman): def myidentity(n, dtype=None): a = zeros((n,n), dtype=dtype) a.flat[::n+1] = 1 return a Did I look at the wrong place or is there a reason to keep the slow version of identity? Lars
On Wed, Aug 12, 2009 at 1:31 AM, Lars Bittrich<lars.bittrich@googlemail.com> wrote:
Hi,
a colleague made me aware of a speed issue with numpy.identity. Since he was using numpy.diag(numpy.ones(N)) before, he expected identity to be at least as fast as diag. But that is not the case.
We found that there was a discussion on the list (July, 20th; "My identity" by Keith Goodman). The presented solution was much faster. Someone wondered if the change was already made in the svn. But I got something different:
In [1]:import numpy
In [2]:numpy.__version__ Out[2]:'1.4.0.dev7301'
In [3]:numpy.identity?? [...] def identity(n, dtype=None): """ [...] """ a = array([1]+n*[0],dtype=dtype) b = empty((n,n),dtype=dtype)
# Note that this assignment depends on the convention that since the a # array is shorter than the flattened b array, then the a array will # be repeated until it is the appropriate size. Given a's construction, # this nicely sets the diagonal to all ones. b.flat = a return b
instead of (mail by Keith Goodman):
def myidentity(n, dtype=None): a = zeros((n,n), dtype=dtype) a.flat[::n+1] = 1 return a
Did I look at the wrong place or is there a reason to keep the slow version of identity?
Things tend to get lost on the mailing list. The next step would be to file a ticket on the numpy trac. (I've never done that) That would increase the chance of someone important taking a look at it.
On Wed, Aug 12, 2009 at 7:24 AM, Keith Goodman<kwgoodman@gmail.com> wrote:
On Wed, Aug 12, 2009 at 1:31 AM, Lars Bittrich<lars.bittrich@googlemail.com> wrote:
Hi,
a colleague made me aware of a speed issue with numpy.identity. Since he was using numpy.diag(numpy.ones(N)) before, he expected identity to be at least as fast as diag. But that is not the case.
We found that there was a discussion on the list (July, 20th; "My identity" by Keith Goodman). The presented solution was much faster. Someone wondered if the change was already made in the svn. But I got something different:
In [1]:import numpy
In [2]:numpy.__version__ Out[2]:'1.4.0.dev7301'
In [3]:numpy.identity?? [...] def identity(n, dtype=None): """ [...] """ a = array([1]+n*[0],dtype=dtype) b = empty((n,n),dtype=dtype)
# Note that this assignment depends on the convention that since the a # array is shorter than the flattened b array, then the a array will # be repeated until it is the appropriate size. Given a's construction, # this nicely sets the diagonal to all ones. b.flat = a return b
instead of (mail by Keith Goodman):
def myidentity(n, dtype=None): a = zeros((n,n), dtype=dtype) a.flat[::n+1] = 1 return a
Did I look at the wrong place or is there a reason to keep the slow version of identity?
Things tend to get lost on the mailing list. The next step would be to file a ticket on the numpy trac. (I've never done that) That would increase the chance of someone important taking a look at it.
Here's the ticket: http://projects.scipy.org/numpy/ticket/1193 BTW, a fast eye function is already in svn. But identity, having fewer options, is a tiny bit faster.
2009/8/12 Keith Goodman <kwgoodman@gmail.com>: On Wed, Aug 12, 2009 at 7:24 AM, Keith Goodman<kwgoodman@gmail.com> wrote:
On Wed, Aug 12, 2009 at 1:31 AM, Lars Bittrich<lars.bittrich@googlemail.com> wrote:
a colleague made me aware of a speed issue with numpy.identity. Since he was using numpy.diag(numpy.ones(N)) before, he expected identity to be at least as fast as diag. But that is not the case.
We found that there was a discussion on the list (July, 20th; "My identity" by Keith Goodman). The presented solution was much faster. Someone wondered if the change was already made in the svn.
Things tend to get lost on the mailing list. The next step would be to file a ticket on the numpy trac. (I've never done that) That would increase the chance of someone important taking a look at it.
Here's the ticket:
A patch against recent SVN trunk is attached to the ticket. Please review... Cheers, Scott
On Wed, Aug 12, 2009 at 9:29 AM, Scott Sinclair <scott.sinclair.za@gmail.com
wrote:
2009/8/12 Keith Goodman <kwgoodman@gmail.com>: On Wed, Aug 12, 2009 at 7:24 AM, Keith Goodman<kwgoodman@gmail.com> wrote:
On Wed, Aug 12, 2009 at 1:31 AM, Lars Bittrich<lars.bittrich@googlemail.com> wrote:
a colleague made me aware of a speed issue with numpy.identity. Since
he was
using numpy.diag(numpy.ones(N)) before, he expected identity to be at least as fast as diag. But that is not the case.
We found that there was a discussion on the list (July, 20th; "My identity" by Keith Goodman). The presented solution was much faster. Someone wondered if the change was already made in the svn.
Things tend to get lost on the mailing list. The next step would be to file a ticket on the numpy trac. (I've never done that) That would increase the chance of someone important taking a look at it.
Here's the ticket:
A patch against recent SVN trunk is attached to the ticket. Please review...
Already done. Thanks. Chuck
On Wed, Aug 12, 2009 at 8:53 AM, Charles R Harris<charlesr.harris@gmail.com> wrote:
On Wed, Aug 12, 2009 at 9:29 AM, Scott Sinclair <scott.sinclair.za@gmail.com> wrote:
2009/8/12 Keith Goodman <kwgoodman@gmail.com>: On Wed, Aug 12, 2009 at 7:24 AM, Keith Goodman<kwgoodman@gmail.com> wrote:
On Wed, Aug 12, 2009 at 1:31 AM, Lars Bittrich<lars.bittrich@googlemail.com> wrote:
a colleague made me aware of a speed issue with numpy.identity. Since he was using numpy.diag(numpy.ones(N)) before, he expected identity to be at least as fast as diag. But that is not the case.
We found that there was a discussion on the list (July, 20th; "My identity" by Keith Goodman). The presented solution was much faster. Someone wondered if the change was already made in the svn.
Things tend to get lost on the mailing list. The next step would be to file a ticket on the numpy trac. (I've never done that) That would increase the chance of someone important taking a look at it.
Here's the ticket:
A patch against recent SVN trunk is attached to the ticket. Please review...
Already done. Thanks.
Hey, thanks. Now I know how to do the first two steps: (1) Extend the work of others (in this case Luca Citi and Robert Kern) (2) File a ticket (3) ??? (4) Profit
Someone posts on offtopic.com
(1) Extend the work of others (in this case Luca Citi and Robert Kern) (2) File a ticket (3) ??? (4) Profit _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
participants (5)
-
Charles R Harris
-
Chris Colbert
-
Keith Goodman
-
Lars Bittrich
-
Scott Sinclair