@@ -35,18 +35,18 @@ Scale(r"[ace]", low=0.3, high=0.7)
35
35
36
36
* The `low` and `high` values are restricted to the interval [0, 1].
37
37
"""
38
- struct Scale{S<: ColSpec ,T<: Real } <: ColwiseFeatureTransform
38
+ struct Scale{S<: ColSpec ,T} <: ColwiseFeatureTransform
39
39
colspec:: S
40
40
low:: T
41
41
high:: T
42
42
43
- function Scale (colspec:: S , low:: T , high:: T ) where {S<: ColSpec ,T<: Real }
43
+ function Scale (colspec:: S , low:: T , high:: T ) where {S<: ColSpec ,T}
44
44
@assert 0 ≤ low ≤ high ≤ 1 " invalid quantiles"
45
45
new {S,T} (colspec, low, high)
46
46
end
47
47
end
48
48
49
- Scale (colspec:: ColSpec , low:: Real , high:: Real ) =
49
+ Scale (colspec:: ColSpec , low, high) =
50
50
Scale (colspec, promote (low, high)... )
51
51
52
52
Scale (; low= 0.25 , high= 0.75 ) = Scale (AllSpec (), low, high)
@@ -59,10 +59,11 @@ assertions(::Type{<:Scale}) = [assert_continuous]
59
59
isrevertible (:: Type{<:Scale} ) = true
60
60
61
61
function colcache (transform:: Scale , x)
62
- levels = (transform. low, transform. high)
63
- xl, xh = quantile (x, levels)
62
+ low = convert (eltype (x), transform. low)
63
+ high = convert (eltype (x), transform. high)
64
+ xl, xh = quantile (x, (low, high))
64
65
xl == xh && ((xl, xh) = (zero (xl), one (xh)))
65
- (xl = xl, xh = xh)
66
+ (; xl, xh)
66
67
end
67
68
68
69
colapply (:: Scale , x, c) = @. (x - c. xl) / (c. xh - c. xl)
0 commit comments