[sage-support] Re: create a subdiagonal matrix quickly
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
On Jun 20, 2009, at 6:07 PM, rickhg12hs wrote: > > On Jun 19, 6:50 am, Pierre wrote: >> is there an easy way of creating a subdiagonal matrix, that is with 1 >> just under the diagonal and 0's elsewhere ? > > This is a hack (especially since I'm no mathematician and no expert in > Sage or any of its components), but it seems to work. A formal proof > would be an interesting read. > > Here's an example: > > n = 10 > m = matrix(ZZ,n) > m[range(n-1),range(n-1)] = identity_matrix(n-1) > m_subd = m.LLL() > > Works with some large n I played with. Another option 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] - 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
On Jun 19, 6:50 am, Pierre wrote: > is there an easy way of creating a subdiagonal matrix, that is with 1 > just under the diagonal and 0's elsewhere ? This is a hack (especially since I'm no mathematician and no expert in Sage or any of its components), but it seems to work. A formal proof would be an interesting read. Here's an example: n = 10 m = matrix(ZZ,n) m[range(n-1),range(n-1)] = identity_matrix(n-1) m_subd = m.LLL() Works with some large n I played with. Richard --~--~-~--~~~---~--~~ 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: How to doctest a pyx file?
On 20 Jun., 08:15, Simon King wrote: > Hi! > > On 19 Jun., 10:30, Simon King wrote: > > > Note that things worked in the past, when I had the following: > > - mtx.so was in the current directory > > - I set SAGE_PATH to the current directory > > - I did sage -t -long -optional mtx.pyx > > > What is the difference? > > Apparently the difference lies in Sage and not in my tests. I just > tried again the exact setting in which testing my extension modules > used to work -- now it fails, since "sage -t mtx.pyx" tries to compile > mtx.pyx for whatever reason. > Hi Simon, first of all: yes, you are right. A few versions ago, "sage -t ..." worked differently. I dimly remember one or two threads on sage-devel about people wanting to doctest arbitrary files in arbitrary directories, which didn't work as they expected back then. If I understand it correctly, the doctesting mechanism was changed, to be part of (or to make use of) the "load/attach" mechanism of Sage --- so if you can successfully "load" foobar.pyx into Sage, you also should be able to doctest it, with current Sage versions. But for most stuff which is greater than one file, the current behaviour is worse than it was before and is a regression IMHO. And also for me, these code changes did break some setup of mine, where I had installed own stuff in .../python/site-packages/... I could make doctesting my code (extension modules) work again in two hours or so mainly by inserting some of these infamous "#clib ..." "#cinclude ..." poor-man's pragmas I heartily dislike. If you wish, we could discuss this topic further and in depth on sage- devel (where it belongs), just open a thread there. > Couldn't "sage -t" just take any text file, search for "sage:" prompts > etc, and verify the output? > I didn't check it, but if you move all your doctests out of a *.pyx file into another file --- say a *.py file with the necessary "import"s --- then doctesting this new file should work fine. At least for me, this is not an alternative, because I want to have the doctests in the very same file and as close to the source code lines they test. > Another idea. > > Let "knight" be a (python) package or module. Is there a function > (say, recursive_doc_test) in Sage that does the doc tests for "knight" > and, recursively, for its contents (functions; classes; methods of > these classes; other modules, if knight is a package; ...) and returns > the results of the test as a string? I mean > sage: import knight > sage: recursive_doc_test(knight) > 'The following items had faiilures: > In knight.Ni.Shrubbery, l. 12: > expected: > "herring" > got: > nothing > ...' > > The line number would refer to the 12th line in the doc string of the > class knight.Ni.Shrubbery, say. > > Is there anything of that kind in sage? Should there be? > Doctesting is done on the shell level. There, you can say "sage -t mydir/" and all the files under "mydir" and its subdirectories are doctested in one go. Since python modules are grouped hierarchically, this comes very close to what you described. Any shell commands may be issued from inside Sage (since you can from within Python: "os.system ("command arguments")", and the output piped into a file or what you like. So essentially, everything is already there and available. But kind of low-level ... > The disadvantage would be that "recursive_doc_test" probably couldn't > test cdef-methods. > If inside Sage something "polished" existed as you describe it, most probably one *could* doctest cdef-methods with it. At least it should be written this way IMHO. Cheers, gsw > Cheers, > 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 -~--~~~~--~~--~--~---
[sage-support] Re: create a subdiagonal matrix quickly
> 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. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---