Re: [Numpy-discussion] Funny business with 'is' operator?

2013-09-06 Thread James Bergstra
and slicing). On Fri, Sep 6, 2013 at 12:48 PM, James Bergstra wrote: > Thanks for the tips! FWIW my guess is that since '.data' is dynamically > generated property rather than an attribute, it is being freed and > re-allocated in the loop, and once for each of my id() express

Re: [Numpy-discussion] Funny business with 'is' operator?

2013-09-06 Thread James Bergstra
i, Sep 6, 2013 at 5:58 PM, James Bergstra > wrote: > > > > I'm stumped. I can't figure out how to extract from e.g. > > > > view = A[:, 3] > > > > that the view starts at element 3 of A. I was planning to make a > may_share_memory implementation

[Numpy-discussion] Funny business with 'is' operator?

2013-09-06 Thread James Bergstra
Hi, could someone help me understand why this assertion fails? def test_is(self): a = np.empty(1) b = np.empty(1) if a.data is not b.data: assert id(a.data) != id(b.data) # <-- fail I'm trying to write an alternate may_share_memory function. Thanks, - James _

Re: [Numpy-discussion] Funny business with 'is' operator?

2013-09-06 Thread James Bergstra
On Fri, Sep 6, 2013 at 10:19 AM, James Bergstra > wrote: > >> Hi, could someone help me understand why this assertion fails? >> >> def test_is(self): >> a = np.empty(1) >> b = np.empty(1) >> if a.data is not b.data: >> assert id(a

Re: [Numpy-discussion] automatic differentiation with PyAutoDiff

2012-06-14 Thread James Bergstra
On Thu, Jun 14, 2012 at 5:53 PM, Nathaniel Smith wrote: > On Thu, Jun 14, 2012 at 9:22 PM, srean wrote: > No, I'm saying I totally see the advantages. Here's the code I'm talking > about: > >    def _loglik(self, params): >        alpha, beta = self.used_alpha_beta(params) >        if np.any(alp

Re: [Numpy-discussion] automatic differentiation with PyAutoDiff

2012-06-14 Thread James Bergstra
On Thu, Jun 14, 2012 at 4:22 PM, srean wrote: >> >> For example, I wrote a library routine for doing log-linear >> regression. Doing this required computing the derivative of the >> likelihood function, which was a huge nitpicky hassle; took me a few >> hours to work out and debug. But it's still

Re: [Numpy-discussion] automatic differentiation with PyAutoDiff

2012-06-14 Thread James Bergstra
On Thu, Jun 14, 2012 at 3:38 PM, Nathaniel Smith wrote: > On Thu, Jun 14, 2012 at 7:53 PM, James Bergstra > wrote: >> On Thu, Jun 14, 2012 at 11:01 AM, Nathaniel Smith wrote: >> >>>> Indeed that would be great as sympy already has already excellent math >>&

Re: [Numpy-discussion] automatic differentiation with PyAutoDiff

2012-06-14 Thread James Bergstra
On Thu, Jun 14, 2012 at 11:01 AM, Nathaniel Smith wrote: >> Indeed that would be great as sympy already has already excellent math >> expression rendering. >> >> An alternative would be to output mathml or something similar that >> could be understood by the mathjax rendering module of the IPytho

Re: [Numpy-discussion] automatic differentiation with PyAutoDiff

2012-06-14 Thread James Bergstra
On Thu, Jun 14, 2012 at 4:00 AM, Olivier Grisel wrote: > 2012/6/13 James Bergstra : >> Further to the recent discussion on lazy evaluation & numba, I moved >> what I was doing into a new project: >> >> PyAutoDiff: >> https://github.com/jaberg/pyautodiff

[Numpy-discussion] automatic differentiation with PyAutoDiff

2012-06-13 Thread James Bergstra
Further to the recent discussion on lazy evaluation & numba, I moved what I was doing into a new project: PyAutoDiff: https://github.com/jaberg/pyautodiff It currently works by executing CPython bytecode with a numpy-aware engine that builds a symbolic expression graph with Theano... so you can d

Re: [Numpy-discussion] lazy evaluation

2012-06-11 Thread James Bergstra
On Mon, Jun 11, 2012 at 12:03 AM, James Bergstra wrote: > If anyone is interested in my ongoing API & bytecode adventure in why > / how lazy computing could be useful, I've put together a few tiny > hypothetically-runnable examples here: > > https://github.com/jaberg/nu

Re: [Numpy-discussion] lazy evaluation

2012-06-10 Thread James Bergstra
Hi all, (sorry for missing the debate, I don't often check my numpy-list folder.) I agree that an "official" numpy solution to this problem is premature, but at the same time I think the failure to approach anything remotely resembling a consensus on how to deal with lazy evaluation is really gumm

Re: [Numpy-discussion] bincount([], minlength=2) should work right?

2012-02-25 Thread James Bergstra
On Sat, Feb 25, 2012 at 5:13 PM, Alan G Isaac wrote: > On 2/25/2012 4:44 PM, James Bergstra wrote: >> bincount([]) makes no sense, > > I disagree: > http://permalink.gmane.org/gmane.comp.python.numeric.general/42041 > gmane is down to me at the moment, but if this argues that

[Numpy-discussion] bincount([], minlength=2) should work right?

2012-02-25 Thread James Bergstra
bincount([]) makes no sense, but if a minlength argument is provided, then the routine should succeed. It fails in 1.6.1, has it been fixed in master? - James -- http://www-etud.iro.umontreal.ca/~bergstrj ___ NumPy-Discussion mailing list NumPy-Discussi

Re: [Numpy-discussion] ndarray and lazy evaluation

2012-02-20 Thread James Bergstra
On Mon, Feb 20, 2012 at 2:57 PM, Lluís wrote: > James Bergstra writes: > [...] > > I should add that the biggest benefit of expressing things as compound > > expressions in this way is not in saving temporaries (though that is > nice) it's > > being able to expr

Re: [Numpy-discussion] Proposed Roadmap Overview

2012-02-20 Thread James Bergstra
Looks like Dag forked the discussion of lazy evaluation to a new thread ([Numpy-discussion] ndarray and lazy evaluation). There are actually several projects inspired by this sort of design: off the top of my head I can think of Theano, copperhead, numexpr, arguably sympy, and some non-public cod

Re: [Numpy-discussion] ndarray and lazy evaluation

2012-02-20 Thread James Bergstra
On Mon, Feb 20, 2012 at 1:01 PM, James Bergstra wrote: > On Mon, Feb 20, 2012 at 12:28 PM, Francesc Alted wrote: > >> On Feb 20, 2012, at 6:18 PM, Dag Sverre Seljebotn wrote: >> > You need at least a slightly different Python API to get anywhere, so >> > numexpr/The

Re: [Numpy-discussion] ndarray and lazy evaluation

2012-02-20 Thread James Bergstra
brr)) # compute arr and brr as quickly as possible a, b = expr.run() # modify one of the arrays that the expression was compiled to use A[:] += 1 # re-run the compiled expression on the new value a, b = expr.run() - JB -- James Bergstra, Ph.D. Research Scientist Rowland Institute, Harvard

Re: [Numpy-discussion] potential bug in PyArray_MoveInto and PyArray_CopyInto?

2011-07-08 Thread James Bergstra
On Thu, Jul 7, 2011 at 4:59 PM, James Bergstra wrote: > On Thu, Jul 7, 2011 at 1:10 PM, Charles R Harris > wrote: >> >> >> On Thu, Jul 7, 2011 at 11:03 AM, James Bergstra >> wrote: >>> >>> In numpy 1.5.1,  the functions PyArray_MoveInto and Py

Re: [Numpy-discussion] potential bug in PyArray_MoveInto and PyArray_CopyInto?

2011-07-07 Thread James Bergstra
On Thu, Jul 7, 2011 at 1:10 PM, Charles R Harris wrote: > > > On Thu, Jul 7, 2011 at 11:03 AM, James Bergstra > wrote: >> >> In numpy 1.5.1,  the functions PyArray_MoveInto and PyArray_CopyInto >> don't appear to treat strides correctly. >> >>

[Numpy-discussion] potential bug in PyArray_MoveInto and PyArray_CopyInto?

2011-07-07 Thread James Bergstra
In numpy 1.5.1,  the functions PyArray_MoveInto and PyArray_CopyInto don't appear to treat strides correctly. Evidence: PyNumber_InPlaceAdd(dst, src), and modifies the correct subarray to which dst points. In the same context, PyArray_MoveInto(dst, src) modifies the first two rows of the underlyi

[Numpy-discussion] numpy.max(0, 1e-6) == 0 (!?)

2011-01-18 Thread James Bergstra
I find that "numpy.max(0, 1e-6) == 0" is confusing, because it makes bugs hard to spot. The doc says that the second argument to max is an optional integer. My bad. But could the function raise an error if it is passed an invalid 'axis' argument? That would have helped. James -- http://www-etu

[Numpy-discussion] Bug in frompyfunc starting at 10000 elements?

2010-05-21 Thread James Bergstra
Hi all, I'm wondering if this is a bug... Something strange happens with my ufunc as soon as I use 1 elements. As the test shows, the ufunc computes the correct result for either the first or last elements, but both at the same time is no good. Turns out I'm only running numpy 1.3.0 with

Re: [Numpy-discussion] Math Library

2010-04-14 Thread James Bergstra
On Tue, Apr 6, 2010 at 10:08 AM, David Cournapeau wrote: > could be put out of multiarray proper. Also, exposing an API for > things like fancy indexing would be very useful, but I don't know if > it even makes sense - I think a pure python implementation of fancy > indexing as a reference would be

Re: [Numpy-discussion] [OT] Starving CPUs article featured in IEEE's ComputingNow portal

2010-03-22 Thread James Bergstra
all that, plus automatic differentiation, detection and >> correction of numerical instabilities, etc. >> >> Probably the most amazing thing about it is that with recent versions, >> you basically flip a switch and it will instead use an available CUDA- >> capable Nvidi

Re: [Numpy-discussion] how to work with numpy.int8 in c

2010-03-03 Thread James Bergstra
Thanks all for your help, I think I'm on my way again. The catch in the first place was not being confident that a PyArray_Scalar was the thing I needed. I grep'd the code for uint8, int8 and so on and could not find their definitions. On first reading I overlooked the PyArray_Scalar link in thi

Re: [Numpy-discussion] how to work with numpy.int8 in c

2010-03-02 Thread James Bergstra
On Tue, Mar 2, 2010 at 7:32 PM, David Warde-Farley wrote: > > On 2-Mar-10, at 7:23 PM, James Bergstra wrote: > >> Sorry... again... how do I make such a scalar... *in C* ?  What would >> be the recommended C equivalent of this python code?  Are there C >> type-checking

Re: [Numpy-discussion] how to work with numpy.int8 in c

2010-03-02 Thread James Bergstra
On Tue, Mar 2, 2010 at 7:18 PM, Warren Weckesser wrote: > James Bergstra wrote: >> On Tue, Mar 2, 2010 at 3:09 PM, Christopher Barker >> wrote: >> >>> James Bergstra wrote: >>> >>>> Maybe I'm missing something... but I don't th

Re: [Numpy-discussion] how to work with numpy.int8 in c

2010-03-02 Thread James Bergstra
On Tue, Mar 2, 2010 at 3:09 PM, Christopher Barker wrote: > James Bergstra wrote: >> Maybe I'm missing something... but I don't think I want to create an array. >> >> In [3]: import numpy >> >> In [4]: type(numpy.int8()) >> Out[4]: >> >

Re: [Numpy-discussion] how to work with numpy.int8 in c

2010-03-02 Thread James Bergstra
On Mon, Mar 1, 2010 at 1:44 AM, David Cournapeau wrote: > On Mon, Mar 1, 2010 at 1:35 PM, James Bergstra > wrote: >> Could someone point me to documentation (or even numpy src) that shows >> how to allocate a numpy.int8 in C, or check to see if a PyObject is a >> numpy

[Numpy-discussion] how to work with numpy.int8 in c

2010-02-28 Thread James Bergstra
Could someone point me to documentation (or even numpy src) that shows how to allocate a numpy.int8 in C, or check to see if a PyObject is a numpy.int8? Thanks, James -- http://www-etud.iro.umontreal.ca/~bergstrj ___ NumPy-Discussion mailing list NumPy

[Numpy-discussion] problem w 32bit binomial?

2010-02-25 Thread James Bergstra
In case this hasn't been solved in more recent numpy... I've tried the following lines on two installations of numpy 1.3 with python 2.6  numpy.random.binomial(n=numpy.asarray([2,3,4], dtype='int64'), p=numpy.asarray([.1, .2, .3], dtype='float64')) A 64bit computer gives an output of array lengt

Re: [Numpy-discussion] convert strides/shape/offset into nd index?

2009-11-30 Thread James Bergstra
Your question involves a few concepts: - an integer vector describing the position of an element - the logical shape (another int vector) - the physical strides (another int vector) Ignoring the case of negative offsets, a physical offset is the inner product of the physical strides with the po

Re: [Numpy-discussion] Unexpected attribute error

2009-11-18 Thread James Bergstra
On Tue, Nov 17, 2009 at 9:53 PM, Robert Kern wrote: > On Tue, Nov 17, 2009 at 20:48, James Bergstra > wrote: >> Is it by design that  "numpy.sqrt(None)" raises an "AttributeError: sqrt"? > > Yes. numpy.sqrt() is a ufunc. Ufuncs take their arguments and try

[Numpy-discussion] Unexpected attribute error

2009-11-17 Thread James Bergstra
Is it by design that  "numpy.sqrt(None)" raises an "AttributeError: sqrt"? This was confusing because there was an attribute lookup of 'sqrt' in numpy right there in the expression I typed, but that was not the attribute that python was complaining about.  I presume that numpy.sqrt didn't know wha

Re: [Numpy-discussion] finding close together points.

2009-11-10 Thread James Bergstra
On Tue, Nov 10, 2009 at 8:17 PM, Christopher Barker wrote: > James Bergstra wrote: >> In some cases a brute-force approach is also good. > > true. > >> If r is a matrix of shape Nx2: >> >> (r*r).sum(axis=1) -2 * numpy.dot(r, r.T) + >> (r*r).sum(ax

Re: [Numpy-discussion] finding close together points.

2009-11-10 Thread James Bergstra
On Tue, Nov 10, 2009 at 7:07 PM, Christopher Barker wrote: > Hi all, > > I have a bunch of points in 2-d space, and I need to find out which > pairs of points are within a certain distance of one-another (regular > old Euclidean norm). > > scipy.spatial.KDTree.query_ball_tree() seems like it's bui

Re: [Numpy-discussion] type 'numpy.int64' unhashable

2009-10-30 Thread James Bergstra
On Fri, Oct 30, 2009 at 7:23 AM, Gael Varoquaux wrote: > On Fri, Oct 30, 2009 at 08:21:16PM +0900, David Cournapeau wrote: >> On Fri, Oct 30, 2009 at 8:04 PM, Sebastian Haase wrote: > >> > I understand where this error comes from, however what I was trying to >> > do seems to "intuitive" that I w

Re: [Numpy-discussion] Fwd: GPU Numpy

2009-09-09 Thread James Bergstra
On Wed, Sep 9, 2009 at 10:41 AM, Francesc Alted wrote: >> Numexpr mainly supports functions that are meant to be used element-wise, >> so the operation/element ratio is normally 1 (or close to 1). In these >> scenarios is where improved memory access is much more important than CPU >> (or, for th

Re: [Numpy-discussion] Accelerating NumPy computations [Was: GPU Numpy]

2009-08-21 Thread James Bergstra
On Fri, Aug 21, 2009 at 2:51 PM, Matthew Brett wrote: > I can imagine Numpy being useful for scripting in this > C-and-assembler-centric world, making it easier to write automated > testers, or even generate C code. > > Is anyone out there working on this kind of stuff?  I ask only because > there

Re: [Numpy-discussion] Fwd: GPU Numpy

2009-08-06 Thread James Bergstra
On Thu, Aug 6, 2009 at 4:57 PM, Sturla Molden wrote: > >> Now linear algebra or FFTs on a GPU would probably be a huge boon, >> I'll admit - especially if it's in the form of a drop-in replacement >> for the numpy or scipy versions. > > > NumPy generate temporary arrays for expressions involving nd

Re: [Numpy-discussion] Fwd: GPU Numpy

2009-08-06 Thread James Bergstra
On Thu, Aug 6, 2009 at 1:19 PM, Charles R Harris wrote: > I almost looks like you are reimplementing numpy, in c++ no less. Is there > any reason why you aren't working with a numpy branch and just adding > ufuncs? I don't know how that would work. The Ufuncs need a datatype to work with, and AFA

[Numpy-discussion] Fwd: GPU Numpy

2009-08-06 Thread James Bergstra
>David Warde-Farley cs.toronto.edu> writes: >> It did inspire some of our colleagues in Montreal to create this, >> though: >> >>      http://code.google.com/p/cuda-ndarray/ >> >> I gather it is VERY early in development, but I'm sure they'd love >> contributions! >> > >Hi David, >That does look q