Try to fix numba_misc.py

master
Per A Brodtkorb 8 years ago
parent 851d19def0
commit e6ad37f3cf

@ -3,7 +3,7 @@ Misc
''' '''
from __future__ import absolute_import, division from __future__ import absolute_import, division
import sys import sys
from . import numba_misc from wafo import numba_misc
import fractions import fractions
import numpy as np import numpy as np
from numpy import ( from numpy import (
@ -1127,11 +1127,14 @@ def findrfc(tp, h=0.0, method='clib'):
>>> ind1 = wm.findrfc(tp, 0.3) >>> ind1 = wm.findrfc(tp, 0.3)
>>> np.allclose(ind1, [ 0, 9, 32, 53, 74, 95, 116, 137]) >>> np.allclose(ind1, [ 0, 9, 32, 53, 74, 95, 116, 137])
True True
>>> ind2 = wm.findrfc(tp, 0.3, method='2') >>> ind2 = wm.findrfc(tp, 0.3, method=0)
>>> np.allclose(ind2, [ 0, 9, 32, 53, 74, 95, 116, 137]) >>> np.allclose(ind2, [ 0, 9, 32, 53, 74, 95, 116, 137, 146])
True True
>>> ind3 = wm.findrfc(tp, 0.3, method='3') >>> ind3 = wm.findrfc(tp, 0.3, method=1)
>>> np.allclose(ind2, [ 0, 9, 32, 53, 74, 95, 116, 137]) >>> np.allclose(ind3, [ 0, 9, 32, 53, 74, 95, 116, 137, 146])
True
>>> ind3 = wm.findrfc(tp, 0.3, method=2)
>>> np.allclose(ind3, [ 0, 9, 32, 53, 74, 95, 116, 137])
True True

@ -51,7 +51,7 @@ def findcross(xn):
def _make_findrfc(cmp1, cmp2): def _make_findrfc(cmp1, cmp2):
@jit(int64(int32[:], float64[:], float64), nopython=True) @jit(int64(int64[:], float64[:], float64), nopython=True)
def findrfc2(t, y, h): def findrfc2(t, y, h):
# cmp1, cmp2 = (a_le_b, a_lt_b) if method==0 else (a_lt_b, a_le_b) # cmp1, cmp2 = (a_le_b, a_lt_b) if method==0 else (a_lt_b, a_le_b)
@ -122,7 +122,7 @@ _findrfc_le = _make_findrfc(a_le_b, a_lt_b)
_findrfc_lt = _make_findrfc(a_lt_b, a_le_b) _findrfc_lt = _make_findrfc(a_lt_b, a_le_b)
@jit(int64(int32[:], float64[:], float64), nopython=True) @jit(int64(int64[:], float64[:], float64), nopython=True)
def _findrfc(ind, y, h): def _findrfc(ind, y, h):
n = len(y) n = len(y)
t_start = 0 t_start = 0
@ -188,7 +188,7 @@ def _findrfc(ind, y, h):
def findrfc(y, h, method=0): def findrfc(y, h, method=0):
n = len(y) n = len(y)
t = np.zeros(n, dtype=np.int) t = np.zeros(n, dtype=np.int64)
findrfc_ = [_findrfc_le, _findrfc_lt, _findrfc][method] findrfc_ = [_findrfc_le, _findrfc_lt, _findrfc][method]
m = findrfc_(t, y, h) m = findrfc_(t, y, h)
return t[:m] return t[:m]

@ -1404,7 +1404,7 @@ class FitDistribution(rv_frozen):
if True: if True:
i0 = 2 i0 = 2
low = int(np.log10(1/n)-0.7) - 1 low = int(np.log10(1.0/n)-0.7) - 1
log_sf = np.log(np.logspace(low, -0.5, 7)[::-1]) log_sf = np.log(np.logspace(low, -0.5, 7)[::-1])
T = self.isf(np.exp(log_sf)) T = self.isf(np.exp(log_sf))
ci = [] ci = []

@ -270,21 +270,22 @@ def test_findrfc():
def test_rfcfilter(): def test_rfcfilter():
# 1. Filtered signal y is the turning points of x. # 1. Filtered signal y is the turning points of x.
x = sea() x = sea()
y = rfcfilter(x[:, 1], h=0, method=1) y = rfcfilter(x[:, 1], h=0.0, method=1)
assert_array_almost_equal( assert_array_almost_equal(
y[0:5], y[0:5],
np.array([-1.2004945, 0.83950546, -0.09049454, np.array([-1.2004945, 0.83950546, -0.09049454,
-0.02049454, -0.09049454])) -0.02049454, -0.09049454]))
# 2. This removes all rainflow cycles with range less than 0.5. # 2. This removes all rainflow cycles with range less than 0.5.
y1 = rfcfilter(x[:, 1], h=0.5) y1 = rfcfilter(x[:, 1], h=0.5, method=0)
assert_array_almost_equal( assert_array_almost_equal(
y1[0:5], y1[0:5],
np.array([-1.2004945, 0.83950546, -0.43049454, np.array([-1.2004945, 0.83950546, -0.43049454,
0.34950546, -0.51049454])) 0.34950546, -0.51049454]))
# return
t = linspace(0, 7 * pi, 250) t = linspace(0, 7 * pi, 250)
x = sin(t) + 0.1 * sin(50 * t) x = sin(t) + 0.1 * sin(50 * t)
ind = findextrema(x) ind = findextrema(x)

@ -189,7 +189,8 @@ def w2k(w, theta=0.0, h=inf, g=9.81, count_limit=100):
# disp(['Iteration ',num2str(count),' Number of points left: ' # disp(['Iteration ',num2str(count),' Number of points left: '
# num2str(length(ix)) ]), # num2str(length(ix)) ]),
ix = find((np.abs(hn) > sqrt(eps) * np.abs(k)) * np.abs(hn) > sqrt(eps)) ix = find((np.abs(hn) > sqrt(eps) * np.abs(k)) *
np.abs(hn) > sqrt(eps))
count += 1 count += 1
if count == count_limit: if count == count_limit:

Loading…
Cancel
Save