[sage-support] Re: create a subdiagonal matrix quickly

2009-06-22 Thread Jason Grout

Rajeev Singh wrote:
 I should mention that these methods are all nice for this problem, but
 they also end up copying an awful lot of zeros.  I think it would be way
 more efficient in general to make a zero matrix, then set the right
 diagonal by hand using a for loop.
 
 
 Don't you think using a sparse matrix would be a better thing to do in 
 such situations?


I think that choice ought to be given to the user, in the usual 
sparse=True/False option.  If I'm doing a bunch of linear algebra on 
small dense matrices, it slows things down to have one sparse matrix in 
the mix.

I think the sparse option ought to default to False (i.e., default to 
dense) since that seems to be the current convention.

Jason


--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: create a subdiagonal matrix quickly

2009-06-21 Thread rickhg12hs

On Jun 20, 10:18 pm, Robert Bradshaw rober...@math.washington.edu
wrote:
 sage: n = 10
 sage: m = block_matrix([0, zero_matrix(1,1), identity_matrix(n), 0])
 sage: m.subdivide() # get rid of the block divisions
 sage: m
 [0 0 0 0 0 0 0 0 0 0 0]
 [1 0 0 0 0 0 0 0 0 0 0]
 [0 1 0 0 0 0 0 0 0 0 0]
 [0 0 1 0 0 0 0 0 0 0 0]
 [0 0 0 1 0 0 0 0 0 0 0]
 [0 0 0 0 1 0 0 0 0 0 0]
 [0 0 0 0 0 1 0 0 0 0 0]
 [0 0 0 0 0 0 1 0 0 0 0]
 [0 0 0 0 0 0 0 1 0 0 0]
 [0 0 0 0 0 0 0 0 1 0 0]
 [0 0 0 0 0 0 0 0 0 1 0]

 You can also use this to get anything you want on the sub-diagonal  
 (or pretty much anywhere).

 sage: m = block_matrix([0, zero_matrix(1,1), diagonal_matrix([10, 20,  
 30, 40]), 0]); m.subdivide(); m
 [ 0  0  0  0  0]
 [10  0  0  0  0]
 [ 0 20  0  0  0]
 [ 0  0 30  0  0]
 [ 0  0  0 40  0]

Very nice - I didn't know about block_matrix.  In addition, it seems
block_matrix has an optional argument subdivide.

sage: n = 10
sage: m = block_matrix([0, zero_matrix(1,1), identity_matrix(n),
0],subdivide=False)
sage: m
[0 0 0 0 0 0 0 0 0 0 0]
[1 0 0 0 0 0 0 0 0 0 0]
[0 1 0 0 0 0 0 0 0 0 0]
[0 0 1 0 0 0 0 0 0 0 0]
[0 0 0 1 0 0 0 0 0 0 0]
[0 0 0 0 1 0 0 0 0 0 0]
[0 0 0 0 0 1 0 0 0 0 0]
[0 0 0 0 0 0 1 0 0 0 0]
[0 0 0 0 0 0 0 1 0 0 0]
[0 0 0 0 0 0 0 0 1 0 0]
[0 0 0 0 0 0 0 0 0 1 0]

--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: create a subdiagonal matrix quickly

2009-06-21 Thread Jason Grout

rickhg12hs wrote:
 On Jun 20, 10:18 pm, Robert Bradshaw rober...@math.washington.edu
 wrote:
 sage: n = 10
 sage: m = block_matrix([0, zero_matrix(1,1), identity_matrix(n), 0])
 sage: m.subdivide() # get rid of the block divisions
 sage: m
 [0 0 0 0 0 0 0 0 0 0 0]
 [1 0 0 0 0 0 0 0 0 0 0]
 [0 1 0 0 0 0 0 0 0 0 0]
 [0 0 1 0 0 0 0 0 0 0 0]
 [0 0 0 1 0 0 0 0 0 0 0]
 [0 0 0 0 1 0 0 0 0 0 0]
 [0 0 0 0 0 1 0 0 0 0 0]
 [0 0 0 0 0 0 1 0 0 0 0]
 [0 0 0 0 0 0 0 1 0 0 0]
 [0 0 0 0 0 0 0 0 1 0 0]
 [0 0 0 0 0 0 0 0 0 1 0]

 You can also use this to get anything you want on the sub-diagonal  
 (or pretty much anywhere).

 sage: m = block_matrix([0, zero_matrix(1,1), diagonal_matrix([10, 20,  
 30, 40]), 0]); m.subdivide(); m
 [ 0  0  0  0  0]
 [10  0  0  0  0]
 [ 0 20  0  0  0]
 [ 0  0 30  0  0]
 [ 0  0  0 40  0]
 
 Very nice - I didn't know about block_matrix.  In addition, it seems
 block_matrix has an optional argument subdivide.
 
 sage: n = 10
 sage: m = block_matrix([0, zero_matrix(1,1), identity_matrix(n),
 0],subdivide=False)
 sage: m
 [0 0 0 0 0 0 0 0 0 0 0]
 [1 0 0 0 0 0 0 0 0 0 0]
 [0 1 0 0 0 0 0 0 0 0 0]
 [0 0 1 0 0 0 0 0 0 0 0]
 [0 0 0 1 0 0 0 0 0 0 0]
 [0 0 0 0 1 0 0 0 0 0 0]
 [0 0 0 0 0 1 0 0 0 0 0]
 [0 0 0 0 0 0 1 0 0 0 0]
 [0 0 0 0 0 0 0 1 0 0 0]
 [0 0 0 0 0 0 0 0 1 0 0]
 [0 0 0 0 0 0 0 0 0 1 0]
 


I should mention that these methods are all nice for this problem, but 
they also end up copying an awful lot of zeros.  I think it would be way 
more efficient in general to make a zero matrix, then set the right 
diagonal by hand using a for loop.

Jason




--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: create a subdiagonal matrix quickly

2009-06-21 Thread Rajeev Singh

 I should mention that these methods are all nice for this problem, but
 they also end up copying an awful lot of zeros.  I think it would be way
 more efficient in general to make a zero matrix, then set the right
 diagonal by hand using a for loop.


Don't you think using a sparse matrix would be a better thing to do in such
situations?

Rajeev

--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: create a subdiagonal matrix quickly

2009-06-20 Thread Robert Bradshaw

On Jun 20, 2009, at 3:08 AM, Pierre wrote:

 Of course, there are a lot of different pieces of software in the
 background. One strength of Sage is that it provides a uniform way of
 communicating with all these pieces of software, namely via Python/
 Cython. This is like a good travel agent: You say that you want to go
 from London to Liverpool, and the travel agent gives you the cheapest
 or fastest or most comfortable connection: You don't need to worry
 that there are various train companies in the background. (Also you
 don't need to go via Paris if you want to travel from Strasbourg to
 Calais -- sorry, I couldn't resist to mention a detail that I found
 odd when traveling in France :)

 that's about what i told him. Mind you the traveling metaphor is
 quite apt : indeed a good travel agency will get you all the tickets
 for different rides with different companies, but what if one train is
 late ? of course the next train, operated by another company, is not
 going to wait. (Been to england anyone ?) Then suddenly you have to
 worry about companies. That sort of thing can happen with sage : when
 one functionality isn't perfect yet, you can usually get around it by
 knowing that there are several ways of doing things, several pieces of
 software at work. Which means all needs to be perfect if we want to
 avoid the criticism... well, none of this is too serious of course,
 and i'll take care of that colleague personally! but i thought it was
 interesting to point out somebody's first impression on sage, albeit a
 curious one.

That is a very interesting first impression. For the most part, Sage  
seamlessly uses the many components underneath, and things are moving  
even more in this direction. Numerics, however, is one area where  
there is already a vibrant community around the SciPy/NumPy way of  
doing things, so exposing (rather than completely wrapping) lots of  
NumPy does have value.

- Robert


--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: create a subdiagonal matrix quickly

2009-06-19 Thread William Stein

On Fri, Jun 19, 2009 at 1:55 PM, Harald Schillyharald.schi...@gmail.com wrote:

 On Jun 19, 12:50 pm, Pierre pierre.guil...@gmail.com wrote:
 i know numpy does it, so is it there for sage matrices also ?

 i don't think so, how is the numpy syntax? I think this should be an
 enhancement to Sage's sage.matrix.constructor.diagonal_matrix
 function, introducing an offset parameter.

If A is a numpy array, you can do matrix(A) to get a Sage matrix.

William

--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: create a subdiagonal matrix quickly

2009-06-19 Thread Jason Grout

Harald Schilly wrote:
 On Jun 19, 12:50 pm, Pierre pierre.guil...@gmail.com wrote:
 i know numpy does it, so is it there for sage matrices also ?
 
 i don't think so, how is the numpy syntax? I think this should be an
 enhancement to Sage's sage.matrix.constructor.diagonal_matrix
 function, introducing an offset parameter.


+1.  That would make it more consistent with matlab too: diag (diagonal, 
offset).  The same syntax works for numpy.

I think William's solution is the easiest for now, unless you just want 
to write the short function to do it.

If someone wants to modify diagonal_matrix, and wants a little more 
ambitious project, they might work on #5110, which is basically pointing 
to a rewrite of diagonal_matrix at #3704 that languished and was never 
applied.

Jason


--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: create a subdiagonal matrix quickly

2009-06-19 Thread Simon King

Hi!

On 19 Jun., 18:50, Pierre pierre.guil...@gmail.com wrote:
 thanks for this. You might be amused by what my colleague said about
 SAGE, when we were talking about whether or not using numpy:

 SAGE is like the British train system: you have to worry about which
 company to use.

Correct me if I'm wrong, but isn't Sage's mission creating a UNIFORM
viable alternative to Ma*? Then I think this critique is something
that needs to be taken very serious: It shows that there are potential
users that have the impression that Sage is not uniform at all. I
believe it is a wrong impression.

A  possible reply to your colleague:

Of course, there are a lot of different pieces of software in the
background. One strength of Sage is that it provides a uniform way of
communicating with all these pieces of software, namely via Python/
Cython. This is like a good travel agent: You say that you want to go
from London to Liverpool, and the travel agent gives you the cheapest
or fastest or most comfortable connection: You don't need to worry
that there are various train companies in the background. (Also you
don't need to go via Paris if you want to travel from Strasbourg to
Calais -- sorry, I couldn't resist to mention a detail that I found
odd when traveling in France :)

Also of course, Sage isn't a perfect travel agent yet. There is some
functionality (here: of numpy) that can be used when working with
Sage, but the user needs to know where to find the functionality; this
is not uniform. If those examples pop up, I guess the natural way is
to open a ticket, submit a patch, and then another functionality is
available in a uniform way.

Best regards,
Simon

--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---