Skip to content

Commit c937115

Browse files
authored
switch almost all np.array to np.asarray (#44)
which is generally the right decision
1 parent 37dd9c0 commit c937115

File tree

11 files changed

+833
-835
lines changed

11 files changed

+833
-835
lines changed

TESTS/unitTests.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ class pointOpTests(unittest.TestCase):
213213
def test1(self):
214214
matImg = scipy.io.loadmat(op.join(matfiles_path, 'pointOp1.mat'))
215215
img = pt.synthetic_images.ramp((200,200))
216-
filt = np.array([0.2, 0.5, 1.0, 0.4, 0.1]);
216+
filt = np.asarray([0.2, 0.5, 1.0, 0.4, 0.1]);
217217
#foo = pointOp(200, 200, img, 5, filt, 0, 1, 0);
218218
foo = pt.pointOp(img, filt, 0, 1);
219219
foo = np.reshape(foo,(200,200))
@@ -249,15 +249,15 @@ def test13(self):
249249

250250
class binomialFilterTests(unittest.TestCase):
251251
def test1(self):
252-
target = np.array([[0.5],[0.5]])
252+
target = np.asarray([[0.5],[0.5]])
253253
#target = target / np.sqrt(np.sum(target ** 2))
254254
self.assertTrue((pt.binomial_filter(2) == target).all() )
255255
def test2(self):
256-
target = np.array([[0.25], [0.5], [0.25]])
256+
target = np.asarray([[0.25], [0.5], [0.25]])
257257
#target = target / np.sqrt(np.sum(target ** 2))
258258
self.assertTrue((pt.binomial_filter(3) == target).all())
259259
def test3(self):
260-
target = np.array([[0.0625], [0.25], [0.3750], [0.25], [0.0625]])
260+
target = np.asarray([[0.0625], [0.25], [0.3750], [0.25], [0.0625]])
261261
#target = target / np.sqrt(np.sum(target ** 2))
262262
self.assertTrue((pt.binomial_filter(5) == target).all())
263263

@@ -269,13 +269,13 @@ def test1(self):
269269
self.assertTrue(pt.comparePyr(matPyr['pyr'], pyPyr))
270270
def test2(self):
271271
matPyr = scipy.io.loadmat(op.join(matfiles_path, 'buildGpyr2row.mat'))
272-
img = np.array(list(range(256))).astype(float)
272+
img = np.asarray(list(range(256))).astype(float)
273273
img = img.reshape(1, 256)
274274
pyPyr = pt.pyramids.GaussianPyramid(img)
275275
self.assertTrue(pt.comparePyr(matPyr['pyr'], pyPyr))
276276
def test3(self):
277277
matPyr = scipy.io.loadmat(op.join(matfiles_path, 'buildGpyr2col.mat'))
278-
img = np.array(list(range(256))).astype(float)
278+
img = np.asarray(list(range(256))).astype(float)
279279
img = img.reshape(256, 1)
280280
pyPyr = pt.pyramids.GaussianPyramid(img)
281281
self.assertTrue(pt.comparePyr(matPyr['pyr'], pyPyr))
@@ -318,17 +318,17 @@ def test4(self):
318318
self.assertTrue(pt.comparePyr(matPyr['pyr'], pyPyr))
319319
def test5(self):
320320
matPyr = scipy.io.loadmat(op.join(matfiles_path, 'buildLpyr5.mat'))
321-
pyRamp = np.array(list(range(200))).reshape(1, 200)
321+
pyRamp = np.asarray(list(range(200))).reshape(1, 200)
322322
pyPyr = pt.pyramids.LaplacianPyramid(pyRamp)
323323
self.assertTrue(pt.comparePyr(matPyr['pyr'], pyPyr))
324324
def test5bis(self):
325325
matPyr = scipy.io.loadmat(op.join(matfiles_path, 'buildLpyr5.mat'))
326-
pyRamp = np.array(list(range(200)))
326+
pyRamp = np.asarray(list(range(200)))
327327
pyPyr = pt.pyramids.LaplacianPyramid(pyRamp)
328328
self.assertTrue(pt.comparePyr(matPyr['pyr'], pyPyr))
329329
def test6(self):
330330
matPyr = scipy.io.loadmat(op.join(matfiles_path, 'buildLpyr6.mat'))
331-
pyRamp = np.array(list(range(200)))
331+
pyRamp = np.asarray(list(range(200)))
332332
pyPyr = pt.pyramids.LaplacianPyramid(pyRamp)
333333
self.assertTrue(pt.comparePyr(matPyr['pyr'], pyPyr))
334334
def test7(self):
@@ -1145,16 +1145,16 @@ def test0(self):
11451145
matPyr = scipy.io.loadmat(op.join(matfiles_path, 'imGradient0.mat'))
11461146
ramp = pt.synthetic_images.ramp(10)
11471147
[dx,dy] = pt.image_gradient(ramp)
1148-
dx = np.array(dx)
1149-
dy = np.array(dy)
1148+
dx = np.asarray(dx)
1149+
dy = np.asarray(dy)
11501150
self.assertTrue(pt.compareRecon(matPyr['res'][:,:,0], dx))
11511151
self.assertTrue(pt.compareRecon(matPyr['res'][:,:,1], dy))
11521152
def test1(self):
11531153
matPyr = scipy.io.loadmat(op.join(matfiles_path, 'imGradient1.mat'))
11541154
ramp = pt.synthetic_images.ramp(10)
11551155
[dx,dy] = pt.image_gradient(ramp, 'reflect1')
1156-
dx = np.array(dx)
1157-
dy = np.array(dy)
1156+
dx = np.asarray(dx)
1157+
dy = np.asarray(dy)
11581158
self.assertTrue(pt.compareRecon(matPyr['res'][:,:,0], dx))
11591159
self.assertTrue(pt.compareRecon(matPyr['res'][:,:,1], dy))
11601160

src/pyrtools/pyramids/SteerablePyramidFreq.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ def __init__(self, image, height='auto', order=3, twidth=1, is_complex=False):
114114
raise ValueError("twidth must be positive.")
115115
twidth = int(twidth)
116116

117-
dims = np.array(self.image.shape)
118-
ctr = np.ceil((np.array(dims)+0.5)/2).astype(int)
117+
dims = np.asarray(self.image.shape)
118+
ctr = np.ceil((np.asarray(dims)+0.5)/2).astype(int)
119119

120120
(xramp, yramp) = np.meshgrid(np.linspace(-1, 1, dims[1]+1)[:-1],
121121
np.linspace(-1, 1, dims[0]+1)[:-1])
@@ -126,7 +126,7 @@ def __init__(self, image, height='auto', order=3, twidth=1, is_complex=False):
126126
log_rad = np.log2(log_rad)
127127

128128
# Radial transition function (a raised cosine in log-frequency):
129-
(Xrcos, Yrcos) = rcosFn(twidth, (-twidth/2.0), np.array([0, 1]))
129+
(Xrcos, Yrcos) = rcosFn(twidth, (-twidth/2.0), np.asarray([0, 1]))
130130
Yrcos = np.sqrt(Yrcos)
131131

132132
YIrcos = np.sqrt(1.0 - Yrcos**2)
@@ -191,7 +191,7 @@ def __init__(self, image, height='auto', order=3, twidth=1, is_complex=False):
191191
self.pyr_size[(i, b)] = band.shape
192192

193193
self._anglemasks.append(anglemasks)
194-
dims = np.array(lodft.shape)
194+
dims = np.asarray(lodft.shape)
195195
ctr = np.ceil((dims+0.5)/2).astype(int)
196196
lodims = np.ceil((dims-0.5)/2).astype(int)
197197
loctr = np.ceil((lodims+0.5)/2).astype(int)
@@ -210,7 +210,7 @@ def __init__(self, image, height='auto', order=3, twidth=1, is_complex=False):
210210
lodft = lodft * lomask
211211

212212
lodft = np.fft.ifft2(np.fft.ifftshift(lodft))
213-
self.pyr_coeffs['residual_lowpass'] = np.real(np.array(lodft).copy())
213+
self.pyr_coeffs['residual_lowpass'] = np.real(np.asarray(lodft).copy())
214214
self.pyr_size['residual_lowpass'] = lodft.shape
215215

216216
def recon_pyr(self, levels='all', bands='all', twidth=1):
@@ -248,7 +248,7 @@ def recon_pyr(self, levels='all', bands='all', twidth=1):
248248
if dims in dim_list:
249249
continue
250250
dim_list.append(dims)
251-
dims = np.array(dims)
251+
dims = np.asarray(dims)
252252
ctr = np.ceil((dims+0.5)/2).astype(int)
253253
lodims = np.ceil((dims-0.5)/2).astype(int)
254254
loctr = np.ceil((lodims+0.5)/2).astype(int)
@@ -260,7 +260,7 @@ def recon_pyr(self, levels='all', bands='all', twidth=1):
260260
dim_list.append((dim_list[-1][0], dim_list[-1][1]))
261261

262262
# matlab code starts here
263-
dims = np.array(self.pyr_size['residual_highpass'])
263+
dims = np.asarray(self.pyr_size['residual_highpass'])
264264
ctr = np.ceil((dims+0.5)/2.0).astype(int)
265265

266266
(xramp, yramp) = np.meshgrid((np.arange(1, dims[1]+1)-ctr[1]) / (dims[1]/2.),
@@ -271,7 +271,7 @@ def recon_pyr(self, levels='all', bands='all', twidth=1):
271271
log_rad = np.log2(log_rad)
272272

273273
# Radial transition function (a raised cosine in log-frequency):
274-
(Xrcos, Yrcos) = rcosFn(twidth, (-twidth/2.0), np.array([0, 1]))
274+
(Xrcos, Yrcos) = rcosFn(twidth, (-twidth/2.0), np.asarray([0, 1]))
275275
Yrcos = np.sqrt(Yrcos)
276276
YIrcos = np.sqrt(1.0 - Yrcos**2)
277277

src/pyrtools/pyramids/SteerablePyramidSpace.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def __init__(self, image, height='auto', order=1, edge_type='reflect1'):
8585
for b in range(self.num_orientations):
8686
filt = self.filters['bfilts'][:, b].reshape(bfiltsz, bfiltsz).T
8787
band = corrDn(image=lo, filt=filt, edge_type=self.edge_type)
88-
self.pyr_coeffs[(i, b)] = np.array(band)
88+
self.pyr_coeffs[(i, b)] = np.asarray(band)
8989
self.pyr_size[(i, b)] = band.shape
9090

9191
lo = corrDn(image=lo, filt=self.filters['lofilt'], edge_type=self.edge_type, step=(2, 2))

src/pyrtools/pyramids/c/wrapper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,4 +254,4 @@ def pointOp(image, lut, origin, increment, warnings=False):
254254
ctypes.c_double(origin),
255255
ctypes.c_double(increment), warnings)
256256

257-
return np.array(result)
257+
return np.asarray(result)

0 commit comments

Comments
 (0)