On 10/26/06, David Joyner <[EMAIL PROTECTED]> wrote: > > I propose a block_matrix command be added to SAGE. > With all the linear algebra work being done by developers, I hesitate > to do it myself without asking first. Is adding that a good idea > right now? > > ++++++++++++++++++++++++++++++ > > Heidi wrote: > > That might work. I will have defined matrices A, B, and C, say. Then > > I'll construct a matrix > > > > [A B B B] > > [C A B B] > > [C C A B] > > [C C C A] > > > > using augment to make the rows and then stacking them in order.
I'd like to encourage the SAGE team to look into what numpy has established for all of the array-oriented work. Numpy 1.0 officially came out today, and it builds on more than 15 years of combined experience and tradition from Numeric and Numarray. There is a VAST amount of existing code which uses these APIs, and while some of the choices may not be perfect, much cleanup was done for numpy 1.0 (even at the expense of breaking backwards compatibility). I realize that the goals of SAGE and those of python/numpy/scipy are not the same, and I respect that. But at the same time, I hope that all in the SAGE team see the value of smooth interoperability between what SAGE offers and the well-established community of numerical/applied computing that uses numpy (or its predecessors). The numpy arrays are /very/ flexible objects, meant to provide not only basic arithmetic but also support for more sophisticated or special-purpose uses. There is a 'matrix' type meant for 2-dimensional matrix-type work (numpy's base arrays are more like arbitrary rank tensors), and arrays support 'record' access, which provides enormous amounts of flexibility (see http://www.scipy.org/RecordArrays for a simple introduction, or PyTables at http://www.pytables.org/moin for the kind of things that can be done with these). For example, the functionality proposed above is provided out of the box by numpy, and easily accessible with the r_ and c_ helper objects: In [53]: A,B,C Out[53]: (array([[0, 0], [0, 0]]), array([[5, 5], [5, 5]]), array([[9, 9], [9, 9]])) In [54]: r_[c_[A,B,B,B],c_[C,A,B,B],c_[C,C,A,B],c_[C,C,C,A]] Out[54]: array([[0, 0, 5, 5, 5, 5, 5, 5], [0, 0, 5, 5, 5, 5, 5, 5], [9, 9, 0, 0, 5, 5, 5, 5], [9, 9, 0, 0, 5, 5, 5, 5], [9, 9, 9, 9, 0, 0, 5, 5], [9, 9, 9, 9, 0, 0, 5, 5], [9, 9, 9, 9, 9, 9, 0, 0], [9, 9, 9, 9, 9, 9, 0, 0]]) In [55]: _.shape Out[55]: (8, 8) Here are the transpose and element-wise square: In [57]: _54.T Out[57]: array([[0, 0, 9, 9, 9, 9, 9, 9], [0, 0, 9, 9, 9, 9, 9, 9], [5, 5, 0, 0, 9, 9, 9, 9], [5, 5, 0, 0, 9, 9, 9, 9], [5, 5, 5, 5, 0, 0, 9, 9], [5, 5, 5, 5, 0, 0, 9, 9], [5, 5, 5, 5, 5, 5, 0, 0], [5, 5, 5, 5, 5, 5, 0, 0]]) In [58]: _54**2 Out[58]: array([[ 0, 0, 25, 25, 25, 25, 25, 25], [ 0, 0, 25, 25, 25, 25, 25, 25], [81, 81, 0, 0, 25, 25, 25, 25], [81, 81, 0, 0, 25, 25, 25, 25], [81, 81, 81, 81, 0, 0, 25, 25], [81, 81, 81, 81, 0, 0, 25, 25], [81, 81, 81, 81, 81, 81, 0, 0], [81, 81, 81, 81, 81, 81, 0, 0]]) I am sure that SAGE will find places where you'll have good reasons to implement your own ideas and diverge from numpy. But I'd like to very strongly encourage you to not reinvent any existing wheels there or diverge unless you really need to. IMO, the long-term impact and interoperability of SAGE with the rest of the 'scientific python ecosystem' will be greatly enhanced if you play along with numpy at this early stage in your design. The time invested in familiarizing yourselves with the numpy array protocol (the basic interoperability interface, planned for inclusion in python itself in the future and already supported by other libraries such as the Python Imaging Library) and the rest of numpy's design and API will be, I think, time well spent. And the numpy and scipy lists will welcome any questions that SAGE devs may have on this front. Regards, f --~--~---------~--~----~------------~-------~--~----~ 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/ -~----------~----~----~----~------~----~------~--~---