我需要在IronPython中使用KdTree。我是从源代码构建的,并使用AddReference添加了库。在C#中有很多使用这个库的例子,但是我无法将它翻译成IronPython。我在创建对象时遇到了问题:
C#:
var tree = new KdTree<float, string>(2, new FloatMath());
IronPython的:
from KdTree import *
from KdTree.Math import *
tree = KdTree[float, str](2, FloatMath())
但我得到了:
TypeError: expected ITypeMath[float], got FloatMath
我检查了源代码并找到了构造函数:
public KdTree(int dimensions, ITypeMath<TKey> typeMath)
FloatMath正在扩展实现ITypeMath的TypeMath:
public class FloatMath : TypeMath<float>
public abstract class TypeMath<T> : ITypeMath<T>
看起来我无法将参数传递给构造函数,因为接口是预期的。我错过了什么?