Skip to content

Commit e708edb

Browse files
committed
change T to V in Partials code to avoid confusion with tag parameter
1 parent bfd5baf commit e708edb

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

src/partials.jl

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
immutable Partials{N,T} <: AbstractVector{T}
2-
values::NTuple{N,T}
1+
immutable Partials{N,V} <: AbstractVector{V}
2+
values::NTuple{N,V}
33
end
44

55
##############################
66
# Utility/Accessor Functions #
77
##############################
88

9-
@generated function single_seed(::Type{Partials{N,T}}, ::Type{Val{i}}) where {N,T,i}
10-
ex = Expr(:tuple, [ifelse(i === j, :(one(T)), :(zero(T))) for j in 1:N]...)
9+
@generated function single_seed(::Type{Partials{N,V}}, ::Type{Val{i}}) where {N,V,i}
10+
ex = Expr(:tuple, [ifelse(i === j, :(one(V)), :(zero(V))) for j in 1:N]...)
1111
return :(Partials($(ex)))
1212
end
1313

14-
@inline valtype(::Partials{N,T}) where {N,T} = T
15-
@inline valtype(::Type{Partials{N,T}}) where {N,T} = T
14+
@inline valtype(::Partials{N,V}) where {N,V} = V
15+
@inline valtype(::Type{Partials{N,V}}) where {N,V} = V
1616

1717
@inline npartials(::Partials{N}) where {N} = N
18-
@inline npartials(::Type{Partials{N,T}}) where {N,T} = N
18+
@inline npartials(::Type{Partials{N,V}}) where {N,V} = N
1919

2020
@inline Base.length(::Partials{N}) where {N} = N
2121
@inline Base.size(::Partials{N}) where {N} = (N,)
@@ -35,15 +35,15 @@ Base.IndexStyle(::Type{<:Partials}) = IndexLinear()
3535
@inline iszero(partials::Partials) = iszero_tuple(partials.values)
3636

3737
@inline Base.zero(partials::Partials) = zero(typeof(partials))
38-
@inline Base.zero(::Type{Partials{N,T}}) where {N,T} = Partials{N,T}(zero_tuple(NTuple{N,T}))
38+
@inline Base.zero(::Type{Partials{N,V}}) where {N,V} = Partials{N,V}(zero_tuple(NTuple{N,V}))
3939

4040
@inline Base.one(partials::Partials) = one(typeof(partials))
41-
@inline Base.one(::Type{Partials{N,T}}) where {N,T} = Partials{N,T}(one_tuple(NTuple{N,T}))
41+
@inline Base.one(::Type{Partials{N,V}}) where {N,V} = Partials{N,V}(one_tuple(NTuple{N,V}))
4242

4343
@inline Base.rand(partials::Partials) = rand(typeof(partials))
44-
@inline Base.rand(::Type{Partials{N,T}}) where {N,T} = Partials{N,T}(rand_tuple(NTuple{N,T}))
44+
@inline Base.rand(::Type{Partials{N,V}}) where {N,V} = Partials{N,V}(rand_tuple(NTuple{N,V}))
4545
@inline Base.rand(rng::AbstractRNG, partials::Partials) = rand(rng, typeof(partials))
46-
@inline Base.rand(rng::AbstractRNG, ::Type{Partials{N,T}}) where {N,T} = Partials{N,T}(rand_tuple(rng, NTuple{N,T}))
46+
@inline Base.rand(rng::AbstractRNG, ::Type{Partials{N,V}}) where {N,V} = Partials{N,V}(rand_tuple(rng, NTuple{N,V}))
4747

4848
Base.isequal(a::Partials{N}, b::Partials{N}) where {N} = isequal(a.values, b.values)
4949
Base.:(==)(a::Partials{N}, b::Partials{N}) where {N} = a.values == b.values
@@ -55,7 +55,7 @@ Base.hash(partials::Partials, hsh::UInt64) = hash(hash(partials), hsh)
5555

5656
@inline Base.copy(partials::Partials) = partials
5757

58-
Base.read(io::IO, ::Type{Partials{N,T}}) where {N,T} = Partials{N,T}(ntuple(i->read(io, T), Val{N}))
58+
Base.read(io::IO, ::Type{Partials{N,V}}) where {N,V} = Partials{N,V}(ntuple(i->read(io, V), Val{N}))
5959

6060
function Base.write(io::IO, partials::Partials)
6161
for p in partials
@@ -69,8 +69,8 @@ end
6969

7070
Base.promote_rule(::Type{Partials{N,A}}, ::Type{Partials{N,B}}) where {N,A,B} = Partials{N,promote_type(A, B)}
7171

72-
Base.convert(::Type{Partials{N,T}}, partials::Partials) where {N,T} = Partials{N,T}(partials.values)
73-
Base.convert(::Type{Partials{N,T}}, partials::Partials{N,T}) where {N,T} = partials
72+
Base.convert(::Type{Partials{N,V}}, partials::Partials) where {N,V} = Partials{N,V}(partials.values)
73+
Base.convert(::Type{Partials{N,V}}, partials::Partials{N,V}) where {N,V} = partials
7474

7575
########################
7676
# Arithmetic Functions #
@@ -123,10 +123,10 @@ end
123123

124124
@inline Base.:+(a::Partials{0,A}, b::Partials{0,B}) where {A,B} = Partials{0,promote_type(A,B)}(tuple())
125125
@inline Base.:-(a::Partials{0,A}, b::Partials{0,B}) where {A,B} = Partials{0,promote_type(A,B)}(tuple())
126-
@inline Base.:-(partials::Partials{0,T}) where {T} = partials
127-
@inline Base.:*(partials::Partials{0,T}, x::Real) where {T} = Partials{0,promote_type(T,typeof(x))}(tuple())
128-
@inline Base.:*(x::Real, partials::Partials{0,T}) where {T} = Partials{0,promote_type(T,typeof(x))}(tuple())
129-
@inline Base.:/(partials::Partials{0,T}, x::Real) where {T} = Partials{0,promote_type(T,typeof(x))}(tuple())
126+
@inline Base.:-(partials::Partials{0,V}) where {V} = partials
127+
@inline Base.:*(partials::Partials{0,V}, x::Real) where {V} = Partials{0,promote_type(V,typeof(x))}(tuple())
128+
@inline Base.:*(x::Real, partials::Partials{0,V}) where {V} = Partials{0,promote_type(V,typeof(x))}(tuple())
129+
@inline Base.:/(partials::Partials{0,V}, x::Real) where {V} = Partials{0,promote_type(V,typeof(x))}(tuple())
130130

131131
@inline _mul_partials(a::Partials{0,A}, b::Partials{0,B}, afactor, bfactor) where {A,B} = Partials{0,promote_type(A,B)}(tuple())
132132
@inline _div_partials(a::Partials{0,A}, b::Partials{0,B}, afactor, bfactor) where {A,B} = Partials{0,promote_type(A,B)}(tuple())
@@ -154,37 +154,37 @@ end
154154
@inline rand_tuple(::AbstractRNG, ::Type{Tuple{}}) = tuple()
155155
@inline rand_tuple(::Type{Tuple{}}) = tuple()
156156

157-
@generated function iszero_tuple(tup::NTuple{N,T}) where {N,T}
157+
@generated function iszero_tuple(tup::NTuple{N,V}) where {N,V}
158158
ex = Expr(:&&, [:(z == tup[$i]) for i=1:N]...)
159159
return quote
160-
z = zero(T)
160+
z = zero(V)
161161
$(Expr(:meta, :inline))
162162
@inbounds return $ex
163163
end
164164
end
165165

166-
@generated function zero_tuple(::Type{NTuple{N,T}}) where {N,T}
166+
@generated function zero_tuple(::Type{NTuple{N,V}}) where {N,V}
167167
ex = tupexpr(i -> :(z), N)
168168
return quote
169-
z = zero(T)
169+
z = zero(V)
170170
return $ex
171171
end
172172
end
173173

174-
@generated function one_tuple(::Type{NTuple{N,T}}) where {N,T}
174+
@generated function one_tuple(::Type{NTuple{N,V}}) where {N,V}
175175
ex = tupexpr(i -> :(z), N)
176176
return quote
177-
z = one(T)
177+
z = one(V)
178178
return $ex
179179
end
180180
end
181181

182-
@generated function rand_tuple(rng::AbstractRNG, ::Type{NTuple{N,T}}) where {N,T}
183-
return tupexpr(i -> :(rand(rng, T)), N)
182+
@generated function rand_tuple(rng::AbstractRNG, ::Type{NTuple{N,V}}) where {N,V}
183+
return tupexpr(i -> :(rand(rng, V)), N)
184184
end
185185

186-
@generated function rand_tuple(::Type{NTuple{N,T}}) where {N,T}
187-
return tupexpr(i -> :(rand(T)), N)
186+
@generated function rand_tuple(::Type{NTuple{N,V}}) where {N,V}
187+
return tupexpr(i -> :(rand(V)), N)
188188
end
189189

190190
@generated function scale_tuple(tup::NTuple{N}, x) where N

0 commit comments

Comments
 (0)