Skip to content

Commit c3245b1

Browse files
committed
Ensure that most "Colour" honours float precision change.
1 parent f737edf commit c3245b1

37 files changed

+524
-224
lines changed

colour/adaptation/fairchild1990.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
from colour.algebra import spow
2424
from colour.adaptation import VON_KRIES_CAT
25-
from colour.utilities import (as_float_array, dot_vector, from_range_100,
25+
from colour.utilities import (as_float_array, dot_vector, from_range_100, ones,
2626
row_as_diagonal, to_domain_100, tsplit, tstack)
2727

2828
__author__ = 'Colour Developers'
@@ -231,14 +231,15 @@ def degrees_of_adaptation(LMS, Y_n, v=1 / 3, discount_illuminant=False):
231231

232232
LMS = as_float_array(LMS)
233233
if discount_illuminant:
234-
return np.ones(LMS.shape)
234+
return ones(LMS.shape)
235235

236236
Y_n = as_float_array(Y_n)
237237
v = as_float_array(v)
238238

239239
L, M, S = tsplit(LMS)
240240

241-
LMS_E = dot_vector(VON_KRIES_CAT, np.ones(LMS.shape)) # E illuminant.
241+
# E illuminant.
242+
LMS_E = dot_vector(VON_KRIES_CAT, ones(LMS.shape))
242243
L_E, M_E, S_E = tsplit(LMS_E)
243244

244245
Ye_n = spow(Y_n, v)

colour/algebra/geometry.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
import numpy as np
4141
from collections import namedtuple
4242

43-
from colour.utilities import (CaseInsensitiveMapping, as_float_array, tsplit,
44-
tstack)
43+
from colour.utilities import (CaseInsensitiveMapping, as_float_array, ones,
44+
tsplit, tstack)
4545

4646
__author__ = 'Colour Developers'
4747
__copyright__ = 'Copyright (C) 2013-2020 - Colour Developers'
@@ -492,7 +492,7 @@ def ellipse_fitting_Halir1998(a):
492492
# Quadratic part of the design matrix.
493493
D1 = tstack([x ** 2, x * y, y ** 2])
494494
# Linear part of the design matrix.
495-
D2 = tstack([x, y, np.ones(x.shape)])
495+
D2 = tstack([x, y, ones(x.shape)])
496496

497497
D1_T = np.transpose(D1)
498498
D2_T = np.transpose(D2)

colour/appearance/cam16.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
viewing_condition_dependent_parameters)
3939
from colour.utilities import (CaseInsensitiveMapping, as_float_array,
4040
as_namedtuple, dot_vector, from_range_100,
41-
from_range_degrees, to_domain_100,
41+
from_range_degrees, ones, to_domain_100,
4242
to_domain_degrees, tsplit)
4343

4444
__author__ = 'Colour Developers'
@@ -244,7 +244,7 @@ def XYZ_to_CAM16(XYZ,
244244

245245
# Computing degree of adaptation :math:`D`.
246246
D = (np.clip(degree_of_adaptation(surround.F, L_A), 0, 1)
247-
if not discount_illuminant else np.ones(L_A.shape))
247+
if not discount_illuminant else ones(L_A.shape))
248248

249249
n, F_L, N_bb, N_cb, z = tsplit(
250250
viewing_condition_dependent_parameters(Y_b, Y_w, L_A))
@@ -419,7 +419,7 @@ def CAM16_to_XYZ(CAM16_specification,
419419

420420
# Computing degree of adaptation :math:`D`.
421421
D = (np.clip(degree_of_adaptation(surround.F, L_A), 0, 1)
422-
if not discount_illuminant else np.ones(L_A.shape))
422+
if not discount_illuminant else ones(L_A.shape))
423423

424424
n, F_L, N_bb, N_cb, z = tsplit(
425425
viewing_condition_dependent_parameters(Y_b, Y_w, L_A))

colour/appearance/ciecam02.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
from colour.constants import EPSILON
3939
from colour.utilities import (
4040
CaseInsensitiveMapping, as_float_array, as_int_array, as_namedtuple,
41-
as_float, from_range_degrees, dot_matrix, dot_vector, from_range_100,
42-
to_domain_100, to_domain_degrees, tsplit, tstack)
41+
as_float, from_range_degrees, dot_matrix, dot_vector, from_range_100, ones,
42+
to_domain_100, to_domain_degrees, tsplit, tstack, zeros)
4343

4444
__author__ = 'Colour Developers'
4545
__copyright__ = 'Copyright (C) 2013-2020 - Colour Developers'
@@ -265,7 +265,7 @@ def XYZ_to_CIECAM02(XYZ,
265265

266266
# Computing degree of adaptation :math:`D`.
267267
D = (degree_of_adaptation(surround.F, L_A)
268-
if not discount_illuminant else np.ones(L_A.shape))
268+
if not discount_illuminant else ones(L_A.shape))
269269

270270
# Computing full chromatic adaptation.
271271
RGB_c = full_chromatic_adaptation_forward(RGB, RGB_w, Y_w, D)
@@ -437,7 +437,7 @@ def CIECAM02_to_XYZ(CIECAM02_specification,
437437

438438
# Computing degree of adaptation :math:`D`.
439439
D = (degree_of_adaptation(surround.F, L_A)
440-
if not discount_illuminant else np.ones(L_A.shape))
440+
if not discount_illuminant else ones(L_A.shape))
441441

442442
# Computing full chromatic adaptation.
443443
RGB_wc = full_chromatic_adaptation_forward(RGB_w, RGB_w, Y_w, D)
@@ -900,8 +900,8 @@ def opponent_colour_dimensions_inverse(P_n, h):
900900
P_5 = P_1 / cos_hr
901901
n = P_2 * (2 + P_3) * (460 / 1403)
902902

903-
a = np.zeros(hr.shape)
904-
b = np.zeros(hr.shape)
903+
a = zeros(hr.shape)
904+
b = zeros(hr.shape)
905905

906906
b = np.where(
907907
np.isfinite(P_1) * np.abs(sin_hr) >= np.abs(cos_hr),
@@ -1456,7 +1456,7 @@ def P(N_c, N_cb, e_t, t, A, N_bb):
14561456

14571457
P_1 = ((50000 / 13) * N_c * N_cb * e_t) / t
14581458
P_2 = A / N_bb + 0.305
1459-
P_3 = np.ones(P_1.shape) * (21 / 20)
1459+
P_3 = ones(P_1.shape) * (21 / 20)
14601460

14611461
P_n = tstack([P_1, P_2, P_3])
14621462

colour/appearance/hunt.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
from collections import namedtuple
2525

2626
from colour.algebra import spow
27-
from colour.utilities import (CaseInsensitiveMapping, as_float_array,
28-
dot_vector, from_range_degrees, to_domain_100,
29-
tsplit, tstack, usage_warning)
27+
from colour.utilities import (
28+
CaseInsensitiveMapping, as_float_array, dot_vector, from_range_degrees,
29+
ones, to_domain_100, tsplit, tstack, usage_warning, zeros)
3030

3131
__author__ = 'Colour Developers'
3232
__copyright__ = 'Copyright (C) 2013-2020 - Colour Developers'
@@ -325,7 +325,7 @@ def XYZ_to_Hunt(XYZ,
325325
>>> XYZ_b = np.array([95.05, 100.00, 108.88])
326326
>>> L_A = 318.31
327327
>>> surround = HUNT_VIEWING_CONDITIONS['Normal Scenes']
328-
>>> CCT_w = 6504.0
328+
>>> CCT_w = 6504
329329
>>> XYZ_to_Hunt(XYZ, XYZ_w, XYZ_b, L_A, surround, CCT_w=CCT_w)
330330
... # doctest: +ELLIPSIS
331331
Hunt_Specification(J=30.0462678..., C=0.1210508..., h=269.2737594..., \
@@ -662,14 +662,14 @@ def chromatic_adaptation(XYZ,
662662
L_A_p = spow(L_A, 1 / 3)
663663
F_rgb = ((1 + L_A_p + h_rgb) / (1 + L_A_p + (1 / h_rgb)))
664664
else:
665-
F_rgb = np.ones(h_rgb.shape)
665+
F_rgb = ones(h_rgb.shape)
666666

667667
# Computing Helson-Judd effect parameters.
668668
if helson_judd_effect:
669669
D_rgb = (f_n((Y_b / Y_w) * F_L * F_rgb[..., 1]) - f_n(
670670
(Y_b / Y_w) * F_L * F_rgb))
671671
else:
672-
D_rgb = np.zeros(F_rgb.shape)
672+
D_rgb = zeros(F_rgb.shape)
673673

674674
# Computing cone bleach factors.
675675
B_rgb = (10 ** 7) / ((10 ** 7) + 5 * L_A[..., np.newaxis] * (rgb_w / 100))

colour/characterisation/correction.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363

6464
from colour.algebra import least_square_mapping_MoorePenrose
6565
from colour.utilities import (CaseInsensitiveMapping, as_float_array, as_int,
66-
closest, filter_kwargs, tsplit, tstack)
66+
closest, filter_kwargs, ones, tsplit, tstack)
6767

6868
__author__ = 'Colour Developers'
6969
__copyright__ = 'Copyright (C) 2013-2020 - Colour Developers'
@@ -119,7 +119,7 @@ def augmented_matrix_Cheung2004(RGB, terms=3):
119119
"""
120120

121121
R, G, B = tsplit(RGB)
122-
ones = np.ones(R.shape)
122+
tail = ones(R.shape)
123123

124124
existing_terms = np.array([3, 5, 7, 8, 10, 11, 14, 16, 17, 19, 20, 22])
125125
closest_terms = as_int(closest(existing_terms, terms))
@@ -132,23 +132,23 @@ def augmented_matrix_Cheung2004(RGB, terms=3):
132132
if terms == 3:
133133
return RGB
134134
elif terms == 5:
135-
return tstack([R, G, B, R * G * B, ones])
135+
return tstack([R, G, B, R * G * B, tail])
136136
elif terms == 7:
137-
return tstack([R, G, B, R * G, R * B, G * B, ones])
137+
return tstack([R, G, B, R * G, R * B, G * B, tail])
138138
elif terms == 8:
139-
return tstack([R, G, B, R * G, R * B, G * B, R * G * B, ones])
139+
return tstack([R, G, B, R * G, R * B, G * B, R * G * B, tail])
140140
elif terms == 10:
141141
return tstack(
142-
[R, G, B, R * G, R * B, G * B, R ** 2, G ** 2, B ** 2, ones])
142+
[R, G, B, R * G, R * B, G * B, R ** 2, G ** 2, B ** 2, tail])
143143
elif terms == 11:
144144
return tstack([
145145
R, G, B, R * G, R * B, G * B, R ** 2, G ** 2, B ** 2, R * G * B,
146-
ones
146+
tail
147147
])
148148
elif terms == 14:
149149
return tstack([
150150
R, G, B, R * G, R * B, G * B, R ** 2, G ** 2, B ** 2, R * G * B, R
151-
** 3, G ** 3, B ** 3, ones
151+
** 3, G ** 3, B ** 3, tail
152152
])
153153
elif terms == 16:
154154
return tstack([
@@ -158,7 +158,7 @@ def augmented_matrix_Cheung2004(RGB, terms=3):
158158
elif terms == 17:
159159
return tstack([
160160
R, G, B, R * G, R * B, G * B, R ** 2, G ** 2, B ** 2, R * G * B,
161-
R ** 2 * G, G ** 2 * B, B ** 2 * R, R ** 3, G ** 3, B ** 3, ones
161+
R ** 2 * G, G ** 2 * B, B ** 2 * R, R ** 3, G ** 3, B ** 3, tail
162162
])
163163
elif terms == 19:
164164
return tstack([
@@ -170,7 +170,7 @@ def augmented_matrix_Cheung2004(RGB, terms=3):
170170
return tstack([
171171
R, G, B, R * G, R * B, G * B, R ** 2, G ** 2, B ** 2, R * G * B,
172172
R ** 2 * G, G ** 2 * B, B ** 2 * R, R ** 2 * B, G ** 2 * R,
173-
B ** 2 * G, R ** 3, G ** 3, B ** 3, ones
173+
B ** 2 * G, R ** 3, G ** 3, B ** 3, tail
174174
])
175175
elif terms == 22:
176176
return tstack([

colour/colorimetry/generation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
from colour.constants import DEFAULT_FLOAT_DTYPE
3838
from colour.colorimetry import (DEFAULT_SPECTRAL_SHAPE, SpectralDistribution)
39-
from colour.utilities import CaseInsensitiveMapping, as_float_array
39+
from colour.utilities import CaseInsensitiveMapping, as_float_array, full, ones
4040

4141
__author__ = 'Colour Developers'
4242
__copyright__ = 'Copyright (C) 2013-2020 - Colour Developers'
@@ -90,7 +90,7 @@ def sd_constant(k, shape=DEFAULT_SPECTRAL_SHAPE, dtype=None):
9090
dtype = DEFAULT_FLOAT_DTYPE
9191

9292
wavelengths = shape.range(dtype)
93-
values = np.full(len(wavelengths), k, dtype)
93+
values = full(len(wavelengths), k, dtype)
9494

9595
name = '{0} Constant'.format(k)
9696
return SpectralDistribution(values, wavelengths, name=name, dtype=dtype)
@@ -485,7 +485,7 @@ def sd_multi_leds_Ohno2005(peak_wavelengths,
485485
peak_wavelengths = as_float_array(peak_wavelengths)
486486
fwhm = np.resize(fwhm, peak_wavelengths.shape)
487487
if peak_power_ratios is None:
488-
peak_power_ratios = np.ones(peak_wavelengths.shape)
488+
peak_power_ratios = ones(peak_wavelengths.shape)
489489
else:
490490
peak_power_ratios = np.resize(peak_power_ratios,
491491
peak_wavelengths.shape)

colour/colorimetry/photometry.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
from colour.colorimetry import PHOTOPIC_LEFS
2222
from colour.constants import K_M
23+
from colour.utilities import as_float
2324

2425
__author__ = 'Colour Developers'
2526
__copyright__ = 'Copyright (C) 2013-2020 - Colour Developers'
@@ -75,7 +76,7 @@ def luminous_flux(sd,
7576

7677
flux = K_m * np.trapz(sd.values, sd.wavelengths)
7778

78-
return flux
79+
return as_float(flux)
7980

8081

8182
def luminous_efficiency(
@@ -155,4 +156,4 @@ def luminous_efficacy(
155156

156157
efficacy = K_M * luminous_efficiency(sd, lef)
157158

158-
return efficacy
159+
return as_float(efficacy)

colour/colorimetry/tristimulus.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@ def sd_to_XYZ_integration(
498498
S = illuminant.values
499499
x_bar, y_bar, z_bar = tsplit(cmfs.values)
500500
R = sd.values
501+
501502
dw = cmfs.shape.interval
502503

503504
k = 100 / (np.sum(y_bar * S) * dw) if k is None else k

colour/constants/common.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from __future__ import division, unicode_literals
1010

11+
import os
1112
import numpy as np
1213

1314
from colour.utilities.documentation import DocstringFloat
@@ -46,14 +47,16 @@
4647
EPSILON : numeric
4748
"""
4849

49-
DEFAULT_FLOAT_DTYPE = np.float_
50+
DEFAULT_FLOAT_DTYPE = np.sctypeDict.get(
51+
os.environ.get('COLOUR_SCIENCE__FLOAT_PRECISION', 'float64'), 'float64')
5052
"""
5153
Default floating point number dtype.
5254
5355
DEFAULT_FLOAT_DTYPE : type
5456
"""
5557

56-
DEFAULT_INT_DTYPE = np.int_
58+
DEFAULT_INT_DTYPE = np.sctypeDict.get(
59+
os.environ.get('COLOUR_SCIENCE__INT_PRECISION', 'int64'), 'int64')
5760
"""
5861
Default integer number dtype.
5962

colour/continuous/multi_signals.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,10 +1318,6 @@ def multi_signals_unpack_data(data=None,
13181318
if dtype is None:
13191319
dtype = DEFAULT_FLOAT_DTYPE
13201320

1321-
assert dtype in np.sctypes['float'], (
1322-
'"dtype" must be one of the following types: {0}'.format(
1323-
np.sctypes['float']))
1324-
13251321
domain_u, range_u, signals = None, None, None
13261322
signals = OrderedDict()
13271323
# TODO: Implement support for Signal class passing.

0 commit comments

Comments
 (0)