From 51444497ac3f6e1cd2c003ddfc315e1777685136 Mon Sep 17 00:00:00 2001 From: Florian Le Bourdais Date: Mon, 16 Sep 2019 14:38:04 +0200 Subject: [PATCH 1/4] make tests pass on Windows (64 bit) --- tofu/data/_core.py | 4 +++- tofu/geom/_GG02.pyx | 10 +++++----- tofu/geom/_GG03.pyx | 10 +++++----- tofu/geom/_core.py | 2 +- tofu/tests/tests01_geom/tests01_GG.py | 4 ++-- tofu/tests/tests02_data/tests03_core.py | 2 +- 6 files changed, 17 insertions(+), 15 deletions(-) diff --git a/tofu/data/_core.py b/tofu/data/_core.py index e587bf19d..a8bfce471 100644 --- a/tofu/data/_core.py +++ b/tofu/data/_core.py @@ -46,10 +46,12 @@ ############################################# def _format_ind(ind=None, n=None): + """Type checking routine for index variable.""" if ind is None: ind = np.ones((n,),dtype=bool) else: - lInt = [int,np.int64] + # list of accepted integer types + lInt = [int, np.int64, np.int32, np.long] if type(ind) in lInt: ii = np.zeros((n,),dtype=bool) ii[int(ii)] = True diff --git a/tofu/geom/_GG02.pyx b/tofu/geom/_GG02.pyx index fa0cf956a..0462264b8 100644 --- a/tofu/geom/_GG02.pyx +++ b/tofu/geom/_GG02.pyx @@ -1384,7 +1384,7 @@ def _Ves_Smesh_Tor_SubFromD_cython(double dL, double dRPhi, PtsCross, dLr, indL, Rref = PtsCross[:,indin], dLr[indin], \ indL[indin], Rref[indin] Ln = indin.sum() - Indin = indin.nonzero()[0] + Indin = indin.nonzero()[0].astype(np.long) dRPhir, dPhir = np.empty((Ln,)), np.empty((Ln,)) Phin = np.zeros((Ln,),dtype=int) @@ -1471,7 +1471,7 @@ def _Ves_Smesh_Tor_SubFromD_cython(double dL, double dRPhi, ind[NP] = NRPhi0[ii] + indiijj dS[NP] = dLr[ii]*dRPhir[ii] NP += 1 - indok = (~np.isnan(ind)).nonzero()[0] + indok = (~np.isnan(ind)).nonzero()[0].astype(np.long) ind = ind[indok] dS = dS[indok] if len(indok)==1: @@ -2001,7 +2001,7 @@ def _Ves_Smesh_Lin_SubFromInd_cython(double[::1] XMinMax, double dL, double dX, LPts, LdS = [], [] # First face - ii = (ind0: indZ0 = ind[ii] // NY0 @@ -2013,7 +2013,7 @@ def _Ves_Smesh_Lin_SubFromInd_cython(double[::1] XMinMax, double dL, double dX, LdS.append( dY0r*dZ0r*np.ones((nii,)) ) # Cylinder - ii = ((ind>=NY0*NZ0) & (ind=NY0*NZ0) & (ind0: indX = (ind[ii]-NY0*NZ0) // Ln @@ -2026,7 +2026,7 @@ def _Ves_Smesh_Lin_SubFromInd_cython(double[::1] XMinMax, double dL, double dX, LdS.append( dXr*dLr[indL] ) # End face - ii = (ind >= NY0*NZ0+NX*Ln).nonzero()[0] + ii = (ind >= NY0*NZ0+NX*Ln).nonzero()[0].astype(np.long) nii = len(ii) if nii>0: indZ0 = (ind[ii]-NY0*NZ0-NX*Ln) // NY0 diff --git a/tofu/geom/_GG03.pyx b/tofu/geom/_GG03.pyx index fa0cf956a..0462264b8 100644 --- a/tofu/geom/_GG03.pyx +++ b/tofu/geom/_GG03.pyx @@ -1384,7 +1384,7 @@ def _Ves_Smesh_Tor_SubFromD_cython(double dL, double dRPhi, PtsCross, dLr, indL, Rref = PtsCross[:,indin], dLr[indin], \ indL[indin], Rref[indin] Ln = indin.sum() - Indin = indin.nonzero()[0] + Indin = indin.nonzero()[0].astype(np.long) dRPhir, dPhir = np.empty((Ln,)), np.empty((Ln,)) Phin = np.zeros((Ln,),dtype=int) @@ -1471,7 +1471,7 @@ def _Ves_Smesh_Tor_SubFromD_cython(double dL, double dRPhi, ind[NP] = NRPhi0[ii] + indiijj dS[NP] = dLr[ii]*dRPhir[ii] NP += 1 - indok = (~np.isnan(ind)).nonzero()[0] + indok = (~np.isnan(ind)).nonzero()[0].astype(np.long) ind = ind[indok] dS = dS[indok] if len(indok)==1: @@ -2001,7 +2001,7 @@ def _Ves_Smesh_Lin_SubFromInd_cython(double[::1] XMinMax, double dL, double dX, LPts, LdS = [], [] # First face - ii = (ind0: indZ0 = ind[ii] // NY0 @@ -2013,7 +2013,7 @@ def _Ves_Smesh_Lin_SubFromInd_cython(double[::1] XMinMax, double dL, double dX, LdS.append( dY0r*dZ0r*np.ones((nii,)) ) # Cylinder - ii = ((ind>=NY0*NZ0) & (ind=NY0*NZ0) & (ind0: indX = (ind[ii]-NY0*NZ0) // Ln @@ -2026,7 +2026,7 @@ def _Ves_Smesh_Lin_SubFromInd_cython(double[::1] XMinMax, double dL, double dX, LdS.append( dXr*dLr[indL] ) # End face - ii = (ind >= NY0*NZ0+NX*Ln).nonzero()[0] + ii = (ind >= NY0*NZ0+NX*Ln).nonzero()[0].astype(np.long) nii = len(ii) if nii>0: indZ0 = (ind[ii]-NY0*NZ0-NX*Ln) // NY0 diff --git a/tofu/geom/_core.py b/tofu/geom/_core.py index d184d9c37..2b38196f0 100644 --- a/tofu/geom/_core.py +++ b/tofu/geom/_core.py @@ -4290,7 +4290,7 @@ def _check_indch(self, ind, out=int): if ind is not None: ind = np.asarray(ind) assert ind.ndim==1 - assert ind.dtype in [np.int64,np.bool_] + assert ind.dtype in [np.int64,np.bool_, np.long] if ind.dtype == np.bool_: assert ind.size==self.nRays if out is int: diff --git a/tofu/tests/tests01_geom/tests01_GG.py b/tofu/tests/tests01_geom/tests01_GG.py index 974b0de92..9609132da 100644 --- a/tofu/tests/tests01_geom/tests01_GG.py +++ b/tofu/tests/tests01_geom/tests01_GG.py @@ -784,7 +784,7 @@ def test13_LOS_PInOut(): SL2 = np.asarray([np.array([2./3.,1.])*2.*np.pi]) lspolyx = np.asarray(SP0x + SP1x + SP2x) lspolyy = np.asarray(SP0y + SP1y + SP2y) - lnvert = np.cumsum(np.ones(nstruct_tot, dtype=np.int64)*5) + lnvert = np.cumsum(np.ones(nstruct_tot, dtype=np.long)*5) lsvinx = np.asarray([VIn[0], VIn[0], VIn[0]]).flatten() lsviny = np.asarray([VIn[1], VIn[1], VIn[1]]).flatten() # Linear without Struct @@ -1804,7 +1804,7 @@ def test24_is_visible(): SL2 = np.asarray([np.array([2./3.,1.])*2.*np.pi]) lspolyx = np.asarray(SP0x + SP1x + SP2x) lspolyy = np.asarray(SP0y + SP1y + SP2y) - lnvert = np.cumsum(np.ones(nstruct_tot, dtype=np.int64)*5) + lnvert = np.cumsum(np.ones(nstruct_tot, dtype=np.long)*5) lsvinx = np.asarray([VIn[0], VIn[0], VIn[0]]).flatten() lsviny = np.asarray([VIn[1], VIn[1], VIn[1]]).flatten() # ... diff --git a/tofu/tests/tests02_data/tests03_core.py b/tofu/tests/tests02_data/tests03_core.py index 2dbe55793..d03e5e2fd 100644 --- a/tofu/tests/tests02_data/tests03_core.py +++ b/tofu/tests/tests02_data/tests03_core.py @@ -329,7 +329,7 @@ def test09_dtreat_set_interp_indt(self): def test10_dtreat_set_interp_indch(self): for oo in self.lobj: - ind = np.arange(0,oo.nch,10) + ind = np.arange(0,oo.nch,10, dtype=np.long) oo.set_dtreat_interp_indch( ind ) assert oo._dtreat['interp-indch'].sum() == ind.size From cc2d7818e4a86db2109c3a72f9d158cd9b41f87d Mon Sep 17 00:00:00 2001 From: "Laura S. Mendoza" Date: Mon, 16 Sep 2019 15:48:25 +0200 Subject: [PATCH 2/4] Update tests03_core.py adding spaces conforming pep8 rules --- tofu/tests/tests02_data/tests03_core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tofu/tests/tests02_data/tests03_core.py b/tofu/tests/tests02_data/tests03_core.py index d03e5e2fd..1d526102f 100644 --- a/tofu/tests/tests02_data/tests03_core.py +++ b/tofu/tests/tests02_data/tests03_core.py @@ -329,7 +329,7 @@ def test09_dtreat_set_interp_indt(self): def test10_dtreat_set_interp_indch(self): for oo in self.lobj: - ind = np.arange(0,oo.nch,10, dtype=np.long) + ind = np.arange(0, oo.nch, 10, dtype=np.long) oo.set_dtreat_interp_indch( ind ) assert oo._dtreat['interp-indch'].sum() == ind.size From d7ff2e4c8e899b7a608cd89d69cff5f91c41bdfa Mon Sep 17 00:00:00 2001 From: "Laura S. Mendoza" Date: Mon, 16 Sep 2019 15:50:48 +0200 Subject: [PATCH 3/4] Update _core.py Adding spaces according to pep8 rules --- tofu/geom/_core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tofu/geom/_core.py b/tofu/geom/_core.py index 2b38196f0..bf13d507d 100644 --- a/tofu/geom/_core.py +++ b/tofu/geom/_core.py @@ -4290,7 +4290,7 @@ def _check_indch(self, ind, out=int): if ind is not None: ind = np.asarray(ind) assert ind.ndim==1 - assert ind.dtype in [np.int64,np.bool_, np.long] + assert ind.dtype in [np.int64, np.bool_, np.long] if ind.dtype == np.bool_: assert ind.size==self.nRays if out is int: From b2c28944a9763cfedc9393861c8c5158d1b90665 Mon Sep 17 00:00:00 2001 From: Florian Le Bourdais Date: Mon, 23 Sep 2019 18:01:38 +0200 Subject: [PATCH 4/4] Better docstring and error message for failing routine --- tofu/data/_core.py | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/tofu/data/_core.py b/tofu/data/_core.py index a8bfce471..a4b942c25 100644 --- a/tofu/data/_core.py +++ b/tofu/data/_core.py @@ -46,7 +46,28 @@ ############################################# def _format_ind(ind=None, n=None): - """Type checking routine for index variable.""" + """Helper routine to convert selected channels (as numbers) in `ind` to a boolean array format. + + Parameters + ---------- + ind : integer, or list of integers + A channel or a list of channels that the user wants to select. + n : integer, or None + The total number of available channels. + + Returns + ------- + ind : ndarray of booleans, size (n,) + The array with the selected channels set to True, remaining ones set to False + + + Examples + -------- + + >>> _format_ind(ind=[0, 3], n=4) + [True, False, False, True] + + """ if ind is None: ind = np.ones((n,),dtype=bool) else: @@ -67,7 +88,7 @@ def _format_ind(ind=None, n=None): ii[ind] = True ind = ii else: - msg = "Index must be a int, or an iterable of bool or int !" + msg = "Index must be int, or an iterable of bool or int (first element of index has type: {})!".format(type(ind[0])) raise Exception(msg) return ind