Skip to content

Commit e6e9998

Browse files
committed
Added noexcept flags to optical package functions and methods.
1 parent b4b746f commit e6e9998

42 files changed

Lines changed: 178 additions & 182 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

raysect/optical/colour.pxd

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,19 @@
3131

3232
from raysect.optical.spectrum cimport Spectrum
3333

34-
cpdef double[:,::1] resample_ciexyz(double min_wavelength, double max_wavelength, int bins)
34+
cpdef double[:,::1] resample_ciexyz(double min_wavelength, double max_wavelength, int bins) noexcept
3535

36-
cpdef (double, double, double) spectrum_to_ciexyz(Spectrum spectrum, double[:,::1] resampled_xyz=*)
36+
cpdef (double, double, double) spectrum_to_ciexyz(Spectrum spectrum, double[:,::1] resampled_xyz=*) noexcept
3737

38-
cpdef (double, double, double) ciexyy_to_ciexyz(double cx, double cy, double y)
38+
cpdef (double, double, double) ciexyy_to_ciexyz(double cx, double cy, double y) noexcept
3939

40-
cpdef (double, double, double) ciexyz_to_ciexyy(double x, double y, double z)
40+
cpdef (double, double, double) ciexyz_to_ciexyy(double x, double y, double z) noexcept
4141

42-
cdef double srgb_transfer_function(double v)
42+
cdef double srgb_transfer_function(double v) noexcept
4343

44-
cpdef (double, double, double) ciexyz_to_srgb(double x, double y, double z)
44+
cpdef (double, double, double) ciexyz_to_srgb(double x, double y, double z) noexcept
4545

46-
cdef double srgb_transfer_function_inverse(double v)
46+
cdef double srgb_transfer_function_inverse(double v) noexcept
4747

48-
cpdef (double, double, double) srgb_to_ciexyz(double r, double g, double b)
48+
cpdef (double, double, double) srgb_to_ciexyz(double r, double g, double b) noexcept
4949

raysect/optical/colour.pyx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ d65_white = InterpolatedSF(d65_wavelength_samples, d65_white_samples)
120120

121121
@cython.boundscheck(False)
122122
@cython.wraparound(False)
123-
cpdef double[:,::1] resample_ciexyz(double min_wavelength, double max_wavelength, int bins):
123+
cpdef double[:,::1] resample_ciexyz(double min_wavelength, double max_wavelength, int bins) noexcept:
124124
"""
125125
Pre-calculates samples of XYZ sensitivity curves over desired spectral range.
126126
@@ -155,7 +155,7 @@ cpdef double[:,::1] resample_ciexyz(double min_wavelength, double max_wavelength
155155
@cython.wraparound(False)
156156
@cython.boundscheck(False)
157157
@cython.initializedcheck(False)
158-
cpdef (double, double, double) spectrum_to_ciexyz(Spectrum spectrum, double[:,::1] resampled_xyz=None):
158+
cpdef (double, double, double) spectrum_to_ciexyz(Spectrum spectrum, double[:,::1] resampled_xyz=None) noexcept:
159159
"""
160160
Calculates a tuple of CIE X, Y, Z values from an input spectrum
161161
@@ -187,7 +187,7 @@ cpdef (double, double, double) spectrum_to_ciexyz(Spectrum spectrum, double[:,::
187187

188188

189189
@cython.cdivision(True)
190-
cpdef (double, double, double) ciexyy_to_ciexyz(double cx, double cy, double y):
190+
cpdef (double, double, double) ciexyy_to_ciexyz(double cx, double cy, double y) noexcept:
191191
"""
192192
Performs conversion from CIE xyY to CIE XYZ colour space
193193
@@ -202,7 +202,7 @@ cpdef (double, double, double) ciexyy_to_ciexyz(double cx, double cy, double y):
202202

203203

204204
@cython.cdivision(True)
205-
cpdef (double, double, double) ciexyz_to_ciexyy(double x, double y, double z):
205+
cpdef (double, double, double) ciexyz_to_ciexyy(double x, double y, double z) noexcept:
206206
"""
207207
Performs conversion from CIE XYZ to CIE xyY colour space
208208
@@ -220,7 +220,7 @@ cpdef (double, double, double) ciexyz_to_ciexyy(double x, double y, double z):
220220
return x / n, y / n, y
221221

222222

223-
cdef double srgb_transfer_function(double v):
223+
cdef double srgb_transfer_function(double v) noexcept:
224224

225225
if v <= 0.0031308:
226226

@@ -232,7 +232,7 @@ cdef double srgb_transfer_function(double v):
232232
return 1.055 * v**0.4166666666666667 - 0.055
233233

234234

235-
cpdef (double, double, double) ciexyz_to_srgb(double x, double y, double z):
235+
cpdef (double, double, double) ciexyz_to_srgb(double x, double y, double z) noexcept:
236236
"""
237237
Convert CIE XYZ values to sRGB colour space.
238238
@@ -266,7 +266,7 @@ cpdef (double, double, double) ciexyz_to_srgb(double x, double y, double z):
266266
return r, g, b
267267

268268

269-
cdef double srgb_transfer_function_inverse(double v):
269+
cdef double srgb_transfer_function_inverse(double v) noexcept:
270270

271271
if v <= 0.04045:
272272

@@ -279,7 +279,7 @@ cdef double srgb_transfer_function_inverse(double v):
279279
return (0.9478672985781991 * (v + 0.055))**2.4
280280

281281

282-
cpdef (double, double, double) srgb_to_ciexyz(double r, double g, double b):
282+
cpdef (double, double, double) srgb_to_ciexyz(double r, double g, double b) noexcept:
283283
"""
284284
Convert sRGB values to CIE XYZ colour space.
285285

raysect/optical/library/spectra/blackbody.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ cdef class BlackBody(NumericallyIntegratedSF):
8888
return self.__new__, (self.__class__, ), self.__getstate__()
8989

9090
@cython.cdivision(True)
91-
cpdef double function(self, double wavelength):
91+
cpdef double function(self, double wavelength) noexcept:
9292
"""
9393
Planck's Law.
9494

raysect/optical/material/conductor.pxd

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ cdef class Conductor(Material):
4040
public SpectralFunction index
4141
public SpectralFunction extinction
4242

43-
cdef double _fresnel(self, double ci, double n, double k) nogil
43+
cdef double _fresnel(self, double ci, double n, double k) noexcept nogil
4444

4545

4646
cdef class RoughConductor(ContinuousBSDF):
@@ -50,8 +50,8 @@ cdef class RoughConductor(ContinuousBSDF):
5050
public SpectralFunction extinction
5151
double _roughness
5252

53-
cdef double _d(self, Vector3D s_half)
54-
cdef double _g(self, Vector3D s_incoming, Vector3D s_outgoing)
55-
cdef double _g1(self, Vector3D v)
53+
cdef double _d(self, Vector3D s_half) noexcept
54+
cdef double _g(self, Vector3D s_incoming, Vector3D s_outgoing) noexcept
55+
cdef double _g1(self, Vector3D v) noexcept
5656
cdef Spectrum _f(self, Spectrum spectrum, Vector3D s_outgoing, Vector3D s_normal)
57-
cdef double _fresnel_conductor(self, double ci, double n, double k) nogil
57+
cdef double _fresnel_conductor(self, double ci, double n, double k) noexcept nogil

raysect/optical/material/conductor.pyx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ cdef class Conductor(Material):
134134
return spectrum
135135

136136
@cython.cdivision(True)
137-
cdef double _fresnel(self, double ci, double n, double k) nogil:
137+
cdef double _fresnel(self, double ci, double n, double k) noexcept nogil:
138138

139139
cdef double c12, k0, k1, k2, k3
140140

@@ -200,7 +200,7 @@ cdef class RoughConductor(ContinuousBSDF):
200200
self._roughness = value
201201

202202
@cython.cdivision(True)
203-
cpdef double pdf(self, Vector3D s_incoming, Vector3D s_outgoing, bint back_face):
203+
cpdef double pdf(self, Vector3D s_incoming, Vector3D s_outgoing, bint back_face) noexcept:
204204

205205
cdef Vector3D s_half
206206

@@ -283,7 +283,7 @@ cdef class RoughConductor(ContinuousBSDF):
283283
return self._f(spectrum, s_outgoing, s_half)
284284

285285
@cython.cdivision(True)
286-
cdef double _d(self, Vector3D s_half):
286+
cdef double _d(self, Vector3D s_half) noexcept:
287287

288288
cdef double r2, h2, k
289289

@@ -293,12 +293,12 @@ cdef class RoughConductor(ContinuousBSDF):
293293
k = h2 * (r2 - 1) + 1
294294
return r2 / (M_PI * k * k)
295295

296-
cdef double _g(self, Vector3D s_incoming, Vector3D s_outgoing):
296+
cdef double _g(self, Vector3D s_incoming, Vector3D s_outgoing) noexcept:
297297
# Smith's geometric shadowing model
298298
return self._g1(s_incoming) * self._g1(s_outgoing)
299299

300300
@cython.cdivision(True)
301-
cdef double _g1(self, Vector3D v):
301+
cdef double _g1(self, Vector3D v) noexcept:
302302
# Smith's geometric component (G1) for GGX distribution
303303
cdef double r2 = self._roughness * self._roughness
304304
return 2 * v.z / (v.z + sqrt(r2 + (1 - r2) * (v.z * v.z)))
@@ -325,7 +325,7 @@ cdef class RoughConductor(ContinuousBSDF):
325325
return spectrum
326326

327327
@cython.cdivision(True)
328-
cdef double _fresnel_conductor(self, double ci, double n, double k) nogil:
328+
cdef double _fresnel_conductor(self, double ci, double n, double k) noexcept nogil:
329329

330330
cdef double c12, k0, k1, k2, k3
331331

raysect/optical/material/dielectric.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,4 @@ cdef class Dielectric(Material):
4848
public SpectralFunction transmission
4949
public bint transmission_only
5050

51-
cdef void _fresnel(self, double ci, double ct, double n1, double n2, double *reflectivity, double *transmission) nogil
51+
cdef void _fresnel(self, double ci, double ct, double n1, double n2, double *reflectivity, double *transmission) noexcept nogil

raysect/optical/material/dielectric.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ cdef class Sellmeier(NumericallyIntegratedSF):
100100
return self.__new__, (self.__class__, ), self.__getstate__()
101101

102102
@cython.cdivision(True)
103-
cpdef double function(self, double wavelength):
103+
cpdef double function(self, double wavelength) noexcept:
104104
"""
105105
Returns a sample of the three term Sellmeier equation at the specified
106106
wavelength.
@@ -302,7 +302,7 @@ cdef class Dielectric(Material):
302302
return spectrum
303303

304304
@cython.cdivision(True)
305-
cdef void _fresnel(self, double ci, double ct, double n1, double n2, double *reflectivity, double *transmission) nogil:
305+
cdef void _fresnel(self, double ci, double ct, double n1, double n2, double *reflectivity, double *transmission) noexcept nogil:
306306

307307
reflectivity[0] = 0.5 * (((n1*ci - n2*ct) / (n1*ci + n2*ct))**2 + ((n1*ct - n2*ci) / (n1*ct + n2*ci))**2)
308308
transmission[0] = 1 - reflectivity[0]

raysect/optical/material/emitter/checkerboard.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@ cdef class Checkerboard(NullVolume):
4343
public double scale1
4444
public double scale2
4545

46-
cdef bint _flip(self, bint v, double p) nogil
46+
cdef bint _flip(self, bint v, double p) noexcept nogil

raysect/optical/material/emitter/checkerboard.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ cdef class Checkerboard(NullVolume):
128128
return spectrum
129129

130130
@cython.cdivision(True)
131-
cdef bint _flip(self, bint v, double p) nogil:
131+
cdef bint _flip(self, bint v, double p) noexcept nogil:
132132

133133
# round to avoid numerical precision issues (rounds to nearest nanometer)
134134
p = round(p * 1e9) / 1e9

raysect/optical/material/lambert.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ cdef class Lambert(ContinuousBSDF):
6868
reflectivity = ConstantSF(0.5)
6969
self.reflectivity = reflectivity
7070

71-
cpdef double pdf(self, Vector3D s_incoming, Vector3D s_outgoing, bint back_face):
71+
cpdef double pdf(self, Vector3D s_incoming, Vector3D s_outgoing, bint back_face) noexcept:
7272
return hemisphere_sampler.pdf(s_outgoing)
7373

7474
cpdef Vector3D sample(self, Vector3D s_incoming, bint back_face):

0 commit comments

Comments
 (0)