#r "nuget: DiffSharp.Core, 1.0.7-preview1873603133"
#r "nuget: DiffSharp.Backends.Reference, 1.0.7-preview1873603133"
#r "nuget: DiffSharp.Backends.Torch, 1.0.7-preview1873603133"
open DiffSharp
open DiffSharp.Util
let t3 = dsharp.tensor [[1.1; 2.2]; [1.1; 2.2]; [1.1; 2.2]]
1 + t3 //Does work!!
open System.Linq.Expressions
let addB = Expression.Parameter(typeof<int>, "b")
let addC = Expression.Parameter(typeof<Tensor>, "c")
Expression.Add(
addC,
addB
) //=> Throw exception...
(*
System.InvalidOperationException: The binary operator Add is not defined for the types 'DiffSharp.Tensor' and 'System.Int32'.
at System.Linq.Expressions.Expression.GetUserDefinedBinaryOperatorOrThrow(ExpressionType binaryType, String name, Expression left, Expression right, Boolean liftToNull)
at System.Linq.Expressions.Expression.Add(Expression left, Expression right, MethodInfo method)
at System.Linq.Expressions.Expression.Add(Expression left, Expression right)
at <StartupCode$FSI_0048>.$FSI_0048.main@()
Stopped due to error
*)
Why 1+t3 is legal but unable to parse into Linq expression? And I would like to know, if this RFC is applied, will it helpful to resolve this issue? F# RFC FS-1043 - Extension members become available to solve operator trait constraints