[sage-devel] Re: Block matrices?
On Jan 9, 2008 3:23 AM, Robert Bradshaw [EMAIL PROTECTED] wrote: http://sagetrac.org/sage_trac/ticket/1732 2 questions about the patch: * Why is this function named block_sum? What are we summing? * Why are we limited to 4 arguments? Ideally, I would love to pass a list to this function and have it concatenate each matrix in the list (horizontally in the following case): A.block_matrix([A_1, A_2, ..., A_n]) You could pass the functions an argument, indicating the number of rows (or columns) you want so that you can do things like A = [ A1 A2] [ A3 A4] like this: A=block_matrix([A1,A2,A3,A4],num_cols=2*3,num_rows=None). Here each A is 3x3 and we are concatenating 2 of them in each row. On a more general note, block_sum as of 2.9.3 is really constructing a block diagonal matrix, isn't it? Why not call it block_diagonal? Of course, for now, it's only using one argument, why not pass it a list of matrices? Thoughts? didier On Jan 8, 2008, at 4:27 AM, vgermrk wrote: Is there a way to construct block matrices in SAGE? Not just the block_sum, augment and stack functions. As an example, let A, B, C, D be matrices and i want to construct a matrix like E=[[A,B],[C,D]] Such a feature would be very nice. -vgermrk- --~--~-~--~~~---~--~~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/ -~--~~~~--~~--~--~---
[sage-devel] Re: Block matrices?
I agree with Didier's comments. Judging from emails to the GAP support list (Which also has such a function), a block matrix function will be frequently used. I think it should be well-documented. On 1/10/08, didier deshommes [EMAIL PROTECTED] wrote: On Jan 9, 2008 3:23 AM, Robert Bradshaw [EMAIL PROTECTED] wrote: http://sagetrac.org/sage_trac/ticket/1732 2 questions about the patch: * Why is this function named block_sum? What are we summing? * Why are we limited to 4 arguments? Ideally, I would love to pass a list to this function and have it concatenate each matrix in the list (horizontally in the following case): A.block_matrix([A_1, A_2, ..., A_n]) You could pass the functions an argument, indicating the number of rows (or columns) you want so that you can do things like A = [ A1 A2] [ A3 A4] like this: A=block_matrix([A1,A2,A3,A4],num_cols=2*3,num_rows=None). Here each A is 3x3 and we are concatenating 2 of them in each row. On a more general note, block_sum as of 2.9.3 is really constructing a block diagonal matrix, isn't it? Why not call it block_diagonal? Of course, for now, it's only using one argument, why not pass it a list of matrices? Thoughts? didier On Jan 8, 2008, at 4:27 AM, vgermrk wrote: Is there a way to construct block matrices in SAGE? Not just the block_sum, augment and stack functions. As an example, let A, B, C, D be matrices and i want to construct a matrix like E=[[A,B],[C,D]] Such a feature would be very nice. -vgermrk- --~--~-~--~~~---~--~~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/ -~--~~~~--~~--~--~---
[sage-devel] Re: Block matrices?
These sound like good suggestions, I'll re-implement the richer functionality. On Jan 10, 2008, at 7:50 AM, didier deshommes wrote: On Jan 9, 2008 3:23 AM, Robert Bradshaw [EMAIL PROTECTED] wrote: http://sagetrac.org/sage_trac/ticket/1732 2 questions about the patch: * Why is this function named block_sum? What are we summing? * Why are we limited to 4 arguments? Ideally, I would love to pass a list to this function and have it concatenate each matrix in the list (horizontally in the following case): A.block_matrix([A_1, A_2, ..., A_n]) You could pass the functions an argument, indicating the number of rows (or columns) you want so that you can do things like A = [ A1 A2] [ A3 A4] like this: A=block_matrix([A1,A2,A3,A4],num_cols=2*3,num_rows=None). Here each A is 3x3 and we are concatenating 2 of them in each row. On a more general note, block_sum as of 2.9.3 is really constructing a block diagonal matrix, isn't it? Why not call it block_diagonal? Of course, for now, it's only using one argument, why not pass it a list of matrices? Thoughts? didier On Jan 8, 2008, at 4:27 AM, vgermrk wrote: Is there a way to construct block matrices in SAGE? Not just the block_sum, augment and stack functions. As an example, let A, B, C, D be matrices and i want to construct a matrix like E=[[A,B],[C,D]] Such a feature would be very nice. -vgermrk- --~--~-~--~~~---~--~~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/ -~--~~~~--~~--~--~---
[sage-devel] Re: Block matrices?
On Jan 10, 2008 9:16 AM, Robert Bradshaw [EMAIL PROTECTED] wrote: These sound like good suggestions, I'll re-implement the richer functionality. Quick question -- why does this even have to be another function? Couldn't we just expand the functionality of the matrix command, at least in some cases? That's how some other systems work. E.g., if A, B, C, D are all matrices of the same size, we could make matrix([[A,B], [C, D]]) (1) determine a ring that the base rings of A,B,C,D all map to, then (2) make the block matrix as mentioned above. We would know to do this because A,B,C,D are all of type MatrixElement and MatrixElements are not ring elements. (Issue: Square matrices could someday be ring elements but they aren't now.) For clarity we could have a disambuiguation, e.g., matrix([..], block=True) Anyway, to implement this would mean implementing exactly what you plan to do already with a block_matrix command, then just adding a quick hook to matrix(...) when one would otherwise get an error. William --~--~-~--~~~---~--~~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/ -~--~~~~--~~--~--~---
[sage-devel] Re: Block matrices?
On Jan 10, 8:19 pm, William Stein [EMAIL PROTECTED] wrote: On Jan 10, 2008 9:16 AM, Robert Bradshaw [EMAIL PROTECTED] wrote: These sound like good suggestions, I'll re-implement the richer functionality. Quick question -- why does this even have to be another function? Hi, just my 2 cents, extending the matrix-creation command is far better, because you just think this way. I would suggest even more (from the practical point of view) my ideas: 1. check if the matrices are compatible 2. not just 2x2, every possibility matrix-blocks. e.g. [A,B,A,B] or [[A,B,C],[B,B,C]] should work too. 3. If those blocks don't have equal dimensions, try if the smaller dimensions divide the biggest one. if true, then either repeat the smaller block or repeat it on the diagonal; if not true, error. diagonal means, if A is 4x4 and B 2x2: [A,B] = [A, identity-matrix(2) kronecker-symbol B] not diagonal: [A,B] = [A, ones(2) kronecker-symbol B] 4. if there is a mixture of matrices and numbers (elements of those matrices) interpret them as 1x1 matrices. e.g. if A is 4x4 and the diagonal switch is turned on: [A,3] = [A, identity(4) * 3] i think something in this direction could be very useful. also extending the repeat-layout to upper/lower triangles, band-diagonals (upper,lower,both sides) could be nice, too. H --~--~-~--~~~---~--~~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/ -~--~~~~--~~--~--~---
[sage-devel] Re: Block matrices?
On 10-Jan-08, at 11:44 AM, Harald Schilly wrote: On Jan 10, 8:19 pm, William Stein [EMAIL PROTECTED] wrote: On Jan 10, 2008 9:16 AM, Robert Bradshaw [EMAIL PROTECTED] wrote: These sound like good suggestions, I'll re-implement the richer functionality. Quick question -- why does this even have to be another function? Hi, just my 2 cents, extending the matrix-creation command is far better, because you just think this way. That may be true, but this function is already so overloaded that understanding the code is very difficult. I think that making matrix (...) accept more inputs will hide errors and hide intention; I vote for block_matrix and friends. As for replicating the matrix to make it fit, that's a terrible idea: hooray for difficult to diagnose bugs and confusing semantics. Nick --~--~-~--~~~---~--~~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/ -~--~~~~--~~--~--~---
[sage-devel] Re: Block matrices?
On Jan 10, 10:41 pm, Nick Alexander [EMAIL PROTECTED] wrote: That may be true, but this function is already so overloaded that understanding the code is very difficult. well, what if there are both functions and matrix just calls block_matrix if there are matrix objects in the list of arguments? i don't think code complexity is an issue there, since you can encapsulate all functionality in methods and at last, one of the main ideas behind object oriented programming with class hierarchies is that functions look the same but behave different depending on the object. from my point of view it is always more important to think of user friendliness (means less but more intelligent functions .. you can see this in the first posting, where this proposed extension is a logical try-and-error generalization to the current matrix command) and not of coding friendliness ;) As for replicating the matrix to make it fit, that's a terrible idea: hooray for difficult to diagnose bugs and confusing semantics. this should be discussed. for example there could be a safeguard: like a parameter 'replicate' with default value 'none'. then nothing happens, just an error message. it could be easily extended in the future by implementing replication methods ('diagonal', 'full', 'upper- triangle','band3',...) then there is no problem with unintended automatic behaviour and all extensions are backwards compatible. H --~--~-~--~~~---~--~~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/ -~--~~~~--~~--~--~---
[sage-devel] Re: Block matrices?
On 9 Jan., 08:25, Mike Hansen [EMAIL PROTECTED] wrote: It was my impression that he didn't want a matrix with matrix entries, but instead wanted the matrix whose entries were given by the entries of the submatrices. --Mike That's right. I should make myself more clearer next time. --~--~-~--~~~---~--~~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/ -~--~~~~--~~--~--~---
[sage-devel] Re: Block matrices?
http://sagetrac.org/sage_trac/ticket/1732 On Jan 8, 2008, at 4:27 AM, vgermrk wrote: Is there a way to construct block matrices in SAGE? Not just the block_sum, augment and stack functions. As an example, let A, B, C, D be matrices and i want to construct a matrix like E=[[A,B],[C,D]] Such a feature would be very nice. -vgermrk- --~--~-~--~~~---~--~~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/ -~--~~~~--~~--~--~---
[sage-devel] Re: Block matrices?
On Jan 8, 2008 4:27 AM, vgermrk [EMAIL PROTECTED] wrote: Is there a way to construct block matrices in SAGE? Not just the block_sum, augment and stack functions. As an example, let A, B, C, D be matrices and i want to construct a matrix like E=[[A,B],[C,D]] Such a feature would be very nice. Sage's MatrixSpace and matrix don't have support for this. numpy (which you get via import numpy) might have support for numerical matrices like this. --~--~-~--~~~---~--~~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/ -~--~~~~--~~--~--~---
[sage-devel] Re: Block matrices?
On Jan 9, 7:43 am, William Stein [EMAIL PROTECTED] wrote: On Jan 8, 2008 4:27 AM, vgermrk [EMAIL PROTECTED] wrote: Is there a way to construct block matrices in SAGE? Not just the block_sum, augment and stack functions. As an example, let A, B, C, D be matrices and i want to construct a matrix like E=[[A,B],[C,D]] Such a feature would be very nice. Sage's MatrixSpace and matrix don't have support for this. numpy (which you get via import numpy) might have support for numerical matrices like this. CVXOPT also has support for this: http://abel.ee.ucla.edu/cvxopt/examples/short-examples/creating-matrices/ Joachim --~--~-~--~~~---~--~~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/ -~--~~~~--~~--~--~---
[sage-devel] Re: Block matrices?
On Jan 8, 2008 11:05 PM, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: On Jan 9, 7:43 am, William Stein [EMAIL PROTECTED] wrote: On Jan 8, 2008 4:27 AM, vgermrk [EMAIL PROTECTED] wrote: Is there a way to construct block matrices in SAGE? Not just the block_sum, augment and stack functions. As an example, let A, B, C, D be matrices and i want to construct a matrix like E=[[A,B],[C,D]] Such a feature would be very nice. Sage's MatrixSpace and matrix don't have support for this. numpy (which you get via import numpy) might have support for numerical matrices like this. CVXOPT also has support for this: http://abel.ee.ucla.edu/cvxopt/examples/short-examples/creating-matrices/ And, just to be clear, CVXOPT is standard in Sage. There are a number of caveats though. Currently you really have to switch to python mode to create a cvxopt matrix in Sage, probably because of preparser issues (see below). Also, more importantly, it looks to me like making a matrix from matrices in CVXOPT does *not* make a matrix with matrix entries, but instead makes a single matrix -- see below. {{{id=0| %python from cvxopt.base import matrix A = matrix([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], (2,3)) print A /// 1.e+00 3.e+00 5.e+00 2.e+00 4.e+00 6.e+00 }}} {{{id=1| %python B = matrix([ [1.0, 2.0], [3.0, 4.0] ]) print B /// 1.e+00 3.e+00 2.e+00 4.e+00 }}} {{{id=2| %python a = matrix([ [A] ,[B] ]) }}} {{{id=4| print a /// 1.e+00 3.e+00 5.e+00 1.e+00 3.e+00 2.e+00 4.e+00 6.e+00 2.e+00 4.e+00 }}} --~--~-~--~~~---~--~~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/ -~--~~~~--~~--~--~---
[sage-devel] Re: Block matrices?
Sage's MatrixSpace and matrix don't have support for this. numpy (which you get via import numpy) might have support for numerical matrices like this. CVXOPT also has support for this: http://abel.ee.ucla.edu/cvxopt/examples/short-examples/creating-matri... And, just to be clear, CVXOPT is standard in Sage. There are a number of caveats though. Currently you really have to switch to python mode to create a cvxopt matrix in Sage, probably because of preparser issues (see below). Also, more importantly, it looks to me like making a matrix from matrices in CVXOPT does *not* make a matrix with matrix entries, but instead makes a single matrix -- see below. That is true; CVXOPT only supports 2-D numerical matrices, whereas Numpy supports N-D arrays of general objects. --~--~-~--~~~---~--~~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/ -~--~~~~--~~--~--~---
[sage-devel] Re: Block matrices?
It was my impression that he didn't want a matrix with matrix entries, but instead wanted the matrix whose entries were given by the entries of the submatrices. --Mike On Jan 8, 2008 11:12 PM, William Stein [EMAIL PROTECTED] wrote: On Jan 8, 2008 11:05 PM, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: On Jan 9, 7:43 am, William Stein [EMAIL PROTECTED] wrote: On Jan 8, 2008 4:27 AM, vgermrk [EMAIL PROTECTED] wrote: Is there a way to construct block matrices in SAGE? Not just the block_sum, augment and stack functions. As an example, let A, B, C, D be matrices and i want to construct a matrix like E=[[A,B],[C,D]] Such a feature would be very nice. Sage's MatrixSpace and matrix don't have support for this. numpy (which you get via import numpy) might have support for numerical matrices like this. CVXOPT also has support for this: http://abel.ee.ucla.edu/cvxopt/examples/short-examples/creating-matrices/ And, just to be clear, CVXOPT is standard in Sage. There are a number of caveats though. Currently you really have to switch to python mode to create a cvxopt matrix in Sage, probably because of preparser issues (see below). Also, more importantly, it looks to me like making a matrix from matrices in CVXOPT does *not* make a matrix with matrix entries, but instead makes a single matrix -- see below. {{{id=0| %python from cvxopt.base import matrix A = matrix([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], (2,3)) print A /// 1.e+00 3.e+00 5.e+00 2.e+00 4.e+00 6.e+00 }}} {{{id=1| %python B = matrix([ [1.0, 2.0], [3.0, 4.0] ]) print B /// 1.e+00 3.e+00 2.e+00 4.e+00 }}} {{{id=2| %python a = matrix([ [A] ,[B] ]) }}} {{{id=4| print a /// 1.e+00 3.e+00 5.e+00 1.e+00 3.e+00 2.e+00 4.e+00 6.e+00 2.e+00 4.e+00 }}} --~--~-~--~~~---~--~~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/ -~--~~~~--~~--~--~---
[sage-devel] Re: Block matrices?
That will be really easy to implement, I'll do it right now. - Robert On Jan 8, 2008, at 11:25 PM, Mike Hansen wrote: It was my impression that he didn't want a matrix with matrix entries, but instead wanted the matrix whose entries were given by the entries of the submatrices. --Mike On Jan 8, 2008 11:12 PM, William Stein [EMAIL PROTECTED] wrote: On Jan 8, 2008 11:05 PM, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: On Jan 9, 7:43 am, William Stein [EMAIL PROTECTED] wrote: On Jan 8, 2008 4:27 AM, vgermrk [EMAIL PROTECTED] wrote: Is there a way to construct block matrices in SAGE? Not just the block_sum, augment and stack functions. As an example, let A, B, C, D be matrices and i want to construct a matrix like E=[[A,B],[C,D]] Such a feature would be very nice. Sage's MatrixSpace and matrix don't have support for this. numpy (which you get via import numpy) might have support for numerical matrices like this. CVXOPT also has support for this: http://abel.ee.ucla.edu/cvxopt/examples/short-examples/creating- matrices/ And, just to be clear, CVXOPT is standard in Sage. There are a number of caveats though. Currently you really have to switch to python mode to create a cvxopt matrix in Sage, probably because of preparser issues (see below). Also, more importantly, it looks to me like making a matrix from matrices in CVXOPT does *not* make a matrix with matrix entries, but instead makes a single matrix -- see below. {{{id=0| %python from cvxopt.base import matrix A = matrix([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], (2,3)) print A /// 1.e+00 3.e+00 5.e+00 2.e+00 4.e+00 6.e+00 }}} {{{id=1| %python B = matrix([ [1.0, 2.0], [3.0, 4.0] ]) print B /// 1.e+00 3.e+00 2.e+00 4.e+00 }}} {{{id=2| %python a = matrix([ [A] ,[B] ]) }}} {{{id=4| print a /// 1.e+00 3.e+00 5.e+00 1.e+00 3.e+00 2.e+00 4.e+00 6.e+00 2.e+00 4.e+00 }}} --~--~-~--~~~---~--~~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/ -~--~~~~--~~--~--~---