Re: [Numpy-discussion] matrix power (was: matrix multiply)

2008-04-06 Thread Stéfan van der Walt
On 06/04/2008, Anne Archibald [EMAIL PROTECTED] wrote:
 On 05/04/2008, Stéfan van der Walt [EMAIL PROTECTED] wrote:

Some discussion recently took place around raising a square matrices
to integer powers.  See ticket #601:
  
http://scipy.org/scipy/numpy/ticket/601
  
Anne Archibald wrote a patch which factored 'matrix_multiply' out of
defmatrix (the matrix power implemented for the Matrix class).  After
some further discussion on irc, and some careful footwork so that
everything imports correctly, I checked in
  
http://projects.scipy.org/scipy/numpy/changeset/4968
  
The matrix_multiply method is exposed as numpy.linalg.matrix_multiply,
and is not in the top-level numpy namespace (it's a bit crowded there
already).  I'd be glad if you would review the changeset and comment.

  Just to be clear, the function is called matrix_power, not matrix_multiply.

Sorry, 05:00am is maybe not the time to write these posts.  Now there
is another good reason to review the changes :)

Cheers
Stéfan
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] Matrix powers

2008-04-06 Thread Nils Wagner
Hi all,

I tried to use the new function matrix_power, but I can't 
find it.

 matrix_power(array([[0,1],[-1,0]]),10)
Traceback (most recent call last):
   File stdin, line 1, in ?
NameError: name 'matrix_power' is not defined
 numpy.__version__
'1.0.5.dev4968'

Am I missing something ?

Nils
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Final push for NumPy 1.0.5 (I need your help!)

2008-04-06 Thread James Philbin
OK, here's a patch for:
#718: Bug with numpy.float32.tolist

Can someone commit it (I hope someone has committed the other patches
i've sent)?

James
--- arrayobject.c.old	2008-04-06 13:08:37.0 +0100
+++ arrayobject.c	2008-04-06 13:10:57.0 +0100
@@ -1870,8 +1870,11 @@
 
 if (!PyArray_Check(self)) return (PyObject *)self;
 
-if (self-nd == 0)
-return self-descr-f-getitem(self-data,self);
+if (self-nd == 0) {
+lp = PyList_New(1);
+PyList_SetItem(lp, 0, self-descr-f-getitem(self-data, self));
+return lp;
+}
 
 sz = self-dimensions[0];
 lp = PyList_New(sz);
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Final push for NumPy 1.0.5 (I need your help!)

2008-04-06 Thread Travis E. Oliphant
James Philbin wrote:
 OK, here's a patch for:
 #718: Bug with numpy.float32.tolist

 Can someone commit it (I hope someone has committed the other patches
 i've sent)?
   

I don't think this patch should be committed without more discussion.   
This changes behavior and it is intentional that tolist behaves as it 
does now. 

-Travis O.


___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Final push for NumPy 1.0.5 (I need your help!)

2008-04-06 Thread Alan G Isaac
On Sun, 6 Apr 2008, James Philbin apparently wrote:
 OK, here's a patch for:
 #718: Bug with numpy.float32.tolist 

My impression has always been that to ensure
a patch gets appropriate consideration it
should be attached to a ticket...

fwiw,
Alan Isaac



___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] matrix multiply

2008-04-06 Thread Alan G Isaac
On Sun, 6 Apr 2008, Stéfan van der Walt apparently wrote:
 I'd be glad if you would review the changeset and comment. 

Just checking:
it's important to me that this won't change
the behavior of boolean matrices, but I don't
see a test for this.  E.g., ::

 import numpy as N
 A = N.mat('1 0;1 1',dtype='bool')
 A**2
matrix([[ True, False],
[ True,  True]], dtype=bool)

Cheers,
Alan Isaac



___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] matrix multiply

2008-04-06 Thread Anne Archibald
On 06/04/2008, Alan G Isaac [EMAIL PROTECTED] wrote:

 Just checking:
  it's important to me that this won't change
  the behavior of boolean matrices, but I don't
  see a test for this.  E.g., ::

  import numpy as N
  A = N.mat('1 0;1 1',dtype='bool')
  A**2
 matrix([[ True, False],
 [ True,  True]], dtype=bool)

I have no desire to change the behaviour of boolean matrices, and I'll
write a test, but what is it supposed to do with them? Just produce
reduce(dot,[A]*n)? For zero it will give the identity, and for
negative powers some sort of floating-point inverse. Currently for
positive powers it should produce the right answer provided
multiplication is associative (which I think it is).

The inverse actually poses a problem: should it return (A**(-1))**n or
(A**n)**(-1)? (No, they're not the same for boolean matrices.)


Anne
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] matrix multiply

2008-04-06 Thread Alan G Isaac
 On 06/04/2008, Alan G Isaac [EMAIL PROTECTED] wrote: 
 Just checking:
  it's important to me that this won't change
  the behavior of boolean matrices, but I don't
  see a test for this.  E.g., ::

  import numpy as N
  A = N.mat('1 0;1 1',dtype='bool')
  A**2
 matrix([[ True, False],
 [ True,  True]], dtype=bool)

On Sun, 6 Apr 2008, Anne Archibald apparently wrote:
 I have no desire to change the behaviour of boolean matrices, and I'll 
 write a test, but what is it supposed to do with them? Just produce 
 reduce(dot,[A]*n)?

That's the part I care about.

 For zero it will give the identity,

Yes.

 and for negative powers some sort of floating-point 
 inverse.

That deserves discussion.
Not all invertible boolean matrices have an inverse in the algebra.
Just the orthogonal ones do.

I guess I would special case inverses for Boolean matrices.
Just test if the matrix B is orthogonal (under Boolean 
multiplication) and if so return B's transpose.

 Currently for positive powers it should produce the right 
 answer provided multiplication is associative (which 
 I think it is).

Yes; N×N boolean matrices are I believe a semi-group under multiplication.

 The inverse actually poses a problem: should it return 
 (A**(-1))**n or (A**n)**(-1)? (No, they're not the same 
 for boolean matrices.)

I think it must be the latter ... ?

By associativity, if B has an inverse A,
then B**n must have inverse A**n.
So you are observing that with boolean matrices
we might find B**n is invertible even though B is not.
Right?  So the latter will work in more cases.
So again: form B**n, test for orthogonality,
and return the transpose if the test passes.

Cheers,
Alan Isaac



___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] matrix multiply

2008-04-06 Thread Charles R Harris
On Sun, Apr 6, 2008 at 12:59 PM, Alan G Isaac [EMAIL PROTECTED] wrote:

  On 06/04/2008, Alan G Isaac [EMAIL PROTECTED] wrote:
  Just checking:
   it's important to me that this won't change
   the behavior of boolean matrices, but I don't
   see a test for this.  E.g., ::

   import numpy as N
   A = N.mat('1 0;1 1',dtype='bool')
   A**2
  matrix([[ True, False],
  [ True,  True]], dtype=bool)

 On Sun, 6 Apr 2008, Anne Archibald apparently wrote:
  I have no desire to change the behaviour of boolean matrices, and I'll
  write a test, but what is it supposed to do with them? Just produce
  reduce(dot,[A]*n)?

 That's the part I care about.

  For zero it will give the identity,

 Yes.

  and for negative powers some sort of floating-point
  inverse.

 That deserves discussion.
 Not all invertible boolean matrices have an inverse in the algebra.
 Just the orthogonal ones do.

 I guess I would special case inverses for Boolean matrices.
 Just test if the matrix B is orthogonal (under Boolean
 multiplication) and if so return B's transpose.

  Currently for positive powers it should produce the right
  answer provided multiplication is associative (which
  I think it is).

 Yes; N×N boolean matrices are I believe a semi-group under multiplication.


The boolean  algebra is a field and the correct addition is xor, which is
the same as addition modulo 2. This makes all matrices with determinant 1
invertible. This isn't the current convention, however, as it was when
Caratheodory was writing on measures and rings of sets were actually rings
and the symmetric difference was used instead of union.

Chuck
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Final push for NumPy 1.0.5 (I need your help!)

2008-04-06 Thread Stéfan van der Walt
On 06/04/2008, Alan G Isaac [EMAIL PROTECTED] wrote:
 On Sun, 6 Apr 2008, James Philbin apparently wrote:
   OK, here's a patch for:
   #718: Bug with numpy.float32.tolist


 My impression has always been that to ensure
  a patch gets appropriate consideration it
  should be attached to a ticket...

And, more importantly, it should be accompanied by a test (I'm guilty
on the float to string ticket mentioned above).  The test not only
verifies the patch's correct behaviour, but also guides the reviewer
in understanding possible use cases, as well as illustrating calling
convention.  Anything that saves the reviewer time improves your
chances of having the patch accepted.  Finally, it is also considerate
of his/her time: you wrote the patch and recently reviewed the code,
so writing a test takes you much less time than it would the reviewer.

That being said, I am very happy with the quality of patches recently
submitted by, amongst others, Pauli, Anne, David and Christoph.  Your
efforts are very much appreciated.

Regards
Stéfan
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] matrix multiply

2008-04-06 Thread Alan G Isaac
On Sun, 6 Apr 2008, Charles R Harris wrote:
 The boolean  algebra is a field and the correct addition is xor, which is 
 the same as addition modulo 2. This makes all matrices with determinant 1 
 invertible. This isn't the current convention, however, as it was when 
 Caratheodory was writing on measures and rings of sets were actually rings 
 and the symmetric difference was used instead of union. 

I am not sure what you are suggesting for matrix behavior,
nor what correct means here.

Comment:
Standard *boolean algebra* axioms include distributivity, but
1 xor (0 and 0) = 1 xor 0 = 1
(1 xor 0) and (1 xor 0) = 1 and 1 = 1

So I guess (?) what you are saying is something like:
if we have a boolen algebra with operators 'and' and 'or',
we can generate a boolean ring with operations 'xor' and 'and'.
When we do so, the '+' is traditionally used for the 'xor' operation.

But where in the modern literature on boolean matrices is
'+' given this interpretation?

IANAM,*
Alan Isaac

* IANAM = I am not a mathematician.




___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] matrix multiply

2008-04-06 Thread Charles R Harris
On Sun, Apr 6, 2008 at 2:34 PM, Alan G Isaac [EMAIL PROTECTED] wrote:

 On Sun, 6 Apr 2008, Charles R Harris wrote:
  The boolean  algebra is a field and the correct addition is xor, which
 is
  the same as addition modulo 2. This makes all matrices with determinant
 1
  invertible. This isn't the current convention, however, as it was when
  Caratheodory was writing on measures and rings of sets were actually
 rings
  and the symmetric difference was used instead of union.

 I am not sure what you are suggesting for matrix behavior,
 nor what correct means here.

 Comment:
 Standard *boolean algebra* axioms include distributivity, but
 1 xor (0 and 0) = 1 xor 0 = 1
 (1 xor 0) and (1 xor 0) = 1 and 1 = 1

 So I guess (?) what you are saying is something like:
 if we have a boolen algebra with operators 'and' and 'or',
 we can generate a boolean ring with operations 'xor' and 'and'.
 When we do so, the '+' is traditionally used for the 'xor' operation.

 But where in the modern literature on boolean matrices is
 '+' given this interpretation?


It's generally not. It used to be that \Sigma and + were used for set union,
probably because that was what the printers had on hand and what the
mathematicians were used to. Then there was the alternate desire to make
boolean algebra conform to the standad ring structure which led to using the
symmetric difference, \Delta. For instance, if + is 'or', then 1 has no
additive inverse, whereas 1 xor 1 = 0. I'm just pointing to some of the
history here that I've noticed in old papers. I prefer the modern usage
myself as it is closer to the accepted logic operations, but applying
algebraic manipulations like powers and matrix inverses in that context
leads to strange results.

Chuck
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] New project : Spyke python-to-C compiler

2008-04-06 Thread Rahul Garg
Note this message has been posted to numpy-discussion and python-dev.
Sorry for the multiple posting but I thought both python devs and
numpy users will be interested. If you believe your list should not  
receive this email, let me know. Also I just wanted to introduce  
myself since I may ask doubts about Python and Numpy internals from  
time to time :)

Hi.

I am a student at Univ of Alberta doing my masters in computing science.
I am writing a Python-to-C compiler as one part of my thesis.
The compiler, named Spyke, will be made available in a couple of weeks
and is geared towards scientific applications and will therefore focus  
mostly on needs of scientific app developers.

What is Spyke?
In many performance critical projects, it is often necessary to
rewrite parts of the application in C. However writing C wrappers can
be time consuming. Spyke offers an alternative approach. You add  
annotations to your  Python code as strings. These strings are  
discarded by the Python
interpreter but these are interpreted as types by Spyke compiler to
convert to C.

Example :

int - int
def f(x): return 2*x

In this case the Spyke compiler will consider the string int - int
as a decalration that the function accepts int as parameter and
returns int. Spyke will then generate a C function and a wrapper  
function. This
idea is directly copied from PLW (Python Language Wrapper) project.
Once Python3k arrives, much of these declarations will be moved to
function annotations and class decorators.

This way you can do all your development and debugging interactively
using the standard Python interpreter. When you need to compile to C,
you just add type annotations to places that you want to convert and
invoke spyke on the annotated module. This is different from Pyrex
because Pyrex does not accept Python code. With Spyke, your code is
100% pure python.

Spyke has basic support for functions and classes. Spyke can do very  
basic type inference for local variables in function bodies. Spyke  
also has
partial support for homogenous lists and dictionaries and fixed length tuples.
One big advantage of Spyke is that it understands at least part of  
numpy. Numpy arrays  are treated as fundamental types and Spyke knows  
what C code to
generate for slicing/indexing of numpy arrays etc. This should help a
lot in scientific applications. Note that Spyke can handle only a
subset of Python. Exceptions, iterators, generators, runtime code
generation of any kind etc is not handled. Nested functions will be  
added soon. I will definitely add some of these missing features based  
on what is actually required for real world Python codes. Currently if  
Spyke does not understand a function, it  just leaves it as Python  
code. Classes can be handled but special
methods are not currently supported. The support of classes is a
little brittle because I am trying to resolve some issues b/w old and
new style of classes.

Where is Spyke?
Spyke will be available as a binary only release in a couple of weeks.
I intend to make it open source after a few months.
Spyke is written in Python and Java and should be platform independant.
I do intend to make the source open in a few months. Right now its
undergoing very rapid development and has negligible amounts of  
documentation so the source code right now is pretty useless to anyone  
else anyway.

I need help:
However I need a bit of help. I am having a couple of problems :
a) I am finding it hard to get pure Python+NumPy testing codes. I need
more codes to test the compiler. Developing a compiler without a  
test-suite is kind of useless. If you have some pure Python codes  
which need better performance, please contact me. I guarantee that  
your codes will not be released to public without your permission but   
might be referenced in academic publications. I can also make the   
compiler available to you hopefully after 10th of April. Its kind of   
unstable currently. I will also need your help in annotating the  
provided testing codes since I probably wont know what your  
application is doing.

b) Libraries which interface with C/C++ : Many codes in SciPy for
instance have mixed language codes. Part of the code is written in
C/C++. Spyke only knows how to annotated Python codes. For C/C++
libraries wrapped into Python modules, Spyke will therefore need to
know at least 2 things :
i) The mapping of a C function name/struct etc  to Python
ii) The type information of the said C function.

There are many many ways that people interact with C code. People
either write wrappers manually, or use autogenerated wrappers using
SWIG or SIP Boost.Python etc., use Pyrex or Cython while some people
use ctypes. I dont have the time or resources to support these
multitude of methods. I considered trying to parse the C code  
implementing wrappers but its non-trivial to put it mildly. Parsing  
only SWIG generated code is another possibility but its still hard.  
Another approach that I am 

Re: [Numpy-discussion] matrix multiply

2008-04-06 Thread Anne Archibald
   and for negative powers some sort of floating-point
   inverse.

 That deserves discussion.
  Not all invertible boolean matrices have an inverse in the algebra.
  Just the orthogonal ones do.

  I guess I would special case inverses for Boolean matrices.
  Just test if the matrix B is orthogonal (under Boolean
  multiplication) and if so return B's transpose.

This is actually a limitation of the whole linear algebra subsystem:
we only support floating-point linear algebra (apart from dot()).
There are algorithms for doing integer linear algebra, which might be
interesting to implement. But that's a big job. Boolean matrices as
you use them are another step again: because they are not a group
under +, almost all of linear algebra has to be reinterpreted. For
example it's not obvious that matrix multiplication is associative; it
turns out to be, because you can replace the matrices by integer
matrices containing ones for True and zeros for False, then do the
math, then interpret any nonzero integer as True, and zero as False.

As an aside, if you use + to mean xor (which I am not suggesting!)
all of linear algebra continues more or less unchanged; you're just
working over the field of integers modulo 2. If you want eigenvalues
you can pass to an algebraic closure.

   The inverse actually poses a problem: should it return
   (A**(-1))**n or (A**n)**(-1)? (No, they're not the same
   for boolean matrices.)

 I think it must be the latter ... ?

  By associativity, if B has an inverse A,
  then B**n must have inverse A**n.
  So you are observing that with boolean matrices
  we might find B**n is invertible even though B is not.
  Right?  So the latter will work in more cases.
  So again: form B**n, test for orthogonality,
  and return the transpose if the test passes.

Well, as it stands, since we have no integer linear algebra, inverses
are always floating-point. When you do that, you find that, for
example,
([[True,False],[True,True]]**(-1))**2 = [[1.,0.],[-2.,1.]]
but
([[True,False],[True,True]]**2)**(-1) = [[1.,0.],[-1.,1.]]

I am not aware of any algorithm for finding inverses, or even
determining which matrices are invertible, in the peculiar Boolean
arithmetic we use.

Anne
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Ticket #605 Incorrect behavior of numpy.histogram

2008-04-06 Thread Tommy Grav

On Apr 5, 2008, at 2:01 PM, Bruce Southey wrote:

 Hi,
 I have been investigating Ticket #605 'Incorrect behavior of
 numpy.histogram' (http://scipy.org/scipy/numpy/ticket/605 ).

I think that my preference depends on the definition of what
the bin number means. If the bin numbers are the lower bounds
of the bins (numpy default behavior) then it would make little
sense to exclude anything above the largest bin.

I don't have access to numpy on my laptop at the moment,
so I can't remember wether numpy has a keyword for what
the bins array is defining? Having this as a keyword of
(lower,middle,upper) of the bin would be very helpful.

Cheers
   Tommy
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] matrix multiply

2008-04-06 Thread Alan G Isaac
On Sun, 6 Apr 2008, Anne Archibald apparently wrote:
 I am not aware of any algorithm for finding inverses, or 
 even determining which matrices are invertible, in the 
 peculiar Boolean arithmetic we use. 

Again, it is *not* peculiar, it is very standard for
boolean matrices.  And with this behavior, a nonnegative
integer power has an obvious graph theoretic interpretation.

Such boolean matrices are obviously invertible if they
are orthogonal.  It turn out this is a necessary condition
as well. [1]_  Orthogonality is obviously easy to test.

Cheers,
Alan Isaac

.. [1]
   Luce, D., 1952, A Note on Boolean Matrix Theory,
   Proceeding of the Am. Math. Soc 3(3), p.382-8.



___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] matrix multiply

2008-04-06 Thread Alan G Isaac
On Sun, 6 Apr 2008, Charles R Harris apparently wrote:
 I prefer the modern usage myself as it is closer to the 
 accepted logic operations, but applying algebraic 
 manipulations like powers and matrix inverses in that 
 context leads to strange results. 

I have not really thought much about inverses,
but nonnegative integer powers have a natural
interpretation in graph theory (with the boolean
algebra operations, not the boolean ring operations).
This is exactly what I was requesting be preserved.

Cheers,
Alan Isaac



___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] ma's stdu and varu

2008-04-06 Thread Anne Archibald
Hi,

I was just going through tidying up the documentation for all the many
functions in numpy that compute standard deviations or variances (the
functions, the methods, the methods on matrices, the methods on
maskedarrays, all needed their docstrings updated in approximately the
same way). I noticed that maskedarrays seem to have the functions
stdu and varu, for computing the unbiased standard deviation and
variance (where one divides by N-1 rather than N). These are now
available, I think, via std and var with ddof=1. More seriously, they
still provide the peculiar older definition of var, where
varu([1,1.j,-1,-1.j])==0. I don't use maskedarrays, and in fact I
haven't been keeping track of what's going on with the two different
implementations. So: what should be done about stdu and varu? Do the
two implementations both need their definitions of std and var
examined?

Thanks,
Anne
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] matrix multiply

2008-04-06 Thread Charles R Harris
On Sun, Apr 6, 2008 at 8:51 PM, Alan G Isaac [EMAIL PROTECTED] wrote:

 On Sun, 6 Apr 2008, Charles R Harris apparently wrote:
  I prefer the modern usage myself as it is closer to the
  accepted logic operations, but applying algebraic
  manipulations like powers and matrix inverses in that
  context leads to strange results.

 I have not really thought much about inverses,
 but nonnegative integer powers have a natural
 interpretation in graph theory (with the boolean
 algebra operations, not the boolean ring operations).
 This is exactly what I was requesting be preserved.


You mean as edges in a directed graph? I suppose so, although graph
algorithms tend to use different structures, lists of lists, trees, and
such. I would think plain old integer matrices might actually carry more
information; let me count the ways. And positive matrices have their own
oddities. Hmm... I wonder what matrices over Z_2 mean in that context?

Chuck
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] New project : Spyke python-to-C compiler

2008-04-06 Thread Travis E. Oliphant
Rahul Garg wrote:
 Note this message has been posted to numpy-discussion and python-dev.
 Sorry for the multiple posting but I thought both python devs and
 numpy users will be interested. If you believe your list should not  
 receive this email, let me know. Also I just wanted to introduce  
 myself since I may ask doubts about Python and Numpy internals from  
 time to time :)
   
Hey Rahul,

This is a very interesting project.   I've been interested in something 
like this for a while.   I'd love to see more about what you are doing.

Best regards,

-Travis Oliphant

___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] New project : Spyke python-to-C compiler

2008-04-06 Thread Travis E. Oliphant

What will be the licensing of this project?  Do you know yet?

I have a couple of comments because I've been thinking along these lines.
 What is Spyke?
 In many performance critical projects, it is often necessary to
 rewrite parts of the application in C. However writing C wrappers can
 be time consuming. Spyke offers an alternative approach. You add  
 annotations to your  Python code as strings. These strings are  
 discarded by the Python
 interpreter but these are interpreted as types by Spyke compiler to
 convert to C.

 Example :

 int - int
 def f(x): return 2*x

 In this case the Spyke compiler will consider the string int - int
 as a decalration that the function accepts int as parameter and
 returns int. Spyke will then generate a C function and a wrapper  
 function.
What about the use of decorators in this case? 

Also, it would be great to be able to create ufuncs (and general numpy 
funcs) using this approach.   A decorator would work well here as well. 
 Where is Spyke?
 Spyke will be available as a binary only release in a couple of weeks.
 I intend to make it open source after a few months.
   
I'd like to encourage you to make it available as open source as early 
as possible.I think you are likely to get help in ways you didn't 
expect.  People are used to reading code, so even an alpha project can 
get help early. In fact given that you are looking for help.  I 
think this may be the best way to get it. 

If you need help getting set up in terms of hosting it somewhere, I can 
help you do that. 
 Spyke is written in Python and Java and should be platform independant.
 I do intend to make the source open in a few months. Right now its
 undergoing very rapid development and has negligible amounts of  
 documentation so the source code right now is pretty useless to anyone  
 else anyway.
   

 c) Strings as type declarations : Do you think I should use decorators
 instead at least for function type declarations?
   
I think you should use decorators.   That way you can work towards 
having the compiler embedded in the decorator and happen seamlessly 
without invoking a separte program (it just happens when the module is 
loaded -- a.l.a weave).

Best regards,

-Travis Oliphant



___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] ma's stdu and varu

2008-04-06 Thread Travis E. Oliphant
Anne Archibald wrote:
 Hi,

 I was just going through tidying up the documentation for all the many
 functions in numpy that compute standard deviations or variances (the
 functions, the methods, the methods on matrices, the methods on
 maskedarrays, all needed their docstrings updated in approximately the
 same way). I noticed that maskedarrays seem to have the functions
 stdu and varu, for computing the unbiased standard deviation and
 variance (where one divides by N-1 rather than N). These are now
 available, I think, via std and var with ddof=1. More seriously, they
 still provide the peculiar older definition of var, where
 varu([1,1.j,-1,-1.j])==0. I don't use maskedarrays, and in fact I
 haven't been keeping track of what's going on with the two different
 implementations. So: what should be done about stdu and varu? Do the
 two implementations both need their definitions of std and var
 examined?
   

Yes, the masked arrays should be changed and stdu and varu eliminated. 

-Travis


___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] matrix multiply

2008-04-06 Thread Alan G Isaac
On Sun, 6 Apr 2008, Charles R Harris apparently wrote:
 You mean as edges in a directed graph? 

Yes.

Naturally a boolean matrix is not the most compact
representation of a directed graph, especially a
sparse one.  However it can be convenient.

If B is a boolean matrix such that Bij=1 if there is
and edge from i to j, then B**2 has unit entries where
there is a path of length 2 from i to j.  The transitive
closure is similarly easy to represent (as a matrix power).

Cheers,
Alan Isaac



___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] matrix multiply

2008-04-06 Thread Charles R Harris
On Sun, Apr 6, 2008 at 10:38 PM, Alan G Isaac [EMAIL PROTECTED] wrote:

 On Sun, 6 Apr 2008, Charles R Harris apparently wrote:
  You mean as edges in a directed graph?

 Yes.

 Naturally a boolean matrix is not the most compact
 representation of a directed graph, especially a
 sparse one.  However it can be convenient.


I've had occasional thoughts of adding a computer science kit to scipy
with equivalence relations, trees, tries, graphs, and other such things that
come in handy for some sorts of problems.

Chuck
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion