public Func <Tensor[], Tensor> customGrad(CustomGradientFunc f, string fName) { return((Tensor[] inputs) => { this.customGradientDepth++; Func <Tensor, List <Tensor> > gradientsFunc = null; var gradientsMode = true; var result = this.tidy("gradients", () => { var gr = f(inputs); gradientsFunc = gr.gradFunc; return gr.value; }, gradientsMode); this.customGradientDepth--; if (this.shouldRecord()) { Func <Tensor, Tensor[]> gradFunc = (Tensor dy) => { return gradientsFunc(dy).ToArray(); }; this.addTapeNode(inputs, result, gradFunc); } return result; }); }
public static Func <Tensor[], Tensor> customGrad(CustomGradientFunc f) { return(ENV.engine.customGrad(f, f.ToString())); }