← Back to team overview

aesthete-team team mailing list archive

mpmath related diffs

 

Hi all, please find attached two diffs.

The first one allows mpmath to be loaded dynamically on an up to date Fedora 15 computer. It may not be necessary elsewhere so use with care.

The second one allows evaluation of things like sec(pi) by falling over to numericalization (is that a word?) of each argument before passing to eval. This may not work perfectly in every situation (try cos(-1)) but it's progress I think.

Regards,
Chris.
=== modified file 'aesthete/glypher/Dynamic.py'
--- aesthete/glypher/Dynamic.py	2011-11-05 01:22:26 +0000
+++ aesthete/glypher/Dynamic.py	2011-11-07 23:26:00 +0000
@@ -18,7 +18,13 @@
     '''This gives the evaluated code access to the sympy globals by a 'from
     sympy import *' in this closed-off module.'''
 
-    return eval(code, current_globals, {'args':args})
+    try:
+        return eval(code, current_globals, {'args':args})
+    except: # hack to get mpmath functions working
+        new_args = []
+        for arg in args:
+            new_args.append(N(arg))
+        return eval(code, current_globals, {'args':new_args})
 
 def eval_for_sympy(ent, code) :
     '''This gives the evaluated code access to the sympy globals by a 'from

=== modified file 'aesthete/glypher/glypher.py'
--- aesthete/glypher/glypher.py	2011-11-01 00:18:56 +0000
+++ aesthete/glypher/glypher.py	2011-11-07 03:07:19 +0000
@@ -8,6 +8,8 @@
     from sympy.polys.polytools import factor # 0.7.1
 import os
 import codecs
+import pkg_resources
+
 
 import sys, traceback
 from ..utils import debug_print
@@ -35,11 +37,20 @@
 default_font_size = 10.0
 default_rgb_colour = (1.0, 0.0, 0.0)
 
-libraries = {'sympy.mpmath' : False}
+try:
+    sympy_ver = pkg_resources.get_distribution("sympy").version # get version of sympy
+except:
+    sympy_ver = '0.6.7' # default to this if pkg_resources non-functional
+if sympy_ver == '0.7.1':
+    mpmath_lib = 'mpmath'
+else:
+    mpmath_lib = 'sympy.mpmath'
+
+libraries = {mpmath_lib : False}
 def set_library(name, mode=True) :
     if Dynamic.load_library(name, not mode) :
         libraries[name] = mode
-set_library('sympy.mpmath')
+set_library(mpmath_lib)
 
 bbox_mode = False
 stroke_mode = False


Follow ups