Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/config.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ for Config in (:GradientConfig, :JacobianConfig)
seeds::NTuple{N,Partials{N,T}}
duals::D
# disable default outer constructor
function $Config(seeds, duals)
@assert N <= CHUNK_THRESHOLD
new(seeds, duals)
end
$Config(seeds, duals) = new(seeds, duals)
end

# This is type-unstable, which is why our docs advise users to manually enter a chunk size
Expand Down
6 changes: 4 additions & 2 deletions src/partials.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
immutable Partials{N,T} <: AbstractArray{N,T}
immutable Partials{N,T} <: AbstractVector{T}
values::NTuple{N,T}
end

Expand All @@ -15,13 +15,15 @@ end
@inline Base.length{N}(::Partials{N}) = N
@inline Base.size{N}(::Partials{N}) = (N,)

@inline Base.getindex(partials::Partials, i) = partials.values[i]
@inline Base.getindex(partials::Partials, i::Int) = partials.values[i]
setindex{N,T}(partials::Partials{N,T}, v, i) = Partials{N,T}((partials[1:i-1]..., v, partials[i+1:N]...))

Base.start(partials::Partials) = start(partials.values)
Base.next(partials::Partials, i) = next(partials.values, i)
Base.done(partials::Partials, i) = done(partials.values, i)

Base.linearindexing(::Partials) = Base.LinearFast()

#####################
# Generic Functions #
#####################
Expand Down
1 change: 1 addition & 0 deletions test/PartialsTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ for N in (0, 3), T in (Int, Float32, Float64)
@test ForwardDiff.npartials(PARTIALS) == N
@test ForwardDiff.npartials(typeof(PARTIALS)) == N

@test ndims(PARTIALS) == ndims(PARTIALS2) == 1
@test length(PARTIALS) == N
@test length(VALUES) == N

Expand Down
14 changes: 7 additions & 7 deletions test/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import ForwardDiff
using ForwardDiff.CHUNK_THRESHOLD
using Base.Test

const XLEN = CHUNK_THRESHOLD
# seed RNG, thus making result inaccuracies deterministic
# so we don't have to retune EPS for arbitrary inputs
srand(1)

const XLEN = CHUNK_THRESHOLD + 1
const YLEN = div(CHUNK_THRESHOLD, 2) + 1
const X, Y = rand(XLEN), rand(YLEN)
const CHUNK_SIZES = (1, div(CHUNK_THRESHOLD, 3), div(CHUNK_THRESHOLD, 2), CHUNK_THRESHOLD)
const FINITEDIFF_ERROR = 1e-5
const CHUNK_SIZES = (1, div(CHUNK_THRESHOLD, 3), div(CHUNK_THRESHOLD, 2), CHUNK_THRESHOLD, CHUNK_THRESHOLD + 1)
const FINITEDIFF_ERROR = 1.5e-5

# used to test against results calculated via finite difference
test_approx_eps(a::Array, b::Array) = @test_approx_eq_eps a b EPS

# seed RNG, thus making result inaccuracies deterministic
# so we don't have to retune EPS for arbitrary inputs
srand(1)