Commit 0236e1cc authored by Martin Reinecke's avatar Martin Reinecke
Browse files

Merge branch 'fix_deprecation_warnings' into 'NIFTy_7'

fix numpy deprecation warnings

See merge request !619
parents f8d19b19 0c406f77
Pipeline #102099 passed with stages
in 26 minutes and 34 seconds
......@@ -59,11 +59,11 @@ class GLSpace(StructuredDomain):
@property
def shape(self):
return (int((self.nlat * self.nlon)),)
return (int(self.nlat * self.nlon),)
@property
def size(self):
return int((self.nlat * self.nlon))
return int(self.nlat * self.nlon)
@property
def scalar_dvol(self):
......
......@@ -131,7 +131,7 @@ class LMSpace(StructuredDomain):
op = HarmonicTransformOperator(lm0, gl)
kernel_lm = op.adjoint_times(kernel_sphere.weight(1)).val
# evaluate the k lengths of the harmonic space
k_lengths = self.get_k_length_array().val.astype(int)
k_lengths = self.get_k_length_array().val.astype(np.int64)
return Field.from_raw(self, kernel_lm[k_lengths])
@property
......
......@@ -122,7 +122,7 @@ class RGSpace(StructuredDomain):
if np.all(self.distances == self.distances[0]): # shortcut
maxdist = np.asarray(self.shape)//2
tmp = np.sum(maxdist*maxdist)
tmp = np.zeros(tmp+1, dtype=np.bool)
tmp = np.zeros(tmp+1, dtype=bool)
t2 = np.arange(maxdist[0]+1, dtype=np.int64)
t2 *= t2
for i in range(1, dimensions):
......
......@@ -259,7 +259,7 @@ class Field(Operator):
if np.isscalar(wgt):
fct *= wgt
else:
new_shape = np.ones(len(self.shape), dtype=int)
new_shape = np.ones(len(self.shape), dtype=np.int64)
new_shape[self._domain.axes[ind][0]:
self._domain.axes[ind][-1]+1] = wgt.shape
wgt = wgt.reshape(new_shape)
......
......@@ -68,9 +68,9 @@ class _LightConeDerivative(LinearOperator):
def _cone_arrays(c, domain, sigx, want_gradient):
x = _make_coords(domain)
a = np.zeros(domain.shape, dtype=np.complex)
a = np.zeros(domain.shape, dtype=np.complex128)
if want_gradient:
derivs = np.zeros((c.size,) + domain.shape, dtype=np.complex)
derivs = np.zeros((c.size,) + domain.shape, dtype=np.complex128)
else:
derivs = None
a -= (x[0]/(sigx*domain[0].distances[0]))**2
......
......@@ -64,10 +64,10 @@ def _comp_traverse(start, end, shp, dist, lo, mid, hi, sig, erf):
c_first = np.ceil(start[:, i]+direction*dmin)
c_first = np.where(direction > 0., c_first, c_first-1.)
c_first = (c_first-start[:, i])/dirx
pos1 = np.asarray((start[:, i]+dmin*direction), dtype=int)
pos1 = np.asarray((start[:, i]+dmin*direction), dtype=np.int64)
pos1 = np.sum(pos1*inc)
cdist = np.empty(0, dtype=np.float64)
add = np.empty(0, dtype=int)
add = np.empty(0, dtype=np.int64)
for j in range(ndim):
if direction[j] != 0:
step = inc[j] if direction[j] > 0 else -inc[j]
......
......@@ -393,7 +393,7 @@ class _InformationStore(object):
m = self.history_length
mmax = self.max_history_length
k = self.k
result = np.empty((2*m+1, 2*m+1), dtype=np.float)
result = np.empty((2*m+1, 2*m+1), dtype=np.float64)
# update the stores
k1 = (k-1) % mmax
......@@ -435,10 +435,10 @@ class _InformationStore(object):
m = self.history_length
b_dot_b = self.b_dot_b
delta = np.zeros(2*m+1, dtype=np.float)
delta = np.zeros(2*m+1, dtype=np.float64)
delta[2*m] = -1
alpha = np.empty(m, dtype=np.float)
alpha = np.empty(m, dtype=np.float64)
for j in range(m-1, -1, -1):
delta_b_b = sum([delta[l] * b_dot_b[l, j] for l in range(2*m+1)])
......
......@@ -97,8 +97,8 @@ class DOFDistributor(LinearOperator):
firstaxis = self._target.axes[self._space][0]
lastaxis = self._target.axes[self._space][-1]
arrshape = self._target.shape
presize = np.prod(arrshape[0:firstaxis], dtype=int)
postsize = np.prod(arrshape[lastaxis+1:], dtype=int)
presize = np.prod(arrshape[0:firstaxis], dtype=np.int64)
postsize = np.prod(arrshape[lastaxis+1:], dtype=np.int64)
self._hshape = (presize, self._domain[self._space].shape[0], postsize)
self._pshape = (presize, self._dofdex.size, postsize)
......
......@@ -66,7 +66,7 @@ class RegriddingOperator(LinearOperator):
self._frac = [None] * ndim
for d in range(ndim):
tmp = np.arange(new_shape[d])*(newdist[d]/dom.distances[d])
self._bindex[d] = np.minimum(dom.shape[d]-2, tmp.astype(int))
self._bindex[d] = np.minimum(dom.shape[d]-2, tmp.astype(np.int64))
self._frac[d] = tmp-self._bindex[d]
def apply(self, x, mode):
......
......@@ -286,7 +286,7 @@ def test_stdfunc():
f = ift.Field.full(s, 27)
assert_equal(f.val, 27)
assert_equal(f.shape, (200,))
assert_equal(f.dtype, int)
assert_equal(f.dtype, np.int64)
fx = ift.full(f.domain, 0)
assert_equal(f.dtype, fx.dtype)
assert_equal(f.shape, fx.shape)
......
......@@ -51,26 +51,27 @@ slow_minimizers = ['ift.SteepestDescent(IC)']
slow_minimizers)
@pmp('space', spaces)
def test_quadratic_minimization(minimizer, space):
starting_point = ift.Field.from_random(domain=space, random_type='normal') * 10
covariance_diagonal = ift.Field.from_random(domain=space, random_type='uniform') + 0.5
covariance = ift.DiagonalOperator(covariance_diagonal)
required_result = ift.full(space, 1.)
try:
minimizer = eval(minimizer)
energy = ift.QuadraticEnergy(
A=covariance, b=required_result, position=starting_point)
(energy, convergence) = minimizer(energy)
except NotImplementedError:
pytest.skip()
assert_equal(convergence, IC.CONVERGED)
assert_allclose(
energy.position.val,
1./covariance_diagonal.val,
rtol=1e-3,
atol=1e-3)
with ift.random.Context(98765):
starting_point = ift.Field.from_random(domain=space, random_type='normal') * 10
covariance_diagonal = ift.Field.from_random(domain=space, random_type='uniform') + 0.5
covariance = ift.DiagonalOperator(covariance_diagonal)
required_result = ift.full(space, 1.)
try:
minimizer = eval(minimizer)
energy = ift.QuadraticEnergy(
A=covariance, b=required_result, position=starting_point)
(energy, convergence) = minimizer(energy)
except NotImplementedError:
pytest.skip()
assert_equal(convergence, IC.CONVERGED)
assert_allclose(
energy.position.val,
1./covariance_diagonal.val,
rtol=1e-3,
atol=1e-3)
@pmp('space', spaces)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment