Re: [Numpy-discussion] [help needed] associativity and precedence of '@'

2014-03-18 Thread Eelco Hoogendoorn
Perhaps this a bit of a thread hyjack; but this discussion got me thinking
about how to arrive
at a more vectorized/tensorified way of specifying linear algebra
operations, in an elegant manner.

I probably got a little carried away, but what about this syntax?

   - indexing/calling an ndarray with a string returns a TensorExpression
   object
   - these TensorExpression objects can be combined into a graph using
   operator overloads
   - and these graphs are translated to calls to BLAS or einsum, as is
   appropriate


#declare some symbols
i,j,ij,k = 'i','j','ij','k'
#we may force evaluation of a (sub) TensorExpression by calling it
#this is trivial to translate to call to einsum
#but such special cases could be dispatched to BLAS as well
b = (A(ij) * x(j)) (i)
#alternatively, we can predeclare a LHS which is automatically sized later
#note that this translates into the same call as the above; just some
syntactic sugar
b = np.empty(())
b[i] = A(ij) * x(j)
#more complex TensorExpression graphs of this form are trivial to translate
to a call to einsum as well
a(i)*b(j)*c(k)
#conceptually, there is no need to limit this scheme to multiplications
only!
#although such generalizations would require a more complex execution engine
#however, the revamped nditer should make this quite managable to implement
a(i)*b(j) + c(k)
#if axes strings are omitted, standard numpy broadcasting rules are applied
to the expressiongraph created
#this is identical to a*b+c; except that we have the opportunity to
eliminate temporaries
a()*b()+c()


Note that such an approach kills quite some birds with one stone
it allows for the elimination of temporaries along the lines of numexpr

But if i could write:
b[i] = A[ij] * x[j]
I would much prefer that over
b = A @ x
even though the latter is shorter

Now if i had n input and output vectors, it would be easy what to do with
them:
b[ni] = A[ij] * x[nj]

As i argued earlier, I much prefer this form of explicitness over
conventions about what constitutes a row or column vector. And
vectorization of linear algebra is a trivial extension in this manner,
which in itself is just a subset of even more general multilinear products,
which themselves are a subset of more general expression involving things
other than products

Its a somewhat ambitious idea, and there are probably reasons why it isnt a
good idea as well, but it does not require python language modifications,
and it does not clash with any other functionality or syntax of numpy, as
far as i can tell. Calling of arrays is not yet defined, and alternatively
array indexing could be overloaded on string type.

Either way, something to chew on when deciding on the best way to go
forward.




On Tue, Mar 18, 2014 at 4:28 AM, Mark Daoust daoust...@gmail.com wrote:

 On Mon, Mar 17, 2014 at 8:54 PM, Nathaniel Smith n...@pobox.com wrote:


 But, this is actually a feature! Because obviously what *should* be
 returned in this case is *not* (Mat @ vec) @ Mat, *or* Mat @ (vec @
 Mat). Both of those answers are terrible; it's just, if you have an
 ordinary left-/right-associative operator, those are your only
 options. What *should* be returned is an error. And in this scheme we
 get to see the whole @ expression at once, so we actually can raise an
 error for such things.



 Sorry if this is a little off topic.

 But there's still something about the vector examples that bugs me,
 matrix@vector and vector@@2, keep popping up (this also applies to
 the matrix@matrix examples to a lesser extent).

 I'm a little unconformable looking at the shape to to decide what's a
 matrix and what's a vector. (Matlab has some problems like this)

 If it only has one or two dimensions it's easy, but I always find that if
 I've written code that works for 1 matrix or vector, 5 minutes later I want
 it to work for fields of matrices or vectors. If we're just going by shape
 there's no way to distinguish between a 2d field of matrices and a 3d field
 of vectors.

 I guess this is a repeat of part of what Eelco Hoogendoorn saying a few
 posts back

 I was just wondering if anyone sees a place, to get @ a little closer to
 Einsum, for some sort of array class that understands the difference
 between a 4D array of scalars, a 3D array of vectors, and a 2D array of
 matrices... The difference between the axes that broad-cast and the axes
 that can sum when you hit them with an @ ... or something like that.

 Just a thought.

 Einsum is fantastic by the way, totally worth learning and using.




 Mark Daoust

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


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


Re: [Numpy-discussion] [help needed] associativity and precedence of '@'

2014-03-18 Thread Sebastian Haase
Just add one vote:  I am for
* right association *
because  1) I'm thinking of matrix multiplication more like operators,
which I also learned to work from right to left and because 2) I would
put a vector to the right, which would result in better performance.

I don't have an opinion on tight/same/ or weak (maybe that means
then 'same' because it's easier to remember !?)

My two cents,
Sebastian Haase


On Tue, Mar 18, 2014 at 7:13 AM, Eelco Hoogendoorn
hoogendoorn.ee...@gmail.com wrote:


 Perhaps this a bit of a thread hyjack; but this discussion got me thinking
 about how to arrive

 at a more vectorized/tensorified way of specifying linear algebra
 operations, in an elegant manner.

 I probably got a little carried away, but what about this syntax?

 indexing/calling an ndarray with a string returns a TensorExpression object
 these TensorExpression objects can be combined into a graph using operator
 overloads
 and these graphs are translated to calls to BLAS or einsum, as is
 appropriate


 #declare some symbols
 i,j,ij,k = 'i','j','ij','k'
 #we may force evaluation of a (sub) TensorExpression by calling it
 #this is trivial to translate to call to einsum
 #but such special cases could be dispatched to BLAS as well
 b = (A(ij) * x(j)) (i)
 #alternatively, we can predeclare a LHS which is automatically sized later
 #note that this translates into the same call as the above; just some
 syntactic sugar
 b = np.empty(())
 b[i] = A(ij) * x(j)
 #more complex TensorExpression graphs of this form are trivial to translate
 to a call to einsum as well
 a(i)*b(j)*c(k)
 #conceptually, there is no need to limit this scheme to multiplications
 only!
 #although such generalizations would require a more complex execution engine
 #however, the revamped nditer should make this quite managable to implement
 a(i)*b(j) + c(k)
 #if axes strings are omitted, standard numpy broadcasting rules are applied
 to the expressiongraph created
 #this is identical to a*b+c; except that we have the opportunity to
 eliminate temporaries
 a()*b()+c()


 Note that such an approach kills quite some birds with one stone
 it allows for the elimination of temporaries along the lines of numexpr

 But if i could write:

 b[i] = A[ij] * x[j]
 I would much prefer that over
 b = A @ x
 even though the latter is shorter

 Now if i had n input and output vectors, it would be easy what to do with
 them:

 b[ni] = A[ij] * x[nj]

 As i argued earlier, I much prefer this form of explicitness over
 conventions about what constitutes a row or column vector. And vectorization
 of linear algebra is a trivial extension in this manner, which in itself is
 just a subset of even more general multilinear products, which themselves
 are a subset of more general expression involving things other than products

 Its a somewhat ambitious idea, and there are probably reasons why it isnt a
 good idea as well, but it does not require python language modifications,
 and it does not clash with any other functionality or syntax of numpy, as
 far as i can tell. Calling of arrays is not yet defined, and alternatively
 array indexing could be overloaded on string type.

 Either way, something to chew on when deciding on the best way to go
 forward.





 On Tue, Mar 18, 2014 at 4:28 AM, Mark Daoust daoust...@gmail.com wrote:

 On Mon, Mar 17, 2014 at 8:54 PM, Nathaniel Smith n...@pobox.com wrote:


 But, this is actually a feature! Because obviously what *should* be
 returned in this case is *not* (Mat @ vec) @ Mat, *or* Mat @ (vec @
 Mat). Both of those answers are terrible; it's just, if you have an
 ordinary left-/right-associative operator, those are your only
 options. What *should* be returned is an error. And in this scheme we
 get to see the whole @ expression at once, so we actually can raise an
 error for such things.



 Sorry if this is a little off topic.

 But there's still something about the vector examples that bugs me,
 matrix@vector and vector@@2, keep popping up (this also applies to the
 matrix@matrix examples to a lesser extent).

 I'm a little unconformable looking at the shape to to decide what's a
 matrix and what's a vector. (Matlab has some problems like this)

 If it only has one or two dimensions it's easy, but I always find that if
 I've written code that works for 1 matrix or vector, 5 minutes later I want
 it to work for fields of matrices or vectors. If we're just going by shape
 there's no way to distinguish between a 2d field of matrices and a 3d field
 of vectors.

 I guess this is a repeat of part of what Eelco Hoogendoorn saying a few
 posts back

 I was just wondering if anyone sees a place, to get @ a little closer to
 Einsum, for some sort of array class that understands the difference between
 a 4D array of scalars, a 3D array of vectors, and a 2D array of matrices...
 The difference between the axes that broad-cast and the axes that can sum
 when you hit them with an @ ... or something like that.

 Just a thought.

 Einsum 

Re: [Numpy-discussion] [help needed] associativity and precedence of '@'

2014-03-18 Thread Robert Kern
On Tue, Mar 18, 2014 at 12:54 AM, Nathaniel Smith n...@pobox.com wrote:
 On Sat, Mar 15, 2014 at 6:28 PM, Nathaniel Smith n...@pobox.com wrote:
 Mathematica: instead of having an associativity, a @ b @ c gets
 converted into mdot([a, b, c])

 So, I've been thinking about this (thanks to @rfateman for pointing it
 out), and wondering if Mathematica's approach is worth following up
 more. (It would need to make it past python-dev, of course, but worst
 case is just that they say no and we're back where we are now, so we
 might as well think it through.)

I predict with near-certainty that this will be rejected, but that
doesn't prevent it from derailing the discussion. This proposal is
unlike anything else in Python. Chained comparisons are *not* similar
to this proposal. The chaining only happens at the syntax level, not
the semantics. `a  b  c` gets compiled down to `a.__lt__(b) and
b.__lt__(c)`, not `do_comparison([a, b, c], [lt, lt])`.

We have approval for a binary @ operator. Take the win.

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


Re: [Numpy-discussion] [help needed] associativity and precedence of '@'

2014-03-18 Thread Eelco Hoogendoorn
To elaborate a little on such a more general and explicit method of
specifying linear operations (perhaps 'expressions with named axes' is a
good nomer to cover this topic).

I think indexing rather than calling is preferable. I worried at first
about the performance overhead of checking for strings at every indexing
op, but get ndarray__getitem__ is already quite a complex beast anyway, and
adding (yet another) type test on its args isn't a significant difference.
For those who disagree; we could also approach strings with a 'forgiveness
is better then permission' attitude.

The general rules could be: if no string args, everything works as normal.
In case of string args, we may think of the effect of __getitem__ as
indexing with strings replaced by colons first, and then creating a
NamedAxisIndexExpression (NAIE), associating the given string label with
each corresponding axis. Thus, we can write things like A[0:3,'i']

As some additional rules; string arguments can be 'expanded', the string is
split on commas if present, and otherwise split into characters, which are
then the axis labels.

In expressions, all non-labeled axes are treated in sequential order,
similar to the ... construct, and have standard numpy broadcasting
semantics.

The only problem with [] notation is field name lookup; though I have
always felt that tables with named columns should be an ndarray subtype,
given their fundamentally different indexing semantics.

Realizing the full potential of such an approach would be a complex
undertaking, but to start with, a more elegant interface to np.einsum would
be rather easy to implement.


On Tue, Mar 18, 2014 at 9:46 AM, Sebastian Haase seb.ha...@gmail.comwrote:

 Just add one vote:  I am for
 * right association *
 because  1) I'm thinking of matrix multiplication more like operators,
 which I also learned to work from right to left and because 2) I would
 put a vector to the right, which would result in better performance.

 I don't have an opinion on tight/same/ or weak (maybe that means
 then 'same' because it's easier to remember !?)

 My two cents,
 Sebastian Haase


 On Tue, Mar 18, 2014 at 7:13 AM, Eelco Hoogendoorn
 hoogendoorn.ee...@gmail.com wrote:
 
 
  Perhaps this a bit of a thread hyjack; but this discussion got me
 thinking
  about how to arrive
 
  at a more vectorized/tensorified way of specifying linear algebra
  operations, in an elegant manner.
 
  I probably got a little carried away, but what about this syntax?
 
  indexing/calling an ndarray with a string returns a TensorExpression
 object
  these TensorExpression objects can be combined into a graph using
 operator
  overloads
  and these graphs are translated to calls to BLAS or einsum, as is
  appropriate
 
 
  #declare some symbols
  i,j,ij,k = 'i','j','ij','k'
  #we may force evaluation of a (sub) TensorExpression by calling it
  #this is trivial to translate to call to einsum
  #but such special cases could be dispatched to BLAS as well
  b = (A(ij) * x(j)) (i)
  #alternatively, we can predeclare a LHS which is automatically sized
 later
  #note that this translates into the same call as the above; just some
  syntactic sugar
  b = np.empty(())
  b[i] = A(ij) * x(j)
  #more complex TensorExpression graphs of this form are trivial to
 translate
  to a call to einsum as well
  a(i)*b(j)*c(k)
  #conceptually, there is no need to limit this scheme to multiplications
  only!
  #although such generalizations would require a more complex execution
 engine
  #however, the revamped nditer should make this quite managable to
 implement
  a(i)*b(j) + c(k)
  #if axes strings are omitted, standard numpy broadcasting rules are
 applied
  to the expressiongraph created
  #this is identical to a*b+c; except that we have the opportunity to
  eliminate temporaries
  a()*b()+c()
 
 
  Note that such an approach kills quite some birds with one stone
  it allows for the elimination of temporaries along the lines of numexpr
 
  But if i could write:
 
  b[i] = A[ij] * x[j]
  I would much prefer that over
  b = A @ x
  even though the latter is shorter
 
  Now if i had n input and output vectors, it would be easy what to do with
  them:
 
  b[ni] = A[ij] * x[nj]
 
  As i argued earlier, I much prefer this form of explicitness over
  conventions about what constitutes a row or column vector. And
 vectorization
  of linear algebra is a trivial extension in this manner, which in itself
 is
  just a subset of even more general multilinear products, which themselves
  are a subset of more general expression involving things other than
 products
 
  Its a somewhat ambitious idea, and there are probably reasons why it
 isnt a
  good idea as well, but it does not require python language modifications,
  and it does not clash with any other functionality or syntax of numpy, as
  far as i can tell. Calling of arrays is not yet defined, and
 alternatively
  array indexing could be overloaded on string type.
 
  Either way, something to 

Re: [Numpy-discussion] [help needed] associativity and precedence of '@'

2014-03-18 Thread Christophe Bal
*About weak-left.* You need to define a priority of @ the matrix product
regarding to * the elementwise product because (A*B)@C  A*(B@C) : see the
example above. I say that also from a mathematical point of view.

Using mathematical like notations, Matrix1 * Matrix2 * 3 can be written
because (Matrix1 * Matrix2) * 3 = Matrix1 * (Matrix2 * 3).

That's why I think that the weak-left is the better choice.

*About group implementation.* I think the idea of calculating A@B@C as
__atmul__([A,B,C]) is a very good idea because this allows efficient
implementations.

*-*
*[1 2]*
*A = [3 4]*

*[5 6]*
*B = [7 8]*

*[a d]*
*C = [b c]*

*-*
*(A*B)@C*
*=*
*[5  12]   [a d]*
*[21 32] @ [b c]*
*=*
*[5a+12b  5d+12c ]*
*[21a+32b 21d+32c]*

*-*
*A*(B@C)*
*=*
*[1 2]   [5a+6b 5d+6c]*
*[3 4] * [7a+8b 7d+8c]*
*=*
*[5a+6b   10d+12c]*
*[21a+24b 28d+32c]*



2014-03-18 10:50 GMT+01:00 Eelco Hoogendoorn hoogendoorn.ee...@gmail.com:

 To elaborate a little on such a more general and explicit method of
 specifying linear operations (perhaps 'expressions with named axes' is a
 good nomer to cover this topic).

 I think indexing rather than calling is preferable. I worried at first
 about the performance overhead of checking for strings at every indexing
 op, but get ndarray__getitem__ is already quite a complex beast anyway, and
 adding (yet another) type test on its args isn't a significant difference.
 For those who disagree; we could also approach strings with a 'forgiveness
 is better then permission' attitude.

 The general rules could be: if no string args, everything works as normal.
 In case of string args, we may think of the effect of __getitem__ as
 indexing with strings replaced by colons first, and then creating a
 NamedAxisIndexExpression (NAIE), associating the given string label with
 each corresponding axis. Thus, we can write things like A[0:3,'i']

 As some additional rules; string arguments can be 'expanded', the string
 is split on commas if present, and otherwise split into characters, which
 are then the axis labels.

 In expressions, all non-labeled axes are treated in sequential order,
 similar to the ... construct, and have standard numpy broadcasting
 semantics.

 The only problem with [] notation is field name lookup; though I have
 always felt that tables with named columns should be an ndarray subtype,
 given their fundamentally different indexing semantics.

 Realizing the full potential of such an approach would be a complex
 undertaking, but to start with, a more elegant interface to np.einsum would
 be rather easy to implement.


 On Tue, Mar 18, 2014 at 9:46 AM, Sebastian Haase seb.ha...@gmail.comwrote:

 Just add one vote:  I am for
 * right association *
 because  1) I'm thinking of matrix multiplication more like operators,
 which I also learned to work from right to left and because 2) I would
 put a vector to the right, which would result in better performance.

 I don't have an opinion on tight/same/ or weak (maybe that means
 then 'same' because it's easier to remember !?)

 My two cents,
 Sebastian Haase


 On Tue, Mar 18, 2014 at 7:13 AM, Eelco Hoogendoorn
 hoogendoorn.ee...@gmail.com wrote:
 
 
  Perhaps this a bit of a thread hyjack; but this discussion got me
 thinking
  about how to arrive
 
  at a more vectorized/tensorified way of specifying linear algebra
  operations, in an elegant manner.
 
  I probably got a little carried away, but what about this syntax?
 
  indexing/calling an ndarray with a string returns a TensorExpression
 object
  these TensorExpression objects can be combined into a graph using
 operator
  overloads
  and these graphs are translated to calls to BLAS or einsum, as is
  appropriate
 
 
  #declare some symbols
  i,j,ij,k = 'i','j','ij','k'
  #we may force evaluation of a (sub) TensorExpression by calling it
  #this is trivial to translate to call to einsum
  #but such special cases could be dispatched to BLAS as well
  b = (A(ij) * x(j)) (i)
  #alternatively, we can predeclare a LHS which is automatically sized
 later
  #note that this translates into the same call as the above; just some
  syntactic sugar
  b = np.empty(())
  b[i] = A(ij) * x(j)
  #more complex TensorExpression graphs of this form are trivial to
 translate
  to a call to einsum as well
  a(i)*b(j)*c(k)
  #conceptually, there is no need to limit this scheme to multiplications
  only!
  #although such generalizations would require a more complex execution
 engine
  #however, the revamped nditer should make this quite managable to
 implement
  a(i)*b(j) + c(k)
  #if axes strings are omitted, standard numpy broadcasting rules are
 applied
  to the expressiongraph created
  #this is identical to a*b+c; except that we have the opportunity to
  eliminate temporaries
  a()*b()+c()
 
 
  Note that such an approach kills quite some birds with one stone
  it allows for the elimination of temporaries along the lines of numexpr
 
  

Re: [Numpy-discussion] [help needed] associativity and precedence of '@'

2014-03-18 Thread Robert Kern
On Tue, Mar 18, 2014 at 3:22 PM, Christophe Bal projet...@gmail.com wrote:
 About weak-left. You need to define a priority of @ the matrix product
 regarding to * the elementwise product because (A*B)@C  A*(B@C) : see the
 example above. I say that also from a mathematical point of view.

What example above?

 Using mathematical like notations, Matrix1 * Matrix2 * 3 can be written
 because (Matrix1 * Matrix2) * 3 = Matrix1 * (Matrix2 * 3).

This seems to argue against what you just said.

 That's why I think that the weak-left is the better choice.

But this is true as well:

  3 * Matrix1 * Matrix2 = (3 * Matrix1) * Matrix2 = 3 * (Matrix1 * Matrix2)

Does that expression argue for tight-left?

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


Re: [Numpy-discussion] [help needed] associativity and precedence of '@'

2014-03-18 Thread Christophe Bal
Strange, Gmail has cut my example.

Here it is normally.

*[1 2]*
*A = [3 4]*

*[5 6]*
*B = [7 8]*

*[a d]*
*C = [b c]*

*(A*B)@C*
*=*
*[5  12]   [a d]*
*[21 32] @ [b c]*
*=*
*[5a+12b  5d+12c ]*
*[21a+32b 21d+32c]*

*A*(B@C)*
*=*
*[1 2]   [5a+6b 5d+6c]*
*[3 4] * [7a+8b 7d+8c]*
*=*
*[5a+6b   10d+12c]*
*[21a+24b 28d+32c]*


2014-03-18 16:29 GMT+01:00 Robert Kern robert.k...@gmail.com:

 On Tue, Mar 18, 2014 at 3:22 PM, Christophe Bal projet...@gmail.com
 wrote:
  About weak-left. You need to define a priority of @ the matrix product
  regarding to * the elementwise product because (A*B)@C  A*(B@C) : see
 the
  example above. I say that also from a mathematical point of view.

 What example above?

  Using mathematical like notations, Matrix1 * Matrix2 * 3 can be written
  because (Matrix1 * Matrix2) * 3 = Matrix1 * (Matrix2 * 3).

 This seems to argue against what you just said.

  That's why I think that the weak-left is the better choice.

 But this is true as well:

   3 * Matrix1 * Matrix2 = (3 * Matrix1) * Matrix2 = 3 * (Matrix1 * Matrix2)

 Does that expression argue for tight-left?

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

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


Re: [Numpy-discussion] [help needed] associativity and precedence of '@'

2014-03-18 Thread Christophe Bal
When I write using mathematical like notations..., Matrix1 * Matrix2 is a
matrix multiplication.
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] [help needed] associativity and precedence of '@'

2014-03-18 Thread Nathaniel Smith
On Tue, Mar 18, 2014 at 9:50 AM, Eelco Hoogendoorn
hoogendoorn.ee...@gmail.com wrote:
 To elaborate a little on such a more general and explicit method of
 specifying linear operations (perhaps 'expressions with named axes' is a
 good nomer to cover this topic).
[...]

This is a good topic to bring up on numpy-discussion, but maybe you
should start a new thread? That way it's both more likely to be
noticed by interested parties, and also it will make it easier for me
to keep track of what's going on in this thread, which is about a
specific concrete decision we need to make ;-).

-n

-- 
Nathaniel J. Smith
Postdoctoral researcher - Informatics - University of Edinburgh
http://vorpus.org
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] [help needed] associativity and precedence of '@'

2014-03-18 Thread Nathaniel Smith
On Tue, Mar 18, 2014 at 3:22 PM, Christophe Bal projet...@gmail.com wrote:
 About weak-left. You need to define a priority of @ the matrix product
 regarding to * the elementwise product because (A*B)@C  A*(B@C)

This doesn't follow.  (a / b) * c != a / (b * c), but / and * in
Python have the same priority.

-- 
Nathaniel J. Smith
Postdoctoral researcher - Informatics - University of Edinburgh
http://vorpus.org
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] _gufuncs_linalg module

2014-03-18 Thread Jay Bourque
I was just about to submit some pull requests for fixes to the
_gufuncs_linalg module and discovered that it no longer exists. It looks
like it was removed in this
commithttps://github.com/numpy/numpy/commit/0f516827dd081625b8b2262297be57ac855a9bb5.
Is there any reason why it was removed without any apparent discussion? It
looks like it was originally added in this
PRhttps://github.com/numpy/numpy/pull/3220after a long
discussion.

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


Re: [Numpy-discussion] [help needed] associativity and precedence of '@'

2014-03-18 Thread josef . pktd
I'm still bothered by what Nathaniel mentioned about mixing 1d and 2d arrays


 c = np.arange(4)
 a = np.arange(16).reshape(4,4)
 cc = c[:,None]

 a.dot(c).dot(c.T)
420

 a.dot(c.dot(c.T))
array([[  0,  14,  28,  42],
   [ 56,  70,  84,  98],
   [112, 126, 140, 154],
   [168, 182, 196, 210]])


 a.dot(cc).dot(cc.T)
array([[  0,  14,  28,  42],
   [  0,  38,  76, 114],
   [  0,  62, 124, 186],
   [  0,  86, 172, 258]])

 a.dot(cc.dot(cc.T))
array([[  0,  14,  28,  42],
   [  0,  38,  76, 114],
   [  0,  62, 124, 186],
   [  0,  86, 172, 258]])


hint:
 c.dot(c.T)
14

and I expect it will be a lot more fun if we mix in some 3d or nd arrays.


I think some of the decisions should not be driven by what is the most
convenient for the usual cases, but by how easy it is to read your code and
find the bugs where we made silly mistakes.


A biased view from someone who learned how to use numpy and scipy by
debugging.


Matlab and GAUSS are user friendly, they don't allow for reduced dimension
and never steal an axis in a reduce operation.

I didn't manage to come up with more difficult examples (and ran out of
time)

 (a.dot(c).dot(c.T)).dot(2*a)
Traceback (most recent call last):
  File stdin, line 1, in module
AttributeError: 'numpy.int32' object has no attribute 'dot'

If we make too many mistakes, then numpy tells us.
In the above examples, the scalar dot matrix would raise according to the
PEP.

I cannot come up with examples where we mix 3d and 2d and 1d because dot
currently doesn't do it.


sane-left

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


Re: [Numpy-discussion] [help needed] associativity and precedence of '@'

2014-03-18 Thread Christophe Bal
This is a different situation because / is indeed an hidden multiplication
: a/b = a*inv(b). The same is true for + and - : a-b=a+opp(b). What I'm
saying is that these operations * and / are indeed of the very same j-kind.

This is not the same for * and @.


2014-03-18 17:53 GMT+01:00 Nathaniel Smith n...@pobox.com:

 On Tue, Mar 18, 2014 at 3:22 PM, Christophe Bal projet...@gmail.com
 wrote:
  About weak-left. You need to define a priority of @ the matrix product
  regarding to * the elementwise product because (A*B)@C  A*(B@C)

 This doesn't follow.  (a / b) * c != a / (b * c), but / and * in
 Python have the same priority.

 --
 Nathaniel J. Smith
 Postdoctoral researcher - Informatics - University of Edinburgh
 http://vorpus.org
 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion

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


Re: [Numpy-discussion] _gufuncs_linalg module

2014-03-18 Thread Nathaniel Smith
On Tue, Mar 18, 2014 at 5:26 PM, Jay Bourque jay.bour...@continuum.io wrote:
 I was just about to submit some pull requests for fixes to the
 _gufuncs_linalg module and discovered that it no longer exists. It looks
 like it was removed in this commit. Is there any reason why it was removed
 without any apparent discussion? It looks like it was originally added in
 this PR after a long discussion.

IIRC the functionality was merged into umath_linalg.c.src?

-- 
Nathaniel J. Smith
Postdoctoral researcher - Informatics - University of Edinburgh
http://vorpus.org
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] [help needed] associativity and precedence of '@'

2014-03-18 Thread Nathaniel Smith
On 18 Mar 2014 17:32, Christophe Bal projet...@gmail.com wrote:

 This is a different situation because / is indeed an hidden
multiplication : a/b = a*inv(b). The same is true for + and - :
a-b=a+opp(b). What I'm saying is that these operations * and / are indeed
of the very same j-kind.

 This is not the same for * and @.

// (floordiv) isn't equivalent to a multiplication, but it is also at the
same level.  and  aren't inverses, but they are at the same level. 'in'
and 'is' are not even the same type (they have totally different
requirements on their right argument) but they are at the same level.
Whatever choice we make needs to be something we can justify, and our
justification should probably not imply that all of python's other
operators are wrong ;-).

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


Re: [Numpy-discussion] [help needed] associativity and precedence of '@'

2014-03-18 Thread Christophe Bal
I think that there is very big misunderstanding. My point of view is both a
mathematical and a programmagical one.
Le 18 mars 2014 20:20, Nathaniel Smith n...@pobox.com a écrit :

 On 18 Mar 2014 17:32, Christophe Bal projet...@gmail.com wrote:
 
  This is a different situation because / is indeed an hidden
 multiplication : a/b = a*inv(b). The same is true for + and - :
 a-b=a+opp(b). What I'm saying is that these operations * and / are indeed
 of the very same j-kind.
 
  This is not the same for * and @.

 // (floordiv) isn't equivalent to a multiplication, but it is also at the
 same level.  and  aren't inverses, but they are at the same level. 'in'
 and 'is' are not even the same type (they have totally different
 requirements on their right argument) but they are at the same level.
 Whatever choice we make needs to be something we can justify, and our
 justification should probably not imply that all of python's other
 operators are wrong ;-).

 -n

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


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


Re: [Numpy-discussion] _gufuncs_linalg module

2014-03-18 Thread Jay Bourque
Okay, it looks like the removal was part of this
PRhttps://github.com/numpy/numpy/pull/3880,
and that PR is referenced from this
issuehttps://github.com/numpy/numpy/issues/3217which mentions
needing more review and tests, and also lists several todo
items and open issues. I think that more or less answers my question.

-Jay


On Tue, Mar 18, 2014 at 12:36 PM, Nathaniel Smith n...@pobox.com wrote:

 On Tue, Mar 18, 2014 at 5:26 PM, Jay Bourque jay.bour...@continuum.io
 wrote:
  I was just about to submit some pull requests for fixes to the
  _gufuncs_linalg module and discovered that it no longer exists. It looks
  like it was removed in this commit. Is there any reason why it was
 removed
  without any apparent discussion? It looks like it was originally added in
  this PR after a long discussion.

 IIRC the functionality was merged into umath_linalg.c.src?

 --
 Nathaniel J. Smith
 Postdoctoral researcher - Informatics - University of Edinburgh
 http://vorpus.org
 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion

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


[Numpy-discussion] Dates and times and Datetime64 (again)

2014-03-18 Thread Sankarshan Mudkavi
Hey all,

It's been a while since the last datetime and timezones discussion thread was 
visited (linked below):

http://thread.gmane.org/gmane.comp.python.numeric.general/53805

It looks like the best approach to follow is the UTC only approach in the 
linked thread with an optional flag to indicate the timezone (to avoid 
confusing applications where they don't expect any timezone info). Since this 
is slightly more useful than having just a naive datetime64 package and would 
be open to extension if required, it's probably the best way to start improving 
the datetime64 library.

If we do wish to have full timezone support it would very likely lead to 
performance drops (as reasoned in the thread) and we would need to have a 
dedicated, maintained tzinfo package, at which point it would make much more 
sense to just incorporate the pytz library. (I also don't have the expertise to 
implement this, so I would be unable to help resolve the current logjam)

I would like to start writing a NEP for this followed by implementation, 
however I'm not sure what the format etc. is, could someone direct me to a page 
where this information is provided?

Please let me know if there are any ideas, comments etc.

Cheers,
Sankarshan


signature.asc
Description: Message signed with OpenPGP using GPGMail
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] [RFC] should we argue for a matrix power operator, @@?

2014-03-18 Thread Ondřej Čertík
On Mon, Mar 17, 2014 at 11:30 AM, Fernando Perez fperez@gmail.com wrote:
 On Mon, Mar 17, 2014 at 10:01 AM, Aron Ahmadia a...@ahmadia.net wrote:


 On Mon, Mar 17, 2014 at 7:53 AM, Nathaniel Smith n...@pobox.com wrote:

 The thread so far, it sounds like the consensus answer is meh,
 whatever. So I'm thinking we should just drop @@ from the PEP, and if
 it turns out that this is a problem we can always revisit it in the
 ~3.6/3.7 timeframe.


 +1 from here.


 +1 too. Absent *clear* enthusiasm and support for new syntax/operators, I
 think being conservative and slow is the right approach. Just having @ will
 give us data and experience with this space, and it may become clear after
 one more cycle that we really need/want @@, or not, as the case may be.  But
 it's easier to add it later if we really need it than to remove it if it
 proves to be a bad idea, so +1 for moving slowly on this.

+1. Thanks Nathan for pushing this!

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


[Numpy-discussion] PR with changes to triangular array functions

2014-03-18 Thread Jaime Fernández del Río
I submitted a PR that makes some improvements to the numpy functions
dealing with triangular arrays. Aside from a general speed-up of about 2x
for most functions, there are some minor changes to the public API. In case
anyone is concerned about them, here's a list:

* 'np.tri' now accepts a boolean 'invert' kwarg that is equivalent to '1 -
np.tri' only faster.
* 'np.mask_indices' is no longer used by any of the triangular array
functions. While it is part of the public API, it is not even mentioned in
the documentation AFAICT. It may be a candidate for deprecation IMO.
* 'np.tril_indices' and 'np.triu_indices' now accept an 'm' kwarg to
indicate the number of columns of the array, so they are no longer
restricted to square arrays. The weird thing is that, to preserve the order
of the existing arguments, the signature is '(n, k=0, m=None)', while other
similar functions, such as 'np.tri', have signature '(n, m=None, k=0)'.
* 'np.triu_indices_from' and 'np.tril_indices_from' now also accept
rectangular arrays.

The PR can be found here:
https://github.com/numpy/numpy/pull/4509

Jaime
-- 
(\__/)
( O.o)
(  ) Este es Conejo. Copia a Conejo en tu firma y ayúdale en sus planes
de dominación mundial.
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] PR with changes to triangular array functions

2014-03-18 Thread Ralf Gommers
On Tue, Mar 18, 2014 at 11:21 PM, Jaime Fernández del Río 
jaime.f...@gmail.com wrote:

 I submitted a PR that makes some improvements to the numpy functions
 dealing with triangular arrays. Aside from a general speed-up of about 2x
 for most functions, there are some minor changes to the public API. In case
 anyone is concerned about them, here's a list:


Hi Jaime, I have no concerns but do want to say thank you for the excellent
summaries of your PRs that you send to the lists. Great to keep everyone
who doesn't follow Github activity informed, we should all be doing this
more often!

Cheers,
Ralf




 * 'np.tri' now accepts a boolean 'invert' kwarg that is equivalent to '1 -
 np.tri' only faster.
 * 'np.mask_indices' is no longer used by any of the triangular array
 functions. While it is part of the public API, it is not even mentioned in
 the documentation AFAICT. It may be a candidate for deprecation IMO.
 * 'np.tril_indices' and 'np.triu_indices' now accept an 'm' kwarg to
 indicate the number of columns of the array, so they are no longer
 restricted to square arrays. The weird thing is that, to preserve the order
 of the existing arguments, the signature is '(n, k=0, m=None)', while other
 similar functions, such as 'np.tri', have signature '(n, m=None, k=0)'.
 * 'np.triu_indices_from' and 'np.tril_indices_from' now also accept
 rectangular arrays.

 The PR can be found here:
 https://github.com/numpy/numpy/pull/4509

 Jaime
 --
 (\__/)
 ( O.o)
 (  ) Este es Conejo. Copia a Conejo en tu firma y ayúdale en sus planes
 de dominación mundial.

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


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


Re: [Numpy-discussion] Dates and times and Datetime64 (again)

2014-03-18 Thread Chris Barker
On Tue, Mar 18, 2014 at 2:49 PM, Sankarshan Mudkavi
smudk...@uwaterloo.cawrote:

 It's been a while since the last datetime and timezones discussion thread
 was visited (linked below):

 http://thread.gmane.org/gmane.comp.python.numeric.general/53805

 It looks like the best approach to follow is the UTC only approach in the
 linked thread with an optional flag to indicate the timezone (to avoid
 confusing applications where they don't expect any timezone info). Since
 this is slightly more useful than having just a naive datetime64 package
 and would be open to extension if required, it's probably the best way to
 start improving the datetime64 library.


IIUC, I agree -- which is why we need a NEP to specify the details. Thank
you for stepping up!

If we do wish to have full timezone support it would very likely lead to
 performance drops (as reasoned in the thread) and we would need to have a
 dedicated, maintained tzinfo package, at which point it would make much
 more sense to just incorporate the pytz library.


yup -- there is the option of doing what the stdlib datetime does --
provide a hook to incorporate timezone,s but don't provide
an implementation, unless that is a low-level hook that must
be implemented in C, it's going to be slow -- slow enough that you might as
well use a list of stdlib datetimes Also, this has gone far to long
without getting fixed -- we need something simple to implement more than
anything else.


 I would like to start writing a NEP for this followed by implementation,
 however I'm not sure what the format etc. is, could someone direct me to a
 page where this information is provided?


I don't know that there is such a thing, but you'll find the existing NEPS
here:

https://github.com/numpy/numpy/tree/master/doc/neps

I'd grab one and follow the format.


 Please let me know if there are any ideas, comments etc.


Thanks again -- I look forward to seeing it written up, -- I'm sure to have
something to say then!

-Chris


-- 

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/ORR(206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115   (206) 526-6317   main reception

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