Skip to content
This repository has been archived by the owner on Jan 28, 2020. It is now read-only.

Commit

Permalink
Fix for transforms with non-real numbers
Browse files Browse the repository at this point in the history
Also adds DualNumbers as a testing requirement
  • Loading branch information
timholy committed Dec 21, 2015
1 parent f5dbfd0 commit 04efc81
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/tformedarrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,11 @@ center(A::AbstractArray) = [(size(A,d)+1)/2 for d = 1:ndims(A)]
function irange(imin::Int, imax::Int, coef, offset, upper)
const thresh = 10^4/typemax(Int) # needed to avoid InexactError for results with abs() bigger than typemax
if coef > thresh
return max(imin, floor(Int, (1-offset)/coef)), min(imax, ceil(Int, (upper-offset)/coef))
return max(imin, floor(Int, real((1-offset)/coef))), min(imax, ceil(Int, real((upper-offset)/coef)))
elseif coef < -thresh
return max(imin, floor(Int, (upper-offset)/coef)), min(imax, ceil(Int, (1-offset)/coef))
return max(imin, floor(Int, real((upper-offset)/coef))), min(imax, ceil(Int, real((1-offset)/coef)))
else
if 1 <= offset <= upper
if 1 <= real(offset) <= upper
return imin, imax
else
return 1, 0 # empty range
Expand Down
1 change: 1 addition & 0 deletions test/REQUIRE
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Images
DualNumbers
7 changes: 7 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,10 @@ dest3 = zeros(3,3)
itp = interpolate(A, BSpline(Constant()), OnCell())
tA = AffineTransforms.TransformedArray(extrapolate(itp, NaN), tfm)
@test AffineTransforms.transform!(dest, tA) == [2 3; 6 7]

# Transforms with non-real numbers
using DualNumbers
a = AffineTransforms.tformtranslate([0,dual(1,0)])
A = reshape(1:9, 3, 3)
At = AffineTransforms.transform(A, a)
@test real(At[:,1:2]) == A[:,2:3]

0 comments on commit 04efc81

Please sign in to comment.