Skip to content

Commit c8585bb

Browse files
Kenooscarddssmith
authored andcommitted
Remove type restriction on Dual
1 parent 2ff6808 commit c8585bb

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

docs/src/dev/how_it_works.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Partial derivatives are stored in the `Partials` type:
1111

1212
```julia
1313
struct Partials{N,V} <: AbstractVector{V}
14-
values::NTuple{N,V}
14+
values::TT
1515
end
1616
```
1717

src/partials.jl

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ struct Partials{N,V} <: AbstractVector{V}
22
values::NTuple{N,V}
33
end
44

5+
Partials(values::NTuple{N, Any}) where {N} =
6+
Partials{N, mapreduce(typeof, typejoin, values)}(values)
7+
58
##############################
69
# Utility/Accessor Functions #
710
##############################
@@ -197,27 +200,27 @@ end
197200
return tupexpr(i -> :(rand(V)), N)
198201
end
199202

200-
@generated function scale_tuple(tup::NTuple{N}, x) where N
203+
@generated function scale_tuple(tup::NTuple{N, Any}, x) where N
201204
return tupexpr(i -> :(tup[$i] * x), N)
202205
end
203206

204-
@generated function div_tuple_by_scalar(tup::NTuple{N}, x) where N
207+
@generated function div_tuple_by_scalar(tup::NTuple{N, Any}, x) where N
205208
return tupexpr(i -> :(tup[$i] / x), N)
206209
end
207210

208-
@generated function add_tuples(a::NTuple{N}, b::NTuple{N}) where N
211+
@generated function add_tuples(a::NTuple{N, Any}, b::NTuple{N, Any}) where N
209212
return tupexpr(i -> :(a[$i] + b[$i]), N)
210213
end
211214

212-
@generated function sub_tuples(a::NTuple{N}, b::NTuple{N}) where N
215+
@generated function sub_tuples(a::NTuple{N, Any}, b::NTuple{N, Any}) where N
213216
return tupexpr(i -> :(a[$i] - b[$i]), N)
214217
end
215218

216-
@generated function minus_tuple(tup::NTuple{N}) where N
219+
@generated function minus_tuple(tup::NTuple{N, Any}) where N
217220
return tupexpr(i -> :(-tup[$i]), N)
218221
end
219222

220-
@generated function mul_tuples(a::NTuple{N}, b::NTuple{N}, afactor, bfactor) where N
223+
@generated function mul_tuples(a::NTuple{N, Any}, b::NTuple{N, Any}, afactor, bfactor) where N
221224
return tupexpr(i -> :((afactor * a[$i]) + (bfactor * b[$i])), N)
222225
end
223226

0 commit comments

Comments
 (0)