Skip to content
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

long long vs int + python 3.11 + spectrally 0.0.4 #964

Merged
merged 41 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
d408fe0
[#960] trying with np.ndarray instead of memoryview
dvezinet Sep 5, 2024
014b0ed
[#960] reactivated windows with 3.10 + added 3.11
dvezinet Sep 5, 2024
a3041e9
[#960] extend solution to lnvert
dvezinet Sep 5, 2024
9e84611
[#960] trying with memoryview and type size specified cf Cython 6384
dvezinet Sep 5, 2024
e792606
[#960] keep trying with type int64_t
dvezinet Sep 5, 2024
b4a956c
[#960] forgotten comma
dvezinet Sep 5, 2024
0dcc2f5
[#960] .pxd modified
dvezinet Sep 5, 2024
647d354
[#960] .pxd modified 2
dvezinet Sep 5, 2024
54776d4
[#960] .pxd modified 3
dvezinet Sep 5, 2024
7063bad
[#960] .pxd modified 4
dvezinet Sep 5, 2024
ed61098
[#960] .pxd modified 5
dvezinet Sep 5, 2024
600e50f
[#960] .pxd modified 6
dvezinet Sep 5, 2024
887fd28
[#960] .pxd modified 7: lstruct_nlim
dvezinet Sep 6, 2024
b6fde9c
[#960] .pxd modified 8
dvezinet Sep 6, 2024
46353d6
[#960] .pxd modified 9
dvezinet Sep 6, 2024
af20792
[#960] .pxd modified 10
dvezinet Sep 6, 2024
d557e33
[#960] all dtype=int replaced by dtype=np.int64 in tofu/geom/*.py
dvezinet Sep 6, 2024
e87b350
[#960] Replaced long by int64_t in _GG.pyx
dvezinet Sep 6, 2024
bede552
[960] Replaced long by int64_t in tofu/geom/_basic_geom_tools.pxd tof…
dvezinet Sep 6, 2024
b7cdb2d
[960] Replaced long by int64_t in tofu/geom/_basic_geom_tools.pxd tof…
dvezinet Sep 6, 2024
87dea9a
[960] Replaced long by int64_t in tofu/geom/_raytracing_tools.pyx and…
dvezinet Sep 6, 2024
ee2f21d
[960] Replaced long by int64_t in tofu/geom/_sampling_tools.pyx tofu/…
dvezinet Sep 6, 2024
b5f0db3
[960] Replaced long by int64_t in tofu/geom/_vignetting_tools.pyx tof…
dvezinet Sep 6, 2024
9bf15cc
[960] Replaced dtype=int by dtype=np.int64 in tofu/tests/tests01_geom…
dvezinet Sep 6, 2024
0b8ea6c
[960] Replaced dtype=int by dtype=np.int64 in tofu/geom/_GG.pyx
dvezinet Sep 6, 2024
91dee55
[960] Replaced astype(int) by astype(np.int64) in tofu/geom/_GG.pyx
dvezinet Sep 6, 2024
630eb51
[960] debug unit tests 0
dvezinet Sep 6, 2024
9023207
[960] debug unit tests 1
dvezinet Sep 6, 2024
b99e3e1
[960] debug unit tests 2
dvezinet Sep 6, 2024
4cc9e82
[960] debug unit tests 3
dvezinet Sep 6, 2024
f7c1313
[960] debug unit tests 4
dvezinet Sep 6, 2024
edbbc3f
[#960] spectrally >= 0.0.4
dvezinet Sep 6, 2024
39cde70
[960] debug unit tests 5
dvezinet Sep 6, 2024
c5b9347
[960] debug unit tests 6
dvezinet Sep 6, 2024
1c89dcc
[960] debug unit tests 7
dvezinet Sep 6, 2024
038b96a
[960] debug unit tests 8
dvezinet Sep 6, 2024
ae34f64
[960] debug unit tests 9
dvezinet Sep 6, 2024
99428d4
[960] debug unit tests 10
dvezinet Sep 6, 2024
1d153b4
[960] debug unit tests 11
dvezinet Sep 6, 2024
f3ca7a5
[960] debug unit tests 12
dvezinet Sep 6, 2024
c4a5a72
[960] debug unit tests 13
dvezinet Sep 6, 2024
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
4 changes: 2 additions & 2 deletions .github/workflows/test-complete-matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
python-version: ['3.8', '3.9', '3.10']
python-version: ['3.8', '3.9', '3.10', '3.11']
include:
- python-version: '3.7.11'
os: ubuntu-20.04
exclude:
- python-version: '3.10'
- python-version: ['3.11']
os: windows-latest

steps:
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ svg.path
Polygon3

######## Requirements with Version Specifier ########
spectrally>=0.0.1
spectrally>=0.0.4
Cython>=0.26
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ def get_version_tofu(path=_HERE):
"svg.path",
"Polygon3",
"cython>=0.26",
"spectrally>=0.0.1",
"spectrally>=0.0.4",
],
python_requires=">=3.6",

Expand Down
356 changes: 184 additions & 172 deletions tofu/geom/_GG.pyx

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion tofu/geom/_basic_geom_tools.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# - cythonization of matplotlib path functions (is point in a path?)
# - cythonization of some numpy functions (hypotenus, tile, sum)
################################################################################
from libc.stdint cimport int64_t
cimport cython
from cpython.array cimport array, clone

Expand Down Expand Up @@ -102,4 +103,4 @@ cdef void compute_diff_div(const double[:, ::1] vec1,
# ==============================================================================
# == Matrix sum (np.sum)
# ==============================================================================
cdef long sum_naive_int(long* orig, int n_cols) nogil
cdef int64_t sum_naive_int(int64_t* orig, int n_cols) nogil
7 changes: 4 additions & 3 deletions tofu/geom/_basic_geom_tools.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ from libc.math cimport sqrt as c_sqrt
from libc.math cimport NAN as CNAN
from libc.math cimport pi as c_pi
from libc.stdlib cimport malloc, free
from libc.stdint cimport int64_t
#
cdef double _VSMALL = 1.e-9
cdef double _SMALL = 1.e-6
Expand Down Expand Up @@ -382,12 +383,12 @@ cdef inline void sum_by_rows(double *orig, double *out,
return


cdef inline long sum_naive_int(long* orig, int n_cols) nogil:
cdef inline int64_t sum_naive_int(int64_t* orig, int n_cols) nogil:
cdef int ii
cdef long out
cdef int64_t out

with nogil:
out = 0
for ii in prange(n_cols):
out += orig[ii]
return out
return out
11 changes: 8 additions & 3 deletions tofu/geom/_comp.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,13 +577,13 @@ def _Ves_get_sample_checkinputs(
c0 = (ind is None
or (isinstance(ind, np.ndarray)
and ind.ndim == 1
and ind.dtype == np.int_
and 'int' in ind.dtype.name
and np.all(ind >= 0))
or (which == 'surface'
and isinstance(ind, list)
and all([isinstance(indi, np.ndarray)
and indi.ndim == 1
and indi.dtype == np.int_
and 'int' in indi.dtype.name
and np.all(indi >= 0) for indi in ind])))
if not c0:
msg = ("Arg ind must be either:\n"
Expand All @@ -594,6 +594,11 @@ def _Ves_get_sample_checkinputs(
msg += " You provided:\n{}".format(ind)
raise Exception(msg)

if isinstance(ind, np.ndarray):
ind = ind.astype(np.int64)
elif isinstance(ind, list):
ind = [ii.astype(np.int64) for ii in ind]

return res, domain, resMode, ind


Expand Down Expand Up @@ -1085,7 +1090,7 @@ def _Struct_get_phithetaproj(ax=None, poly_closed=None, lim=None, noccur=0):
nphi = np.r_[1]
else:
assert lim.ndim == 2, str(lim)
nphi = np.ones((noccur,), dtype=int)
nphi = np.ones((noccur,), dtype=np.int64)
ind = (lim[:, 0] > lim[:, 1]).nonzero()[0]
Dphi = np.concatenate((lim, np.full((noccur, 2), np.nan)), axis=1)
if ind.size > 0:
Expand Down
6 changes: 4 additions & 2 deletions tofu/geom/_comp_solidangles.py
Original file line number Diff line number Diff line change
Expand Up @@ -1041,8 +1041,10 @@ def _calc_solidangle_apertures_prepare(
else:
lka = list(apertures.keys())
ap_ind = np.r_[
0, np.cumsum([apertures[k0]['poly_x'].size for k0 in lka])
]
0,
np.cumsum([apertures[k0]['poly_x'].size for k0 in lka]),
].astype(np.int64)

ap_x = np.concatenate([apertures[k0]['poly_x'] for k0 in lka])
ap_y = np.concatenate([apertures[k0]['poly_y'] for k0 in lka])
ap_z = np.concatenate([apertures[k0]['poly_z'] for k0 in lka])
Expand Down
36 changes: 18 additions & 18 deletions tofu/geom/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ def _checkformat_inputs_dreflect(self, Types=None, coefs_reflect=None):
if type(Types) is str:
assert Types in self._DREFLECT_DTYPES.keys()
Types = np.full(
(self.nseg + 2,), self._DREFLECT_DTYPES[Types], dtype=int
(self.nseg + 2,), self._DREFLECT_DTYPES[Types], dtype=np.int64
)
else:
Types = Types.astype(int).ravel()
Expand Down Expand Up @@ -3192,14 +3192,14 @@ def _to_SOLEDGE3X_get_data(self,
+ 'Created on: {}'.format(now))

# Build walls
nwall = np.array([[self.nStruct]], dtype=int)
nwall = np.array([[self.nStruct]], dtype=np.int64)

# typ (from extraprop if any, else from Ves / Struct)
if type_extraprop is not None:
typ = np.array([self._get_extraprop(type_extraprop)], dtype=int)
typ = np.array([self._get_extraprop(type_extraprop)], dtype=np.int64)
else:
typ = np.array([[1 if ss._InOut == 'in' else -1
for ss in self.lStruct]], dtype=int)
for ss in self.lStruct]], dtype=np.int64)
# Get coord
coord = np.array([np.array([
(ss.Poly[0:1, :].T, ss.Poly[1:2, :].T) for ss in self.lStruct],
Expand Down Expand Up @@ -3559,14 +3559,14 @@ def get_reflections(self, indout, u=None, vperp=None):
# Version only usable when indout returns npts+1 and npts+2 instead of
# -1 and -2
# ls = [ss._dreflect['Types'].size for ss in lS]
# Types = np.empty((len(lS), np.max(ls)), dtype=int)
# Types = np.empty((len(lS), np.max(ls)), dtype=np.int64)
# for ii,ss in enumerate(lS):
# Types[ii,:ls[ii]] = ss._dreflect['Types']
# # Deduce Types
# Types = Types[indout[0,:], indout[2,:]]

iu = np.unique(indout[0, :])
Types = np.empty((indout.shape[1],), dtype=int)
Types = np.empty((indout.shape[1],), dtype=np.int64)
for ii in iu:
ind = indout[0, :] == ii
Types[ind] = lS[ii]._dreflect["Types"][indout[2, ind]]
Expand Down Expand Up @@ -3619,7 +3619,7 @@ def _get_phithetaproj_dist(
# Get limits
lS = self.lStruct
dist = np.full((ntheta, nphi), np.inf)
indStruct = np.zeros((ntheta, nphi), dtype=int)
indStruct = np.zeros((ntheta, nphi), dtype=np.int64)
for ii in range(0, self.nStruct):
out = _comp._Struct_get_phithetaproj(
refpt, lS[ii].Poly_closed, lS[ii].Lim, lS[ii].noccur
Expand Down Expand Up @@ -3769,7 +3769,7 @@ def _reflect_Types(self, indout=None, Type=None, nRays=None):
"""
if Type is not None:
assert Type in ["specular", "diffusive", "ccube"]
Types = np.full((nRays,), _DREFLECT[Type], dtype=int)
Types = np.full((nRays,), _DREFLECT[Type], dtype=np.int64)
else:
Types = self.get_reflections(indout)[0]
return Types
Expand Down Expand Up @@ -4067,7 +4067,7 @@ def get_kwdargs_LOS_isVis(self):

# Lims
lSLim = [ss.Lim for ss in lS]
lSnLim = np.array([ss.noccur for ss in lS])
lSnLim = np.array([ss.noccur for ss in lS], dtype=np.int64)

# Nb of structures and of structures inc. Lims (toroidal occurence)
num_lim_structs = len(lS)
Expand All @@ -4082,7 +4082,7 @@ def get_kwdargs_LOS_isVis(self):
# lsnvert = cumulated number of points in the poly of each Struct
lsnvert = np.cumsum([
ss.Poly_closed[0].size for ss in lS],
dtype=int,
dtype=np.int64,
)

# Now setting keyword arguments:
Expand Down Expand Up @@ -5240,7 +5240,7 @@ def _prepare_inputs_kInOut(self, D=None, u=None, indStruct=None):
else:
num_tot_structs += len(ss.Lim)

lsnvert = np.asarray(lsnvert, dtype=np.int_)
lsnvert = np.asarray(lsnvert, dtype=np.int64)
lSPolyx = np.asarray(lSPolyx)
lSPolyy = np.asarray(lSPolyy)
lSVInx = np.asarray(lSVInx)
Expand All @@ -5252,7 +5252,7 @@ def _prepare_inputs_kInOut(self, D=None, u=None, indStruct=None):
lstruct_polyx=lSPolyx,
lstruct_polyy=lSPolyy,
lstruct_lims=lSLim,
lstruct_nlim=np.asarray(lSnLim, dtype=np.int_),
lstruct_nlim=np.asarray(lSnLim, dtype=np.int64),
lstruct_normx=lSVInx,
lstruct_normy=lSVIny,
lnvert=lsnvert,
Expand Down Expand Up @@ -5566,7 +5566,7 @@ def get_reflections_as_cam(self, Type=None, Name=None, nb=None):
clas = Rays if self.__class__.__name__ == Rays else CamLOS1D

# Run first iteration
Types = np.full((nb, self.nRays), 0, dtype=int)
Types = np.full((nb, self.nRays), 0, dtype=np.int64)
Ds = self.D + (self._dgeom["kOut"][None, :] - 1.0e-12) * self.u
us, Types[0, :] = self.config._reflect_geom(
u=self.u,
Expand Down Expand Up @@ -5640,11 +5640,11 @@ def add_reflections(self, Type=None, nb=None):

# Prepare output
nRays = self.nRays
Types = np.full((nRays, nb), 0, dtype=int)
Types = np.full((nRays, nb), 0, dtype=np.int64)
Ds = np.full((3, nRays, nb), np.nan, dtype=float)
us = np.full((3, nRays, nb), np.nan, dtype=float)
kouts = np.full((nRays, nb), np.nan, dtype=float)
indouts = np.full((3, nRays, nb), 0, dtype=int)
indouts = np.full((3, nRays, nb), 0, dtype=np.int64)
vperps = np.full((3, nRays, nb), np.nan, dtype=float)

# Run first iteration
Expand Down Expand Up @@ -6220,7 +6220,7 @@ def get_indStruct_computeInOut(self, unique_In=None):
indIn = np.array([
ii for ii, ss in enumerate(self.config.lStruct)
if compute[ii] and ss._InOut == "in"
], dtype=int)
], dtype=np.int64)
if unique_In is True and indIn.size > 1:
iind = np.argmin([
self.config.lStruct[ii].dgeom['Surf'] for ii in indIn
Expand All @@ -6230,7 +6230,7 @@ def get_indStruct_computeInOut(self, unique_In=None):
indOut = np.array([
ii for ii, ss in enumerate(self.config.lStruct)
if compute[ii] and ss._InOut == "out"
], dtype=int)
], dtype=np.int64)
return indIn, indOut

def _check_indch(self, ind, out=int):
Expand Down Expand Up @@ -8230,7 +8230,7 @@ def get_ind_flatimg(self, direction='flat2img'):
np.digitize(self._dgeom['ddetails']['x12'][0,:], x2b)])
if direction == 'flat2img':
indr = np.zeros((self._dgeom['ddetails']['x1'].size,
self._dgeom['ddetails']['x2'].size),dtype=int)
self._dgeom['ddetails']['x2'].size),dtype=np.int64)
indr[ind[0,:],ind[1,:]] = np.arange(0,self._dgeom['nRays'])
ind = indr
return ind
Expand Down
Loading
Loading