45 |
|
|
46 |
# def maximum(arg0,arg1): |
# def maximum(arg0,arg1): |
47 |
# def minimum(arg0,arg1): |
# def minimum(arg0,arg1): |
48 |
|
# def clip(arg,minval,maxval) |
49 |
|
|
50 |
# def transpose(arg,axis=None): |
# def transpose(arg,axis=None): |
51 |
# def trace(arg,axis0=0,axis1=1): |
# def trace(arg,axis0=0,axis1=1): |
364 |
@return : True if the argument is identical to zero. |
@return : True if the argument is identical to zero. |
365 |
@rtype : C{bool} |
@rtype : C{bool} |
366 |
""" |
""" |
367 |
try: |
if isinstance(arg,numarray.NumArray): |
368 |
return not Lsup(arg)>0. |
return not Lsup(arg)>0. |
369 |
except TypeError: |
elif isinstance(arg,escript.Data): |
370 |
|
return False |
371 |
|
elif isinstance(arg,float): |
372 |
|
return not Lsup(arg)>0. |
373 |
|
elif isinstance(arg,int): |
374 |
|
return not Lsup(arg)>0. |
375 |
|
elif isinstance(arg,Symbol): |
376 |
|
return False |
377 |
|
else: |
378 |
return False |
return False |
379 |
|
|
380 |
def matchType(arg0=0.,arg1=0.): |
def matchType(arg0=0.,arg1=0.): |
916 |
@raises TypeError: if the type of the argument is not expected. |
@raises TypeError: if the type of the argument is not expected. |
917 |
""" |
""" |
918 |
if isinstance(arg,numarray.NumArray): |
if isinstance(arg,numarray.NumArray): |
919 |
return numarray.greater(arg,numarray.zeros(arg.shape,numarray.Float)) |
out=numarray.greater(arg,numarray.zeros(arg.shape,numarray.Float)) |
920 |
|
if isinstance(out,float): out=numarray.array(out) |
921 |
|
return out |
922 |
elif isinstance(arg,escript.Data): |
elif isinstance(arg,escript.Data): |
923 |
return arg._wherePositive() |
return arg._wherePositive() |
924 |
elif isinstance(arg,float): |
elif isinstance(arg,float): |
998 |
@raises TypeError: if the type of the argument is not expected. |
@raises TypeError: if the type of the argument is not expected. |
999 |
""" |
""" |
1000 |
if isinstance(arg,numarray.NumArray): |
if isinstance(arg,numarray.NumArray): |
1001 |
return numarray.less(arg,numarray.zeros(arg.shape,numarray.Float)) |
out=numarray.less(arg,numarray.zeros(arg.shape,numarray.Float)) |
1002 |
|
if isinstance(out,float): out=numarray.array(out) |
1003 |
|
return out |
1004 |
elif isinstance(arg,escript.Data): |
elif isinstance(arg,escript.Data): |
1005 |
return arg._whereNegative() |
return arg._whereNegative() |
1006 |
elif isinstance(arg,float): |
elif isinstance(arg,float): |
1080 |
@raises TypeError: if the type of the argument is not expected. |
@raises TypeError: if the type of the argument is not expected. |
1081 |
""" |
""" |
1082 |
if isinstance(arg,numarray.NumArray): |
if isinstance(arg,numarray.NumArray): |
1083 |
return numarray.greater_equal(arg,numarray.zeros(arg.shape,numarray.Float)) |
out=numarray.greater_equal(arg,numarray.zeros(arg.shape,numarray.Float)) |
1084 |
|
if isinstance(out,float): out=numarray.array(out) |
1085 |
|
return out |
1086 |
elif isinstance(arg,escript.Data): |
elif isinstance(arg,escript.Data): |
1087 |
return arg._whereNonNegative() |
return arg._whereNonNegative() |
1088 |
elif isinstance(arg,float): |
elif isinstance(arg,float): |
1110 |
@raises TypeError: if the type of the argument is not expected. |
@raises TypeError: if the type of the argument is not expected. |
1111 |
""" |
""" |
1112 |
if isinstance(arg,numarray.NumArray): |
if isinstance(arg,numarray.NumArray): |
1113 |
return numarray.less_equal(arg,numarray.zeros(arg.shape,numarray.Float)) |
out=numarray.less_equal(arg,numarray.zeros(arg.shape,numarray.Float))*1. |
1114 |
|
if isinstance(out,float): out=numarray.array(out) |
1115 |
|
return out |
1116 |
elif isinstance(arg,escript.Data): |
elif isinstance(arg,escript.Data): |
1117 |
return arg._whereNonPositive() |
return arg._whereNonPositive() |
1118 |
elif isinstance(arg,float): |
elif isinstance(arg,float): |
1142 |
@raises TypeError: if the type of the argument is not expected. |
@raises TypeError: if the type of the argument is not expected. |
1143 |
""" |
""" |
1144 |
if isinstance(arg,numarray.NumArray): |
if isinstance(arg,numarray.NumArray): |
1145 |
return numarray.less_equal(abs(arg)-tol,numarray.zeros(arg.shape,numarray.Float)) |
out=numarray.less_equal(abs(arg)-tol,numarray.zeros(arg.shape,numarray.Float))*1. |
1146 |
|
if isinstance(out,float): out=numarray.array(out) |
1147 |
|
return out |
1148 |
elif isinstance(arg,escript.Data): |
elif isinstance(arg,escript.Data): |
1149 |
if tol>0.: |
if tol>0.: |
1150 |
return whereNegative(abs(arg)-tol) |
return whereNegative(abs(arg)-tol) |
1225 |
@raises TypeError: if the type of the argument is not expected. |
@raises TypeError: if the type of the argument is not expected. |
1226 |
""" |
""" |
1227 |
if isinstance(arg,numarray.NumArray): |
if isinstance(arg,numarray.NumArray): |
1228 |
return numarray.greater(abs(arg)-tol,numarray.zeros(arg.shape,numarray.Float)) |
out=numarray.greater(abs(arg)-tol,numarray.zeros(arg.shape,numarray.Float))*1. |
1229 |
|
if isinstance(out,float): out=numarray.array(out) |
1230 |
|
return out |
1231 |
elif isinstance(arg,escript.Data): |
elif isinstance(arg,escript.Data): |
1232 |
if tol>0.: |
if tol>0.: |
1233 |
return 1.-whereZero(arg,tol) |
return 1.-whereZero(arg,tol) |
2708 |
@raises TypeError: if the type of the argument is not expected. |
@raises TypeError: if the type of the argument is not expected. |
2709 |
""" |
""" |
2710 |
if isinstance(arg,numarray.NumArray): |
if isinstance(arg,numarray.NumArray): |
2711 |
return arg.min() |
if arg.rank==0: |
2712 |
|
return float(arg) |
2713 |
|
else: |
2714 |
|
return arg.min() |
2715 |
elif isinstance(arg,escript.Data): |
elif isinstance(arg,escript.Data): |
2716 |
return arg._minval() |
return arg._minval() |
2717 |
elif isinstance(arg,float): |
elif isinstance(arg,float): |
2785 |
@raises TypeError: if the type of the argument is not expected. |
@raises TypeError: if the type of the argument is not expected. |
2786 |
""" |
""" |
2787 |
if isinstance(arg,numarray.NumArray): |
if isinstance(arg,numarray.NumArray): |
2788 |
return arg.max() |
if arg.rank==0: |
2789 |
|
return float(arg) |
2790 |
|
else: |
2791 |
|
return arg.max() |
2792 |
elif isinstance(arg,escript.Data): |
elif isinstance(arg,escript.Data): |
2793 |
return arg._maxval() |
return arg._maxval() |
2794 |
elif isinstance(arg,float): |
elif isinstance(arg,float): |
3289 |
if out==None: |
if out==None: |
3290 |
out=a |
out=a |
3291 |
else: |
else: |
3292 |
m=whereNegative(out-a) |
diff=add(a,-out) |
3293 |
out=m*a+(1.-m)*out |
out=add(out,mult(wherePositive(diff),diff)) |
3294 |
return out |
return out |
3295 |
|
|
3296 |
def minimum(*arg): |
def minimum(*args): |
3297 |
""" |
""" |
3298 |
the minimum over arguments args |
the minimum over arguments args |
3299 |
|
|
3307 |
if out==None: |
if out==None: |
3308 |
out=a |
out=a |
3309 |
else: |
else: |
3310 |
m=whereNegative(out-a) |
diff=add(a,-out) |
3311 |
out=m*out+(1.-m)*a |
out=add(out,mult(whereNegative(diff),diff)) |
3312 |
return out |
return out |
3313 |
|
|
3314 |
|
def clip(arg,minval=0.,maxval=1.): |
3315 |
|
""" |
3316 |
|
cuts the values of arg between minval and maxval |
3317 |
|
|
3318 |
|
@param arg: argument |
3319 |
|
@type arg: L{numarray.NumArray}, L{escript.Data}, L{Symbol}, C{int} or C{float} |
3320 |
|
@param minval: lower range |
3321 |
|
@type arg: C{float} |
3322 |
|
@param maxval: uper range |
3323 |
|
@type arg: C{float} |
3324 |
|
@return: is on object with all its value between minval and maxval. value of the argument that greater then minval and |
3325 |
|
less then maxval are unchanged. |
3326 |
|
@rtype: L{numarray.NumArray}, L{escript.Data}, L{Symbol}, C{int} or C{float} depending on the input |
3327 |
|
""" |
3328 |
|
if minval>maxval: |
3329 |
|
raise ValueError,"minval = %s must be less then maxval %s"%(minval,maxval) |
3330 |
|
return minimum(maximum(minval,arg),maxval) |
3331 |
|
|
3332 |
|
|
3333 |
def inner(arg0,arg1): |
def inner(arg0,arg1): |
3334 |
""" |
""" |
3665 |
@param arg: interpolant |
@param arg: interpolant |
3666 |
@param where: FunctionSpace to interpolate to |
@param where: FunctionSpace to interpolate to |
3667 |
""" |
""" |
3668 |
if testForZero(arg): |
if isinstance(arg,Symbol): |
|
return 0 |
|
|
elif isinstance(arg,Symbol): |
|
3669 |
return Interpolated_Symbol(arg,where) |
return Interpolated_Symbol(arg,where) |
3670 |
else: |
else: |
3671 |
return escript.Data(arg,where) |
return escript.Data(arg,where) |
3690 |
to be calculated. |
to be calculated. |
3691 |
""" |
""" |
3692 |
d=arg.getDomain() |
d=arg.getDomain() |
3693 |
return arg.interpolate(escript.FunctionOnContactOne())-arg.interpolate(escript.FunctionOnContactZero()) |
return arg.interpolate(escript.FunctionOnContactOne(d))-arg.interpolate(escript.FunctionOnContactZero(d)) |
3694 |
|
|
3695 |
#============================= |
#============================= |
3696 |
# |
# |