owl icon indicating copy to clipboard operation
owl copied to clipboard

diff and grad don't complain when called on vector/matrix-valued functions

Open pveber opened this issue 3 years ago • 1 comments

I wonder what's the expected behavior for this code:

# open Owl
# let f x = Algodiff.D.Maths.cos x;;
val f : Owl_algodiff.D.t -> Owl_algodiff.D.t = <fun>
# let x = Algodiff.D.Mat.gaussian 3 3;;
val x : Owl_algodiff.D.t = [Arr(3,3)]
# Algodiff.D.grad f x |> Algodiff.D.Mat.print;;

          C0        C1        C2 
R0 -0.817393  0.311382  0.975356 
R1  0.701889 -0.859119  0.566911 
R2 -0.184544 -0.888166 -0.754372 
- : unit = ()

I had expected grad to complain that f evaluates to a matrix instead of a scalar. It doesn't seem to be bothered, and seems to be computing the matrix \frac{ \partial f_{ij} }{ \partial x_{ij} }, which is not really a gradient.

pveber avatar Aug 26 '20 07:08 pveber

Yes we're currently not checking the shape of the output, and you're quire right we should probably do that.

tachukao avatar Aug 26 '20 07:08 tachukao