DynAI icon indicating copy to clipboard operation
DynAI copied to clipboard

Replace dynamic hacks with generics or delegates

Open radumg opened this issue 6 years ago • 0 comments

Description

I'm using lots of dynamic types to marshall input data from a Machine.Predict() to its associated Algorithm.Predict() method. The input ends up malformed in Algorithm.Predict()

Why do it this way

The Predict method is defined on the IAlgorithm interface but since each algorithm has a different return type, it declares its inputs/outputs as dynamic.

Limitations

That wouldn't be a problem in C# land, but Dynamo doesn't like an input port with dynamic as type and unwraps lists to feed individual values - madenning ! Solved with [Arbitrary...] tag in the end so Dynamo leaves lists alone.

Dynamo also can't resolve nodes that take interfaces as inputs to ports, despite feeding it classes that implement those interfaces.

Also can't use generics like `IAlgorithm<Tinput, Toutput> as they're not known and the algorithm is stored on the machine.

What to do about it

  • potentially find a way to use generics - i wasted several hours on it already but Dynamo won't play ball
  • use delegates instead of generics
  • not return the value from Predict directly, but you'd still have the data types conversion issues.

radumg avatar Feb 27 '18 18:02 radumg