Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update codebase to 1.0 and 1.x (continue #27) #31

Merged
merged 36 commits into from
Jan 29, 2020
Merged

update codebase to 1.0 and 1.x (continue #27) #31

merged 36 commits into from
Jan 29, 2020

Conversation

johnnychen94
Copy link
Collaborator

@johnnychen94 johnnychen94 commented Dec 16, 2019

This PR continues #27 and the road I choose is to:

  • fix those easy-to-fix broken tests in julia 1.0
  • fix type instability
  • update codes to 1.3 while keep backward compatibility to 1.0
  • fix the random failure in tst_scale.jl
  • support OffsetArray 1.0

There're some type-instability cases detected, which I've added a TODO comment for that, and probably fix them in a separate future PR.

To easily review the differences, the current base is set to update0.7, will change it to master before merging.

@johnnychen94 johnnychen94 changed the base branch from master to update0.7 December 16, 2019 00:44
src/distortedview.jl Outdated Show resolved Hide resolved
src/distortedview.jl Outdated Show resolved Hide resolved
src/operations/resize.jl Outdated Show resolved Hide resolved
@johnnychen94
Copy link
Collaborator Author

@Evizero could you enable Auto Cancellation of the previous build in travis?

@Evizero
Copy link
Owner

Evizero commented Dec 16, 2019

@Evizero could you enable Auto Cancellation of the previous build in travis?

It looks enabled already

grafik

This was referenced Dec 16, 2019
Only meta operations such as Either, Pipeline doesn't have Agumentor
prefix
* maybe_copy doesn't explain its usage
* replace Slice by OffsetArrays.IdentityUnitRange

JuliaArrays/OffsetArrays.jl#62
detect some type instable test cases, only the outmost wrapper is
instable here
@johnnychen94 johnnychen94 changed the base branch from update0.7 to jc/1.x December 16, 2019 22:44
@@ -117,68 +117,68 @@ end
@test Augmentor.supports_view(op) === false
@test Augmentor.supports_stepview(op) === false
@test Augmentor.supports_permute(op) === false
@test @inferred(Augmentor.applyeager(op, img)) == rotl90(rect)
@test typeof(Augmentor.applyeager(op, img)) <: OffsetArray
@test @inferred(Augmentor.applyeager(op, img, Augmentor.randparam(op, img))) == rotl90(rect) # TODO: update 1.2: type instable if remove Augmentor.randparam
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type instability is detected here for Julia 1.2; the lucky part is that only the out-most wrapper is affected.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it randparam then?

Copy link
Collaborator Author

@johnnychen94 johnnychen94 Dec 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds reasonable, I'll check that; not very familiar with this kind of issue at present.

Copy link
Collaborator Author

@johnnychen94 johnnychen94 Dec 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It turns out that the following part doesn't work anymore

# To preserve type stability of "applyeager", always promote
# arrays to offset arrays
@inline _offsetarray(A::Array) = OffsetArray(A, 0, 0)
@inline _offsetarray(A::OffsetArray) = A
function applyeager(op::Either, img::AbstractArray, idx)
_offsetarray(applyeager(op.operations[idx], img))
end

a typical error is like

ERROR: return type OffsetArray{Gray{Normed{UInt8,8}},2,Array{Gray{Normed{UInt8,8}},2}} does not match inferred return type OffsetArray

I need time to investigate it, but for now, I'll pause it for a few days just to use this package/branch to catch up with my daily work.

Copy link
Owner

@Evizero Evizero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed all your code changes so far
Thanks for working on this

src/operations/resize.jl Outdated Show resolved Hide resolved
@@ -117,68 +117,68 @@ end
@test Augmentor.supports_view(op) === false
@test Augmentor.supports_stepview(op) === false
@test Augmentor.supports_permute(op) === false
@test @inferred(Augmentor.applyeager(op, img)) == rotl90(rect)
@test typeof(Augmentor.applyeager(op, img)) <: OffsetArray
@test @inferred(Augmentor.applyeager(op, img, Augmentor.randparam(op, img))) == rotl90(rect) # TODO: update 1.2: type instable if remove Augmentor.randparam
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it randparam then?

@test_reference "reference/distort_static.txt" dv

camerao = OffsetArray(camera, (-5,-10))
dv2 = @inferred Augmentor.DistortedView(camerao, A)
@test size(dv2) == size(camera)
@test eltype(dv2) == eltype(camera)
@test summary(dv2) == "512×512 Augmentor.DistortedView(::OffsetArray{Gray{N0f8},2}, ::Array{Float64,3} as 3×3 vector field) with element type ColorTypes.Gray{FixedPointNumbers.Normed{UInt8,8}}"
@test summary(dv2) == "512×512 Augmentor.DistortedView(::Array{Gray{N0f8},2}, ::Array{Float64,3} as 3×3 vector field) with eltype Gray{Normed{UInt8,8}}"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happened here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it's related to my previous added specification to DistortedView

It's a WIP commit, I'll recheck that later when I fix julia 1.3 deprecations.

Copy link
Collaborator Author

@johnnychen94 johnnychen94 Dec 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rechecked in 733e32b and it should be a safe change here (as far as I understand the codebase)

To successfully compare two DistortedViews A and B, their axes should be the same, i.e., axes(A)==axes(B), so I add the plain_axes in the construction method to make sure this. This is still lazy-mode since plain_axes doesn't copy data. The test in tst_distortion.jl checks that as well.


I tried to use git blame to find out how in the previous codes two arrays of different axes can compare successfully but I failed, so I find another path here.

Although I think this change meets the goal of DistortedView, it does change the behavior, hence you might need to review this commit carefully. 😂

@johnnychen94
Copy link
Collaborator Author

johnnychen94 commented Dec 17, 2019

Good news is that except a random failure due to accuracy in tst_scale.jl, the whole codebase is now 1.3-compatible. Later commits are to continue WIP commits and address issues in review comments.

@Evizero
Copy link
Owner

Evizero commented Dec 19, 2019

amazing news!

@johnnychen94 johnnychen94 added this to the v0.6 milestone Dec 19, 2019
const rand_mutex = Ref{Threads.Mutex}()

# constant overhead of about 80 ns compared to unsafe rand
function safe_rand(args...)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little worried here that I might misunderstand what "threadsafe" means here. Is that mean the following two scripts should output the same results?

Random.seed!(0)
Threads.@threads for i in 1:5
    println(rand())
end
Random.seed!(0)
for i in 1:5
    println(rand())
end

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no. This has no influence on the ordering that threads invoke save_rand. It really just is about the function being threadsafe so that consecutive return values (regardless of calling thread) can be considered random

src/compat.jl Outdated
if Pkg.installed()["ImageTransformations"] <= v"0.8.3"
Interpolations.tweight(A::AbstractArray{C}) where C<:FixedPoint = C
end
Copy link
Collaborator Author

@johnnychen94 johnnychen94 Jan 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems not a good idea. 👎 and it breaks the nightly test

end
@inline function applyview(op::Either, img::AbstractArray)
applyview(op, img, randparam(op, img))
end
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The general definition is in operation.jl

for FUN in (:applyeager, :applylazy, :applypermute,
            :applyaffine, :applyaffineview,
            :applyaffine_common, :applyaffineview_common,
            :applyview, :applystepview)
    @eval begin
        function ($FUN)(op::Operation, imgs::Tuple)
            param = randparam(op, imgs)
            map(img -> ($FUN)(op, img, param), imgs)
        end
        @inline function ($FUN)(op::Operation, img::AbstractArray)
            ($FUN)(op, img, randparam(op, img))
        end
    end
end

But the inferred type for Either will be Any(without using _offsetarray) or OffsetArray. Add a specialization here tells the compiler more type information.

@johnnychen94
Copy link
Collaborator Author

This PR is growing longer and older with all these commits and it becomes hard to review. Hence I'm merging this PR regardless of two bugs not fixed( #38, #39)

@johnnychen94 johnnychen94 changed the title [WIP] update code to 1.0 and 1.x update codebase to 1.0 and 1.x (continue #27) Jan 29, 2020
@johnnychen94 johnnychen94 merged commit 7a30087 into Evizero:jc/1.x Jan 29, 2020
@johnnychen94 johnnychen94 deleted the jc/update1.0 branch January 29, 2020 07:30
johnnychen94 added a commit that referenced this pull request Jan 29, 2020
* add Project.toml

* update test for cache and minor fix

* update test for rotation and minor fix

* update flipdm to reverse

JuliaLang/julia#26369

* update test for crop and minor fix

* update test for resize

* update test for scale and minor fix

* update test for zoom and minor fix

* WIP: update test for distortion and minor fix

* update test for either and minor fix

* fix pipeline test

* update summary reference for distortedview

* WIP: fix tests for augment and operations

* drop julia 0.7 and update CI

* use FileIO v1.1.0

JuliaIO/FileIO.jl#245

* add 1.x tests to CI

* revert back unnecessary changes

* test windows in travis

* fix randomly failed test cases for inacuraccy reasons

* update to julia 1.1

* maybe_copy doesn't explain its usage
* replace Slice by OffsetArrays.IdentityUnitRange

JuliaArrays/OffsetArrays.jl#62

* update to julia 1.2 -- part I

* WIP: update to julia 1.2 -- part II

detect some type instable test cases, only the outmost wrapper is
instable here

* unify how types are displayed

Only meta operations such as Either, Pipeline doesn't have Agumentor
prefix

* add more test versions

* move safe_rand to compat.jl

rand is thread-safe in julia 1.3

* don't allow failures for julia 1.3

* fix commit "WIP: update 1.0"

* use explicit and intuitive CartesianIndex(1, 1)

* add method specialization for tweight

* allow FileIO 1.2

* fix type instability for Either

* update reference for FixedPointNumbers v0.7

* try: relax equality check for scale

* restore test cases in tst_scale.jl

* Revert "add method specialization for tweight"

This reverts commit a698382.

* Augmentor v0.6.0-pre
@johnnychen94 johnnychen94 added the no changelog tell TagBot to not add this PR into release changelog label Feb 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no changelog tell TagBot to not add this PR into release changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants