Skip to content

derivation of Tensor.matmul #30

@houstonhaynes

Description

@houstonhaynes

derivation of Tensor.matmul

Issue #437 | Created by @psiLearn | 2022-08-31 08:35:33 UTC |

My Example is this short code:

#r "nuget: DiffSharp-cpu"

open DiffSharp
open DiffSharp.Model

let createStiffnessFunction m c d =
    fun (x:Tensor) -> 
        (dsharp.tensor [[0.; 1.];[-c; -d]]).matmul(x)

let f = createStiffnessFunction 0.5 1000. 0.5

let df = dsharp.diff f

f (dsharp.tensor [0.001; 0.])
df (dsharp.tensor [0.001; 0.])

I get this error message. Is it not possible to derive the result of a matmul?

System.Exception: f must be a function of a scalar, encountered f:[|2|]->[|2|]
   at Microsoft.FSharp.Core.PrintfModule.PrintFormatToStringThenFail@1439.Invoke(String message) in D:\a\_work\1\s\src\fsharp\FSharp.Core\printf.fs:line 1439
   at DiffSharp.dsharp.fdiff(FSharpFunc`2 f, Tensor x)
   at DiffSharp.dsharp.diff(FSharpFunc`2 f, Tensor x)
   at <StartupCode$FSI_0096>.$FSI_0096.main@()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions