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

Extending / refactoring to_vec API #105

Closed
willtebbutt opened this issue Aug 8, 2020 · 1 comment
Closed

Extending / refactoring to_vec API #105

willtebbutt opened this issue Aug 8, 2020 · 1 comment

Comments

@willtebbutt
Copy link
Member

The to_vec API has served us pretty well for a long time, but there are certain things that it can't handle.

In particular, when applying to_vec to Differentials it is necessary to output something of the same size as the primal to which it will be added when performing finite differencing. For example, what should to_vec(::Zero) return? Since Zero doesn't carry information around with it that tells you what primal it is going to be added to it's not possible to know how to convert it into a vector of an appropriate size.

There are other cases where this bites. For example, if the primal is a Vector and the differential a Fill. In this case, naively applying to_vec to both yields vectors of different lengths since to_vec(::Fill) returns a length-1 vector as only a single number is required to uniquely specify a Fill, while to_vec(::Vector) is essentially the identity operation.

I proposed to introduce a new function as follows:

function differential_to_vec(primal, differential)
    function from_vec(differential_vec)
        return thing_like_differential
    end
    return vector_form_differential, from_vec 
end

This function literally just ties together a primal and a differential, so that we have enough information to to_vec the differential. That is all.

@willtebbutt
Copy link
Member Author

Whether or not this is helpful depends on whether we do #97 . If we do it, it's redundant. If, for some reason, we decide not to do it, then this is important.

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

No branches or pull requests

1 participant