【问题标题】:Is there a way to accept an argument in a cython function without explicitly specifying its type?有没有办法在没有明确指定其类型的情况下接受 cython 函数中的参数?
【发布时间】:2018-08-02 21:38:23
【问题描述】:

我是 Cython 的新手。我正在尝试编写一个可以接受元组或列表作为参数的函数。

我知道将 void* 参数传递给 C++ 函数允许我们这样做(尽管我可能错了),但是对于 Cython 有类似的方法吗?

有没有一种方法可以通过不必明确提及tuplelist 将以下内容合并为一个? -

def shape_func(tuple a, tuple b) :
    return (a[0] > b[0])

def shape_func(list a, list b) :
    return (a[0] > b[0])

【问题讨论】:

    标签: python types cython void-pointers


    【解决方案1】:

    要么完全不使用类型,即像普通 python 函数一样编写它,要么object。无论哪种情况,都将接受任何 python 对象 (PyObject*)。

    def shape_func(a, b):
        return (a[0] > b[0])
    

    【讨论】:

      猜你喜欢
      • 2018-02-01
      • 2022-01-14
      • 2013-01-18
      • 1970-01-01
      • 2022-01-06
      • 1970-01-01
      • 1970-01-01
      • 2021-12-26
      • 2015-07-30
      相关资源
      最近更新 更多