Home
Insert
Update snippet 'Useful operator definition for interop with C# '
Title
Description
invokes op_Implicit when applied (for implicit conversions). I have found this to be very convenient when using C# libraries
Source code
let inline (!>) (x:^a) : ^b = ((^a or ^b) : (static member op_Implicit : ^a -> ^b) x) (* //Example based on Tensorflow.Net open Tensorflow let tf = Tensorflow.Binding.tf let modelFile = @"uncased_L-12_H-768_A-12\bert_model.ckpt.meta" let graph = tf.Graph().as_default() let saver = tf.train.import_meta_graph(modelFile) //convert Operation to Tensor using implicit conversion operator let input_tensor : Tensor = !> graph.OperationByName("Placeholder") //alternatively have to do this: let op = graph.OperationByName("Placeholder") let tensor = new Tensor(op,0,TF_DataType.TF_INT32) *)
Tags
c#
interoperability
c#
interoperability
Author
Link
Reference NuGet packages
If your snippet has external dependencies, enter the names of NuGet packages to reference, separated by a comma (
#r
directives are not required).
Update