Skip to content

Commit

Permalink
ENH: py3 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
albop committed Dec 24, 2015
1 parent 707c1d1 commit f6a588a
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 18 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pyc
19 changes: 10 additions & 9 deletions interpolation/smolyak/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
import numpy as np
from scipy.linalg import lu
import pandas as pd
from util import *
from functools import reduce
from .util import *

## --------------- ##
#- Building Blocks -#
Expand Down Expand Up @@ -143,7 +144,7 @@ def chebyvalto(x, n, kind=1.):
ret_matrix[:, :col] = x * kind
ret_matrix[:, col:2*col] = 2 * x * ret_matrix[:, :col] - init

for i in xrange(3, n):
for i in range(3, n):
ret_matrix[:, col*(i-1): col*(i)] = 2 * x * ret_matrix[:, col*(i-2):col*(i-1)] \
- ret_matrix[:, col*(i-3): col*(i-2)]

Expand Down Expand Up @@ -255,7 +256,7 @@ def a_chain(n):
A_chain[2] = [-1., 1.]

# Need a for loop to extract remaining elements
for seq in xrange(n, 2, -1):
for seq in range(n, 2, -1):
num = Sn.size
# Need odd indices in python because indexing starts at 0
A_chain[seq] = tuple(Sn[range(1, num, 2)])
Expand Down Expand Up @@ -293,7 +294,7 @@ def phi_chain(n):
aphi_chain[2] = [2, 3]

curr_val = 4
for i in xrange(3, n+1):
for i in range(3, n+1):
end_val = 2**(i-1) + 1
temp = range(curr_val, end_val+1)
aphi_chain[i] = temp
Expand Down Expand Up @@ -568,7 +569,7 @@ def build_B(d, mu, pts, b_inds=None, deriv=False):
# # compute any more. They are multiplications of different numbers
# # of elements from the pieces of easy_B.
# if mu==2:
# for i in xrange(d-1):
# for i in range(d-1):


# mult_inds = np.hstack([np.arange(i+1, d), np.arange(d + (i+1), 2*d)])
Expand All @@ -591,7 +592,7 @@ def build_B(d, mu, pts, b_inds=None, deriv=False):
# #-----------------------------------------------------------------#
# #-----------------------------------------------------------------#

# # for i in xrange(2, mu+1):
# # for i in range(2, mu+1):
# # curr_ind = i

# # while True:
Expand All @@ -601,15 +602,15 @@ def build_B(d, mu, pts, b_inds=None, deriv=False):
# # # Find which possible polynomials can be reached (lowest is 2)
# # poss_inds = np.arange(2, m_i(some function of curr_ind, d, mu)+1)

# # for dd in xrange(d-1):
# # for dd in range(d-1):
# # # Create range of d to be used to build the fancy index
# # mult_ind = np.arange(curr_col+1, d)

# # # Initialize array for fancy index. Want to add arange(d) + (d*i)
# # # for every chebyshev polynomial that we need to reach with these
# # # indexes
# # mult_inds = np.array([])
# # for tt in xrange(some condition for what is max polynomial we reach -1):
# # for tt in range(some condition for what is max polynomial we reach -1):
# # mult_inds = np.hstack([mult_inds, mult_inds + (d*tt)])

# # # this will create the column times all the stuff following it
Expand All @@ -622,7 +623,7 @@ def build_B(d, mu, pts, b_inds=None, deriv=False):

# # while d>curr_dim and condition for continuing is met:
# # curr_dim += 1
# # for mm in xrange(curr_col + 2, d-1):
# # for mm in range(curr_col + 2, d-1):
# # for bb in mult_inds[:-1]:
# # temp2 = easy_B[:, bb*d + mm] * temp1
# # new_cols2 = temp2.shape[1]
Expand Down
2 changes: 1 addition & 1 deletion interpolation/smolyak/interp.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from __future__ import division
import numpy as np
import numpy.linalg as la
from grid import build_B
from .grid import build_B

__all__ = ['find_theta', 'SmolyakInterp']

Expand Down
2 changes: 1 addition & 1 deletion interpolation/splines/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from splines import CubicSpline, MultiCubicSpline
from .splines import CubicSpline, MultiCubicSpline
4 changes: 2 additions & 2 deletions interpolation/splines/eval_cubic_splines.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
# from eval_cubic_splines_cython import *
#
# except Exception:
from eval_cubic_multi_splines_numba import *
from eval_cubic_splines_numba import *
from .eval_cubic_multi_splines_numba import *
from .eval_cubic_splines_numba import *


## the functions in this file work for any dimension (d<=4)
Expand Down
10 changes: 5 additions & 5 deletions interpolation/splines/splines.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy
import numpy as np

from misc import mlinspace
from .misc import mlinspace


class CubicSpline:
Expand Down Expand Up @@ -59,7 +59,7 @@ def set_values(self, values):

values = np.array(values, dtype=float)

from filter_cubic_splines import filter_coeffs
from .filter_cubic_splines import filter_coeffs

if not np.all( np.isfinite(values)):
raise Exception('Trying to interpolate non-finite values')
Expand Down Expand Up @@ -91,7 +91,7 @@ def interpolate(self, points, values=None, with_derivatives=False):

import time

from eval_cubic_splines import vec_eval_cubic_spline, eval_cubic_spline
from .eval_cubic_splines import vec_eval_cubic_spline, eval_cubic_spline

if not np.all( np.isfinite(points)):
raise Exception('Spline interpolator evaluated at non-finite points.')
Expand Down Expand Up @@ -158,7 +158,7 @@ def set_values(self, values):

values = np.array(values, dtype=float)

from filter_cubic_splines import filter_coeffs
from .filter_cubic_splines import filter_coeffs

if not np.all( np.isfinite(values)):
raise Exception('Trying to interpolate non-finite values')
Expand Down Expand Up @@ -193,7 +193,7 @@ def interpolate(self, points, with_derivatives=False):

import time

from eval_cubic_splines import vec_eval_cubic_multi_spline
from .eval_cubic_splines import vec_eval_cubic_multi_spline

if points.ndim == 1:
raise Exception('Expected 2d array. Received {}d array'.format(points.ndim))
Expand Down

0 comments on commit f6a588a

Please sign in to comment.