← Back to team overview

ufl team mailing list archive

Re: UFL and Python built-in functions

 


Johan Hake wrote:
> On Saturday 23 January 2010 08:36:34 Garth N. Wells wrote:
>> Anders Logg wrote:
>>> On Sat, Jan 23, 2010 at 10:35:03AM +0000, Garth N. Wells wrote:
>>>> I've run into an issue when using 'exp' on a Coefficient/Function. In a
>>>> .ufl file, I can use
>>>>
>>>>   M = exp(T)
>>>>
>>>> where T is a Coefficient without problems. Using PyDOLFIN, I get the
>>>> error:
>>>>
>>>>   AttributeError: exp
>>>>
>>>> Could this be that the Python version of exp is being called, rather
>>>> than the UFL version? How can I check in Python which 'exp' function is
>>>> being called?
>>>>
>>>> Garth
>>> print should work. With UFL, I expect you would get something like
>>>
>>> # print exp
>>> <function exp at 0x2673aa0>
>> This is what I get when running ffc on a .ufl file and it works.
>>
>>> Otherwise something like
>>>
>>> # print exp
>>> <ufunc 'exp'>
>> This is what I get from PyDOLFIN and it breaks. Is this likely to be
>> what causes my problem? Any ideas on how to fix it?
> 
> You can remove the last line in dolfin/__init__.py:
> 
>   from numpy import sin, cos, exp
>

I removed this line and now it works great. Thanks.

Garth


> I suppose these are exposed to the dolfin interface so they can be used when 
> sub classing Expression in Python. However with ufl and the mature compile 
> function interface I think these functions should be removed. 
> 
> If they are used in any demo, one can import them from the correct module, 
> which should be math instead of numpy (as the usage is not vectorized), either 
> as:
> 
>   from math import exp as mexp
>   ...
>      def eval(self, values, x):
>          values[0] = mexp(x[0])
> 
> or just:
> 
>   import math
>   ...
>      def eval(self, values, x):
>          values[0] = math.exp(x[0])
> 
> Johan
> 
>> Garth
>>
>>
>> _______________________________________________
>> Mailing list: https://launchpad.net/~ufl
>> Post to     : ufl@xxxxxxxxxxxxxxxxxxx
>> Unsubscribe : https://launchpad.net/~ufl
>> More help   : https://help.launchpad.net/ListHelp
>>





References