2012-07-23 3 views
0

내 파이썬 코드에서 정기적으로 numpy.allclose을 사용하여 일부 계산을 확인합니다. 반면에 이러한 검사를 제외하고 구현은 다중 정밀도 (mpmath.mpc) 숫자를 처리 할 수 ​​있습니다. 나는 mpmath 숫자에 대 한 내 확인 코드를 실행하려면, 나는 두 multiprecision 배열이 충분히 동일한 경우numpy.allclose 및 mpmath와 다중 정밀도

>>> check(H) 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
File "module.py", line 19, in check_H 
    assert(numpy.allclose(H, I, rtol=rtol, atol=atol)) 
File "/home/gereon/python/numpy/core/numeric.py", line 2025, in allclose 
    xinf = isinf(x) 
TypeError: ufunc 'isinf' not supported for the input types, and the inputs could 
not be safely coerced to any supported types according to the casting rule ''safe'' 

같은 것이 가장 좋은 방법은 무엇을 확인하는 것입니다거야?

답변

3

코드 (numeric.py의 allclose)를 살펴 보았습니다. 이것은 isinf 함수에 달려 있는데, 이것은 mpmath에 대해 구현되지 않은 것 같습니다.

기능은 간단합니다. 당신은 mpmath 등가물 대신 수레와 rtolatol을 대체 할 수 있습니다

def allclose(x, y, rtol=1.e-5, atol=1.e-8): 
    return all(less_equal(abs(x-y), atol + rtol * abs(y))) 

: 그것은 아래로 비등.