From: James M. <mu...@pi...> - 2010-10-07 22:34:32
|
Bruce, On Oct 7, 2010, at 3:25 PM, Bruce Sherwood wrote: > The issue is that importing visual also imports math and numpy, and > does some tricky stuff to make sure that, for example, sqrt(scalar) > uses the fast math.sqrt routine, not the numpy.sqrt routine which is > much slower when acting on scalars. Is this really an issue? If you do > import numpy as np > import scipy as sp > import visual as vp > > a=np.sqrt(5) Does the fact that the vp namespace also includes numpy and math affect this (other than bloat)? on the other hand > from visual import * > from numpy import * Now you have replaced the visual version of sqrt with its check, with just the numpy one. I think what you are getting at is a questions of whether it is OK for visual to import math and numpy into its own namespace, and if not, how should visual do this branch? I don't really consider myself enough of an expert to comment. Perhaps someone else does. Actually it looks like visual imports cmath as well. > >>> a=-1 > >>> vp.sqrt([a]) > array([ NaN]) > >>> vp.sqrt(a) > > Traceback (most recent call last): > File "<pyshell#16>", line 1, in <module> > vp.sqrt(a) > File "/Library/Frameworks/Python.framework/Versions/Current/lib/python2.6/site-packages/visual/__init__.py", line 45, in _uf > if type(x) in mathtypes: return math(x) > ValueError: math domain error > >>> b=-1+0j > >>> vp.sqrt(b) > 1j > >>> vp.sqrt([b]) > array([ 0.+1.j]) -Jim |