Skip to content

Commit 4d8eaaa

Browse files
timholyt-bltg
andauthored
The first breaking abs2 step (#188)
This switches `abs2` to be consistent with `ColorVectorSpace.Future.abs2`. Co-authored-by: t-bltg <[email protected]>
1 parent 61e78ec commit 4d8eaaa

File tree

5 files changed

+44
-76
lines changed

5 files changed

+44
-76
lines changed

.github/workflows/UnitTest.yml

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ on:
44
create:
55
tags:
66
push:
7-
branches:
8-
- master
7+
branches: [master]
98
pull_request:
109

10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
12+
cancel-in-progress: true
13+
1114
jobs:
1215
test:
1316
runs-on: ${{ matrix.os }}
@@ -29,28 +32,13 @@ jobs:
2932
arch: x86
3033

3134
steps:
32-
- uses: actions/checkout@v2
33-
- name: "Set up Julia"
34-
uses: julia-actions/setup-julia@v1
35+
- uses: actions/checkout@v3
36+
- uses: julia-actions/setup-julia@latest
3537
with:
3638
version: ${{ matrix.julia-version }}
37-
38-
- name: Cache artifacts
39-
uses: actions/cache@v1
40-
env:
41-
cache-name: cache-artifacts
42-
with:
43-
path: ~/.julia/artifacts
44-
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
45-
restore-keys: |
46-
${{ runner.os }}-test-${{ env.cache-name }}-
47-
${{ runner.os }}-test-
48-
${{ runner.os }}-
49-
50-
- name: "Unit Test"
51-
uses: julia-actions/julia-runtest@master
52-
53-
- uses: julia-actions/julia-processcoverage@v1
54-
- uses: codecov/codecov-action@v1
39+
- uses: julia-actions/cache@v1
40+
- uses: julia-actions/julia-runtest@latest
41+
- uses: julia-actions/julia-processcoverage@latest
42+
- uses: codecov/codecov-action@v3
5543
with:
5644
file: lcov.info

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ColorVectorSpace"
22
uuid = "c3611d14-8923-5661-9e6a-0046d554d3a4"
3-
version = "0.9.10"
3+
version = "0.10.0"
44

55
[deps]
66
ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"

README.md

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,6 @@ for `g = Gray(0.3)`, ColorVectorSpace returned different values for `abs2(g)` an
129129
This behavior is retained, with a deprecation warning, starting with
130130
ColorVectorSpace 0.9.6.
131131

132-
**In the future**, `abs2` will be defined as `abs2(c) == c⋅c ≈ norm(c)^2`.
133-
This effectively divides the old result by 3; code that imposes thresholds
134-
on `abs2(c)` may need to be updated.
135-
You can obtain that behavior now--and circumvent the deprecation warning--
136-
by using `ColorVectorSpace.Future.abs2(c)`.
137-
138132
We anticipate the following transition schedule:
139133

140134
- Sept 21, 2021: release ColorVectorSpace 0.9.7 with both `abs2` and `Future.abs2`.
@@ -143,8 +137,8 @@ We anticipate the following transition schedule:
143137
- May 19, 2022: make the deprecation warning "noisy" (cannot be turned off).
144138
This is designed to catch user-level scripts that may need to update thresholds
145139
or other constants.
146-
- *July 1, 2022: transition `abs2` to the new definition
140+
- *July 20, 2023: transition `abs2` to the new definition
147141
and make `Future.abs2` give a "noisy" depwarn to revert to regular `abs2`.
148-
- *Dec 1, 2022: remove `Future.abs2`.
142+
- *Dec 1, 2023: remove `Future.abs2`.
149143

150-
The two marked with `*` denote breaking releases.
144+
The line marked with `*` denotes a breaking release.

src/ColorVectorSpace.jl

Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,12 @@ import LinearAlgebra: norm, ⋅, dot, promote_leaf_eltypes # norm1, norm2, norm
2626
using Statistics
2727
import Statistics: middle # and `_mean_promote`
2828

29+
isdefined(Base, :get_extension) || using Requires
30+
2931
export RGBRGB, complement, nan, dotc, dot, , hadamard, , tensor, , norm, varmult, stdmult
3032

3133
MathTypes{T,C<:Union{AbstractGray{T},AbstractRGB{T}}} = Union{C,TransparentColor{C,T}}
3234

33-
if Base.VERSION >= v"1.5"
34-
@inline _depwarn(msg, funcsym; force=false) = Base.depwarn(msg, funcsym; force=force)
35-
else
36-
@inline _depwarn(msg, funcsym; force=false) = Base.depwarn(msg, funcsym)
37-
end
38-
3935
## Version compatibility with ColorTypes
4036
### TODO: Remove the definitons other than `one` when dropping ColorTypes v0.10 support
4137

@@ -479,40 +475,32 @@ end
479475
Base.length(r::StepRange{<:AbstractGray,<:AbstractGray}) = length(StepRange(gray(r.start), gray(r.step), gray(r.stop)))
480476
Base.length(r::StepRange{<:AbstractGray}) = length(StepRange(gray(r.start), r.step, gray(r.stop)))
481477

482-
Base.abs2(g::AbstractGray) = abs2(gray(g))
483-
function Base.abs2(c::AbstractRGB)
484-
_depwarn("""
485-
The return value of `abs2` will change to ensure that `abs2(g::Gray) ≈ abs2(RGB(g::Gray))`.
486-
For `RGB` colors, this results in dividing the previous output by 3.
487-
488-
To avoid this warning, use `ColorVectorSpace.Future.abs2` instead of `abs2`; currently,
489-
`abs2` returns the old value (for compatibility), and `ColorVectorSpace.Future.abs2` returns the new value.
490-
When making this change, you may also need to adjust constants like color-difference thresholds
491-
to compensate for the change in the returned value.
492-
493-
If you are getting this from `var`, use `varmult` instead.
494-
""", :abs2)
495-
return mapreducec(v->float(v)^2, +, zero(eltype(c)), c)
496-
end
478+
Base.abs2(c::Union{AbstractGray,AbstractRGB}) = c c
497479

498480
module Future
499-
using ..ColorTypes
500-
using ..ColorVectorSpace: , dot
501-
"""
502-
ColorVectorSpace.Future.abs2(c)
503-
504-
Return a scalar "squared magnitude" for color types. For RGB and gray, this is just the mean-square
505-
channelwise intensity.
481+
using ..ColorTypes
482+
using ..ColorVectorSpace:
483+
"""
484+
ColorVectorSpace.Future.abs2(c)
485+
Return a scalar "squared magnitude" for color types. For RGB and gray, this is just the mean-square
486+
channelwise intensity.
487+
"""
488+
489+
if VERSION >= v"1.5"
490+
@inline _depwarn(msg, funcsym; force=false) = Base.depwarn(msg, funcsym; force=force)
491+
else
492+
@inline _depwarn(msg, funcsym; force=false) = Base.depwarn(msg, funcsym)
493+
end
506494

507-
Compatibility note: this gives a different result from `Base.abs2(c)`, but eventually `Base.abs2` will switch
508-
to the definition used here. Using `ColorVectorSpace.Future.abs2` thus future-proofs your code.
509-
For more information about the transition, see ColorVectorSpace's README.
510-
"""
511-
abs2(c::Union{Real,AbstractGray,AbstractRGB}) = c c
495+
function abs2(c::Union{Real,AbstractGray,AbstractRGB})
496+
_depwarn("""
497+
The return value of `abs2` is now consistent with `ColorVectorSpace.Future.abs2`.
498+
`ColorVectorSpace.Future.abs2` will be removed in the future, please switch to `abs2`.""", :abs2
499+
)
500+
c c
501+
end
512502
end
513503

514-
isdefined(Base, :get_extension) || using Requires
515-
516504
function __init__()
517505
if isdefined(Base, :Experimental) && isdefined(Base.Experimental, :register_error_hint)
518506
Base.Experimental.register_error_hint(MethodError) do io, exc, argtypes, kwargs

test/runtests.jl

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ ColorTypes.comp2(c::RGBA32) = alpha(c)
137137
@test_throws MethodError cf ÷ cf
138138
@test cf + 0.1 === 0.1 + cf === Gray(Float64(0.1f0) + 0.1)
139139
@test cf64 - 0.1f0 === -(0.1f0 - cf64) === Gray( 0.2 - Float64(0.1f0))
140-
@test ColorVectorSpace.Future.abs2(ccmp) === ColorVectorSpace.Future.abs2(gray(ccmp))
140+
@test abs2(ccmp) === abs2(gray(ccmp))
141141
@test norm(cf) == norm(cf, 2) == norm(gray(cf))
142142
@test norm(cf, 1) == norm(gray(cf), 1)
143143
@test norm(cf, Inf) == norm(gray(cf), Inf)
@@ -430,8 +430,9 @@ ColorTypes.comp2(c::RGBA32) = alpha(c)
430430
@test abs(RGB(0.1,0.2,0.3)) == RGB(0.1,0.2,0.3)
431431
cv = RGB(0.1,0.2,0.3)
432432
@test ColorVectorSpace.Future.abs2(cv) == cv cv
433-
@test_logs (:warn, r"change to ensure") abs2(cv) > 2*ColorVectorSpace.Future.abs2(cv)
434-
@test ColorVectorSpace.Future.abs2(cv) norm(cv)^2
433+
@test_logs (:warn, r"is now consistent") ColorVectorSpace.Future.abs2(cv)
434+
@test abs2(cv) == cv cv
435+
@test abs2(cv) norm(cv)^2
435436
@test_throws MethodError sum(abs2, RGB(0.1,0.2,0.3))
436437
@test norm(RGB(0.1,0.2,0.3)) sqrt(0.14)/sqrt(3)
437438

@@ -807,7 +808,7 @@ ColorTypes.comp2(c::RGBA32) = alpha(c)
807808
@test norm(x, p) == norm(g, p) norm(c, p)
808809
end
809810
@test dot(x, x) == dot(g, g) dot(c, c)
810-
@test abs2(x) == abs2(g) ColorVectorSpace.Future.abs2(c)
811+
@test abs2(x) abs2(g) abs2(c)
811812
@test_throws MethodError mapreduce(x->x^2, +, c) # this risks breaking equivalence & noniterability
812813
end
813814

@@ -835,10 +836,7 @@ ColorTypes.comp2(c::RGBA32) = alpha(c)
835836
sv2 = mapc(sqrt, v2)
836837
@test varmult(, cs, dims=1) [v2 v2]
837838
@test stdmult(, cs, dims=1) [sv2 sv2]
838-
839-
# When ColorVectorSpace.Future.abs2 becomes the default, delete the `@test_logs`
840-
# and change the `@test_broken` to `@test`
841-
@test_logs (:warn, r"will change to ensure") match_mode=:any @test_broken var(cs) == varmult(, cs)
839+
@test var(cs) == varmult(, cs)
842840
end
843841

844842
@testset "copy" begin

0 commit comments

Comments
 (0)