Skip to content

Conversation

@yashvardhan747
Copy link
Contributor

@yashvardhan747 yashvardhan747 commented Apr 10, 2019

Solves#136

end

struct BasicContractor{F1<:Function, F2<:Function} <:AbstractContractor
forward::GeneratedFunction{F1}
Copy link
Member

Choose a reason for hiding this comment

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

We don't need the code that's stored in a GeneratedFunction; this should just be the function itself.

Copy link
Member

Choose a reason for hiding this comment

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

The goal is to have an object that satisfies isbitstype(C) == true.


function (C::Contractor{N,Nout,F1,F2,ex})(
A::IntervalBox{Nout,T}, X::IntervalBox{N,T}) where {N,Nout,F1,F2,ex,T}
function (C::Contractor{N,1,F1,F2,ex})(
Copy link
Member

Choose a reason for hiding this comment

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

You can remove all the type parameters in this function, since we don't need them

(C::Contractor{N,1,F1,F2,ex})(A::Interval{T}, X::IntervalBox{N,T}) where {N,F1,F2,ex,T} = C(IntervalBox(A), X)


function (C::BasicContractor{F1,F2})(
Copy link
Member

Choose a reason for hiding this comment

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

Ah, I forgot that you can't define this for abstract types :/ You can use metaprogramming instead to avoid this code duplication.

Copy link
Member

Choose a reason for hiding this comment

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

Actually the easier thing would just be to factor out the contents of the function into a new function.

(C::Contractor)(A::Interval{T}, X::IntervalBox{N,T}) where {N,T} = C(IntervalBox(A), X)


function Forward(C::AbstractContractor)
Copy link
Member

Choose a reason for hiding this comment

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

forward

Copy link
Member

Choose a reason for hiding this comment

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

You can write this in one line.

return C.forward
end

function Backward(C::AbstractContractor)
Copy link
Member

Choose a reason for hiding this comment

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

backward


function (C::Contractor{N,Nout,F1,F2,ex})(
A::IntervalBox{Nout,T}, X::IntervalBox{N,T}) where {N,Nout,F1,F2,ex,T}
function (C::BasicContractor)(
Copy link
Member

Choose a reason for hiding this comment

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

This is a duplication of the code at line 52. This is what needs to be factored out.


function (C::Contractor{N,Nout,F1,F2,ex})(
A::IntervalBox{Nout,T}, X::IntervalBox{N,T}) where {N,Nout,F1,F2,ex,T}
function Contract(C::AbstractContractor, A::IntervalBox{Nout,T}, X::IntervalBox{N,T})where {N,Nout,T}
Copy link
Member

Choose a reason for hiding this comment

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

contract

Capitals for types, lower case for functions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cool..

@dpsanders
Copy link
Member

LGTM, thanks!

@dpsanders dpsanders merged commit 6ab8635 into JuliaIntervals:master Apr 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants