Skip to content

switch almost all np.array to np.asarray #44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions TESTS/unitTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ class pointOpTests(unittest.TestCase):
def test1(self):
matImg = scipy.io.loadmat(op.join(matfiles_path, 'pointOp1.mat'))
img = pt.synthetic_images.ramp((200,200))
filt = np.array([0.2, 0.5, 1.0, 0.4, 0.1]);
filt = np.asarray([0.2, 0.5, 1.0, 0.4, 0.1]);
#foo = pointOp(200, 200, img, 5, filt, 0, 1, 0);
foo = pt.pointOp(img, filt, 0, 1);
foo = np.reshape(foo,(200,200))
Expand Down Expand Up @@ -249,15 +249,15 @@ def test13(self):

class binomialFilterTests(unittest.TestCase):
def test1(self):
target = np.array([[0.5],[0.5]])
target = np.asarray([[0.5],[0.5]])
#target = target / np.sqrt(np.sum(target ** 2))
self.assertTrue((pt.binomial_filter(2) == target).all() )
def test2(self):
target = np.array([[0.25], [0.5], [0.25]])
target = np.asarray([[0.25], [0.5], [0.25]])
#target = target / np.sqrt(np.sum(target ** 2))
self.assertTrue((pt.binomial_filter(3) == target).all())
def test3(self):
target = np.array([[0.0625], [0.25], [0.3750], [0.25], [0.0625]])
target = np.asarray([[0.0625], [0.25], [0.3750], [0.25], [0.0625]])
#target = target / np.sqrt(np.sum(target ** 2))
self.assertTrue((pt.binomial_filter(5) == target).all())

Expand All @@ -269,13 +269,13 @@ def test1(self):
self.assertTrue(pt.comparePyr(matPyr['pyr'], pyPyr))
def test2(self):
matPyr = scipy.io.loadmat(op.join(matfiles_path, 'buildGpyr2row.mat'))
img = np.array(list(range(256))).astype(float)
img = np.asarray(list(range(256))).astype(float)
img = img.reshape(1, 256)
pyPyr = pt.pyramids.GaussianPyramid(img)
self.assertTrue(pt.comparePyr(matPyr['pyr'], pyPyr))
def test3(self):
matPyr = scipy.io.loadmat(op.join(matfiles_path, 'buildGpyr2col.mat'))
img = np.array(list(range(256))).astype(float)
img = np.asarray(list(range(256))).astype(float)
img = img.reshape(256, 1)
pyPyr = pt.pyramids.GaussianPyramid(img)
self.assertTrue(pt.comparePyr(matPyr['pyr'], pyPyr))
Expand Down Expand Up @@ -318,17 +318,17 @@ def test4(self):
self.assertTrue(pt.comparePyr(matPyr['pyr'], pyPyr))
def test5(self):
matPyr = scipy.io.loadmat(op.join(matfiles_path, 'buildLpyr5.mat'))
pyRamp = np.array(list(range(200))).reshape(1, 200)
pyRamp = np.asarray(list(range(200))).reshape(1, 200)
pyPyr = pt.pyramids.LaplacianPyramid(pyRamp)
self.assertTrue(pt.comparePyr(matPyr['pyr'], pyPyr))
def test5bis(self):
matPyr = scipy.io.loadmat(op.join(matfiles_path, 'buildLpyr5.mat'))
pyRamp = np.array(list(range(200)))
pyRamp = np.asarray(list(range(200)))
pyPyr = pt.pyramids.LaplacianPyramid(pyRamp)
self.assertTrue(pt.comparePyr(matPyr['pyr'], pyPyr))
def test6(self):
matPyr = scipy.io.loadmat(op.join(matfiles_path, 'buildLpyr6.mat'))
pyRamp = np.array(list(range(200)))
pyRamp = np.asarray(list(range(200)))
pyPyr = pt.pyramids.LaplacianPyramid(pyRamp)
self.assertTrue(pt.comparePyr(matPyr['pyr'], pyPyr))
def test7(self):
Expand Down Expand Up @@ -1145,16 +1145,16 @@ def test0(self):
matPyr = scipy.io.loadmat(op.join(matfiles_path, 'imGradient0.mat'))
ramp = pt.synthetic_images.ramp(10)
[dx,dy] = pt.image_gradient(ramp)
dx = np.array(dx)
dy = np.array(dy)
dx = np.asarray(dx)
dy = np.asarray(dy)
self.assertTrue(pt.compareRecon(matPyr['res'][:,:,0], dx))
self.assertTrue(pt.compareRecon(matPyr['res'][:,:,1], dy))
def test1(self):
matPyr = scipy.io.loadmat(op.join(matfiles_path, 'imGradient1.mat'))
ramp = pt.synthetic_images.ramp(10)
[dx,dy] = pt.image_gradient(ramp, 'reflect1')
dx = np.array(dx)
dy = np.array(dy)
dx = np.asarray(dx)
dy = np.asarray(dy)
self.assertTrue(pt.compareRecon(matPyr['res'][:,:,0], dx))
self.assertTrue(pt.compareRecon(matPyr['res'][:,:,1], dy))

Expand Down
16 changes: 8 additions & 8 deletions src/pyrtools/pyramids/SteerablePyramidFreq.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ def __init__(self, image, height='auto', order=3, twidth=1, is_complex=False):
raise ValueError("twidth must be positive.")
twidth = int(twidth)

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

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

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

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

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

lodft = np.fft.ifft2(np.fft.ifftshift(lodft))
self.pyr_coeffs['residual_lowpass'] = np.real(np.array(lodft).copy())
self.pyr_coeffs['residual_lowpass'] = np.real(np.asarray(lodft).copy())
self.pyr_size['residual_lowpass'] = lodft.shape

def recon_pyr(self, levels='all', bands='all', twidth=1):
Expand Down Expand Up @@ -248,7 +248,7 @@ def recon_pyr(self, levels='all', bands='all', twidth=1):
if dims in dim_list:
continue
dim_list.append(dims)
dims = np.array(dims)
dims = np.asarray(dims)
ctr = np.ceil((dims+0.5)/2).astype(int)
lodims = np.ceil((dims-0.5)/2).astype(int)
loctr = np.ceil((lodims+0.5)/2).astype(int)
Expand All @@ -260,7 +260,7 @@ def recon_pyr(self, levels='all', bands='all', twidth=1):
dim_list.append((dim_list[-1][0], dim_list[-1][1]))

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

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

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

Expand Down
2 changes: 1 addition & 1 deletion src/pyrtools/pyramids/SteerablePyramidSpace.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def __init__(self, image, height='auto', order=1, edge_type='reflect1'):
for b in range(self.num_orientations):
filt = self.filters['bfilts'][:, b].reshape(bfiltsz, bfiltsz).T
band = corrDn(image=lo, filt=filt, edge_type=self.edge_type)
self.pyr_coeffs[(i, b)] = np.array(band)
self.pyr_coeffs[(i, b)] = np.asarray(band)
self.pyr_size[(i, b)] = band.shape

lo = corrDn(image=lo, filt=self.filters['lofilt'], edge_type=self.edge_type, step=(2, 2))
Expand Down
2 changes: 1 addition & 1 deletion src/pyrtools/pyramids/c/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,4 +254,4 @@ def pointOp(image, lut, origin, increment, warnings=False):
ctypes.c_double(origin),
ctypes.c_double(increment), warnings)

return np.array(result)
return np.asarray(result)
Loading
Loading