Menu

Overloading Functions

Help
Conrad
2016-12-31
2017-01-10
  • Conrad

    Conrad - 2016-12-31

    Hello! I’m using Adigator for a code to invert an ice sheet model. I was wondering if there is any manual/advice/documentation for overloading functions? Essentially I have a function which contains backslash.

    So I’m solving a system of linear equations:
    u = A\x

    Where A is function of two further variables: A(C,N). In my code this appears as:
    u = invFunc(C,N).

    Because of the backslash this function is not suitable for AD. However, I can manually differentiate ‘invFunc’, and can write a second function that can return u.f and u.dN or u.f and u.dC. Hence, is there a way for adigator to bypass invFunc, and somehow call my manually differentiated function?

    Thanks!

     

    Last edit: Conrad 2017-01-03
  • Matthew J. Weinstein

    Hi Conrad,

    Sorry for the late reply, I have been out on travel for awhile.

    ADiGator should be able to differentiate u = A\x, I am guessing the method it uses isn't as numerically stable as you would like?

    Unfortunately there isn't any documentation for manually overloading functions - you can most definitely modify the @cada/mldivide.m routine, or alternatively create a function in adigator/lib/@cada/invFunc.m. That function then just needs to do different things depending upon what flags are set (just call cadaEmptyEval if ADIGATOR.EMPTYFLAG = 1, do all sparsity propagation otherwise, print out function/derivative statements if ADIGATOR.PRINT.FLAG = 1).

    You would be best served to look at examples of overloaded functions to start with and perhaps use something like @cada/cross.m as a template (though it has a lot of code for printing out derivatives that may look more complicated than it is). You may also find chapter three of my disseration helpful, it is here: http://ufdc.ufl.edu/UFE0047841/00001 - it should help with the class properties.

    Also, if you create @cada/invFunc.m, you may want to grab the fresh copy of adigator.m from https://sourceforge.net/p/adigator/code/HEAD/tree/trunk/adigator.m - at some point I made changes so you can overload any non-native matlab function, but I do not remember if it is in the current release.

    Hope that is useful!

    Matt

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.