[sage-devel] Python Quick Reference...
This is one of the better all-in-one references to Python. I recommend grabbing the one big single page and saving it locally. http://rgruet.free.fr/#QuickRef -glenn -- Glenn H. Tarbox, PhD || 206-494-0819 || [EMAIL PROTECTED] "Don't worry about people stealing your ideas. If your ideas are any good you'll have to ram them down peoples throats" -- Howard Aiken --~--~-~--~~~---~--~~ 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://www.sagemath.org -~--~~~~--~~--~--~---
[sage-devel] Re: Pickling functions
This code pickles and unpickles functions. Note it is simi-hackish and I make no guarentee about it working in python 3.0 (but I'll be maintaining a copy for distributed stuff I'm working on for dev1. import new, types, copy_reg, cPickle #See python cookbook for more details def code_ctor(*args): return new.code(*args) def reduce_code(co): if co.co_freevars or co.co_cellvars: raise ValueError, "Cannot pickle code objects from closures" return code_ctor, (co.co_argcount, co.co_nlocals, co.co_stacksize, \ co.co_flags, co.co_code, co.co_consts, co.co_names, \ co.co_varnames, co.co_filename, co.co_name, \ co.co_firstlineno, co.co_lnotab) copy_reg.pickle(types.CodeType, reduce_code) def picklefunction(func): return cPickle.dumps(func.func_code) def unpicklefunction(pickled): recovered = cPickle.loads(pickled) ret = new.function(recovered, globals()) return ret On Sat, Jun 14, 2008 at 11:25 AM, David Roe <[EMAIL PROTECTED]> wrote: > > One way to get around this limitation in python is to use callable > classes instead of functions. > David > > On Sat, Jun 14, 2008 at 10:42 AM, David Harvey > <[EMAIL PROTECTED]> wrote: >> >> On Jun 14, 2008, at 1:25 PM, Daniel Bump wrote: >> >> >> Some code that has been proposed by Nicolas Thiery >> for sage/combinat/families.py would create classes >> that have as attributes dictionaries of functions. >> However dumps(s) will raise an exception if s is >> such a class instance. >> Example: the simple reflections in a Weyl group. See: >> http://groups.google.com/group/sage-combinat-devel/msg/8b987cd471db3493?hl=en >> What it boils down to is this. The following is >> fine in native Python: >> >> import pickle >> def f(x): return x+1 >> >> ... >> >> pickle.dumps(f) >> >> 'c__main__\nf\np0\n.' >> >> pickle.dumps({1:f}) >> >> '(dp0\nI1\nc__main__\nf\np1\ns.' >> But if you try to run this from within Sage, >> both calls to dumps() will raise exceptions. >> Is this a bug in Sage? >> >> I actually thought you couldn't really pickle functions, even in plain >> python. >> http://docs.python.org/lib/node317.html >> "Note that functions (built-in and user-defined) are pickled by ``fully >> qualified'' name reference, not by value. This means that only the function >> name is pickled, along with the name of module the function is defined in. >> Neither the function's code, nor any of its function attributes are pickled. >> Thus the defining module must be importable in the unpickling environment, >> and the module must contain the named object, otherwise an exception will be >> raised." >> david >> >> > >> > > > > --~--~-~--~~~---~--~~ 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://www.sagemath.org -~--~~~~--~~--~--~---
[sage-devel] Re: Pickling functions
One way to get around this limitation in python is to use callable classes instead of functions. David On Sat, Jun 14, 2008 at 10:42 AM, David Harvey <[EMAIL PROTECTED]> wrote: > > On Jun 14, 2008, at 1:25 PM, Daniel Bump wrote: > > > Some code that has been proposed by Nicolas Thiery > for sage/combinat/families.py would create classes > that have as attributes dictionaries of functions. > However dumps(s) will raise an exception if s is > such a class instance. > Example: the simple reflections in a Weyl group. See: > http://groups.google.com/group/sage-combinat-devel/msg/8b987cd471db3493?hl=en > What it boils down to is this. The following is > fine in native Python: > > import pickle > def f(x): return x+1 > > ... > > pickle.dumps(f) > > 'c__main__\nf\np0\n.' > > pickle.dumps({1:f}) > > '(dp0\nI1\nc__main__\nf\np1\ns.' > But if you try to run this from within Sage, > both calls to dumps() will raise exceptions. > Is this a bug in Sage? > > I actually thought you couldn't really pickle functions, even in plain > python. > http://docs.python.org/lib/node317.html > "Note that functions (built-in and user-defined) are pickled by ``fully > qualified'' name reference, not by value. This means that only the function > name is pickled, along with the name of module the function is defined in. > Neither the function's code, nor any of its function attributes are pickled. > Thus the defining module must be importable in the unpickling environment, > and the module must contain the named object, otherwise an exception will be > raised." > david > > > > --~--~-~--~~~---~--~~ 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://www.sagemath.org -~--~~~~--~~--~--~---
[sage-devel] Alex Martelli giving the SciPy 2008 Keynote
forwarding this announcement: -- Forwarded message -- From: Gael Varoquaux <[EMAIL PROTECTED]> Date: Sat, Jun 14, 2008 at 19:40 Subject: Alex Martelli giving the SciPy 2008 Keynote To: [EMAIL PROTECTED] On behalf of the SciPy2008 organizing committee, I am happy to announce that the Keynote at the conference will be given by Alex Martelli. It is a pleasure for us to receive Alex. He currently works as "Uber Tech Leader" at Google and is the author of two of the Python classics: "Python in a nutshell" and the "Python CookBook". Alex graduated in electronic engineering from the university of Bologna and worked in chip design first for Texas Instrument, and later for IBM Research. During the 8 years he spent at IBM, he gradually shifted from hardware design to software development while winning three Outstanding Technical Achievement Awards. Then he joined think3 inc., and Italian CAD company, as Senior Software Consultant where he developed libraries, network protocols, GUI engines, event frameworks, and web access frontends. After 12 years at think3, he worked for 3 years as a freelance consultant, mostly doing Python development, before joining Google. Alex won the 2002 Activators' Choice Award, and the 2006 Frank Willison award for outstanding contributions to the Python community. Alex has also taught courses on programming, development methods, object-oriented design, and numerical computing, at Ferrara University (Italy) and other venues. Alex's proudest achievement is the articles that appeared in Bridge World (January/February 2000), which were hailed as giant steps towards solving issues that had haunted contract-bridge game theoreticians for decades. This biography was loosely adapted from Alex's autobiography (http://www.aleax.it/bio.txt), more information can be found on his website http://www.aleax.it . Gaël -- Scipy2008 conference website: http://conference.scipy.org --~--~-~--~~~---~--~~ 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://www.sagemath.org -~--~~~~--~~--~--~---
[sage-devel] Re: Pickling functions
On Jun 14, 2008, at 1:25 PM, Daniel Bump wrote: > > > Some code that has been proposed by Nicolas Thiery > for sage/combinat/families.py would create classes > that have as attributes dictionaries of functions. > > However dumps(s) will raise an exception if s is > such a class instance. > > Example: the simple reflections in a Weyl group. See: > > http://groups.google.com/group/sage-combinat-devel/msg/ > 8b987cd471db3493?hl=en > > What it boils down to is this. The following is > fine in native Python: > import pickle def f(x): return x+1 > ... pickle.dumps(f) > 'c__main__\nf\np0\n.' pickle.dumps({1:f}) > '(dp0\nI1\nc__main__\nf\np1\ns.' > > But if you try to run this from within Sage, > both calls to dumps() will raise exceptions. > > Is this a bug in Sage? I actually thought you couldn't really pickle functions, even in plain python. http://docs.python.org/lib/node317.html "Note that functions (built-in and user-defined) are pickled by ``fully qualified'' name reference, not by value. This means that only the function name is pickled, along with the name of module the function is defined in. Neither the function's code, nor any of its function attributes are pickled. Thus the defining module must be importable in the unpickling environment, and the module must contain the named object, otherwise an exception will be raised." david --~--~-~--~~~---~--~~ 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://www.sagemath.org -~--~~~~--~~--~--~---
[sage-devel] Pickling functions
Some code that has been proposed by Nicolas Thiery for sage/combinat/families.py would create classes that have as attributes dictionaries of functions. However dumps(s) will raise an exception if s is such a class instance. Example: the simple reflections in a Weyl group. See: http://groups.google.com/group/sage-combinat-devel/msg/8b987cd471db3493?hl=en What it boils down to is this. The following is fine in native Python: >>> import pickle >>> def f(x): return x+1 ... >>> pickle.dumps(f) 'c__main__\nf\np0\n.' >>> pickle.dumps({1:f}) '(dp0\nI1\nc__main__\nf\np1\ns.' But if you try to run this from within Sage, both calls to dumps() will raise exceptions. Is this a bug in Sage? Dan --~--~-~--~~~---~--~~ 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://www.sagemath.org -~--~~~~--~~--~--~---
[sage-devel] Re: how to recognize integers from floats
On Sat, Jun 14, 2008 at 6:25 PM, Ondrej Certik <[EMAIL PROTECTED]> wrote: > On Sat, Jun 14, 2008 at 5:44 PM, Ondrej Certik <[EMAIL PROTECTED]> wrote: >> Hi, >> >> how can I distinguish Sage Integers and Floats without knowing >> anything about Sage? Originally I thought just by checking for __int__ >> and __float__ methods, >> but both Sage Integers and Floats define both __int__ and __float__. >> (Python ints and floats do that too.) >> >> So one can use some other method, for example both python ints and >> Sage Integers define __or__(), but python floats nor Sage Floats >> define it. But I find it quite fragile. >> One solution is to use the Integer._sympy_() method, but maybe there >> is some other way too? > > There is one found by Pearu Peterson: > > 1) if obj defines __complex__ and __float__ and > complex(obj)!=float(obj) then obj is complex, otherwise go to step 2) > 2) if obj defines __float__ and __int__ (or __long__) and > float(obj)!=int(obj) then obj is float, otherwise obj is integer Another option could be to use the __index__() method, even though it seems to me to be an abuse of it: In [1]: a = 5 In [2]: b = 5.5 In [3]: a.__index__() Out[3]: 5 In [4]: b.__index__() --- AttributeErrorTraceback (most recent call last) /home/ondra/ in () AttributeError: 'float' object has no attribute '__index__' Ondrej --~--~-~--~~~---~--~~ 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://www.sagemath.org -~--~~~~--~~--~--~---
[sage-devel] Re: how to recognize integers from floats
On Sat, Jun 14, 2008 at 5:44 PM, Ondrej Certik <[EMAIL PROTECTED]> wrote: > Hi, > > how can I distinguish Sage Integers and Floats without knowing > anything about Sage? Originally I thought just by checking for __int__ > and __float__ methods, > but both Sage Integers and Floats define both __int__ and __float__. > (Python ints and floats do that too.) > > So one can use some other method, for example both python ints and > Sage Integers define __or__(), but python floats nor Sage Floats > define it. But I find it quite fragile. > One solution is to use the Integer._sympy_() method, but maybe there > is some other way too? There is one found by Pearu Peterson: 1) if obj defines __complex__ and __float__ and complex(obj)!=float(obj) then obj is complex, otherwise go to step 2) 2) if obj defines __float__ and __int__ (or __long__) and float(obj)!=int(obj) then obj is float, otherwise obj is integer Ondrej --~--~-~--~~~---~--~~ 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://www.sagemath.org -~--~~~~--~~--~--~---
[sage-devel] how to recognize integers from floats
Hi, how can I distinguish Sage Integers and Floats without knowing anything about Sage? Originally I thought just by checking for __int__ and __float__ methods, but both Sage Integers and Floats define both __int__ and __float__. (Python ints and floats do that too.) So one can use some other method, for example both python ints and Sage Integers define __or__(), but python floats nor Sage Floats define it. But I find it quite fragile. One solution is to use the Integer._sympy_() method, but maybe there is some other way too? BTW, executing the following script in Sage fails: from sage.all import * class A(): def __int__(self): return 5 def __float__(self): return 5.5 a = A() #a = 5.5 var("x") print a*x - But it works when the "a = 5.5" line is uncommented. What is the difference between my A() class and a python float 5.5? Should Sage accept it? I think so. Ondrej --~--~-~--~~~---~--~~ 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://www.sagemath.org -~--~~~~--~~--~--~---
[sage-devel] Re: BLAS routines required by linbox are not installed
thanks!! it works now very well! On Jun 14, 12:01 am, mabshoff <[EMAIL PROTECTED]> wrote: > On Jun 13, 6:01 am, Harald Schilly <[EMAIL PROTECTED]> wrote: > > > On Jun 13, 1:24 pm, eduardo <[EMAIL PROTECTED]> wrote: > > Hi, > > > > SAGE in "/home/SAGE/sage-3.0.2" (as root) > > > IOError: [Errno 13] Permission denied: '/home/SAGE/sage-3.0.2/local/... > > > If you install (extract) something as root, the root is owner. You > > should give the ownership to yourself, or make it read/writeable to > > all > > try: > > cd /home/SAGE > > sudo chmod -R a+rw . > > and/or > > sudo chown -R ocampo:ocampo . > > The issue here is that Sage needs to rewrite a bunch of files on the > first start up after being moved/installed, so start Sage as root > once. Then as a user you do not need to have write access to use Sage. > If you want to develop you need to own the files, etc. > > > (if sudo gives an error, "su -"; passwords are your user or root/admin > > passwords) > > > h > > Cheers, > > Michael --~--~-~--~~~---~--~~ 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://www.sagemath.org -~--~~~~--~~--~--~---