Oct2py 二元运算符“*”未实现

Oct2py binary operator '*' not implemented

我正在使用 oct2py 从 python 执行八度函数,但出现以下错误:

oct2PyError: Octave evaluation error: error: binary operator '*' not implemented for 'int64 scalar' by 'complex matrix' operations

在 python 中,我只是调用函数:

from oct2py import octave
results = octave.myOctaveFunction(parameters)

在调试myOctaveFunction时,我认为错误在代码中:

slc=interpft(slc, OSF*lines, 1);

其中:

编辑:详细回溯:

回溯(最近调用最后):

  File "/home/ezaqui/Papyrus/plugins/org.python.pydev_5.1.2.201606231256/pysrc/_pydevd_bundle/pydevd_exec.py", line 3, in Exec
    exec exp in global_vars, local_vars
  File "<console>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/oct2py/dynamic.py", line 96, in __call__
    return self._ref().feval(self.name, *inputs, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/oct2py/core.py", line 369, in feval
    store_as=store_as, plot_dir=plot_dir)
  File "/usr/local/lib/python2.7/dist-packages/oct2py/core.py", line 568, in _feval
    raise Oct2PyError(msg)
Oct2PyError: Octave evaluation error:
error: binary operator '*' not implemented for 'int64 scalar' by 'complex matrix' operations

tl;博士:

slc=interpft(slc, double(OSF*lines), 1);

解释:

您正在尝试将复数矩阵与 int64 类型相乘。 显然,乘法运算没有为这种类型定义八度;它只为双打定义。

>> int64(5) * [1 + 1i]
error: binary operator '*' not implemented for 'int64 scalar' by 'complex scalar' operations

>> double(5) * [1 + 1i]
ans =  5 + 5i

所以这不是具体的 oct2py 问题。只需确保在与八度函数中的复矩阵相乘之前将 OSF 转换为 double

至于为什么你首先得到一个复数的乘法,我怀疑 interpft 函数获取你的乘法结果并在某处乘以一个复数矩阵。事实证明,在八度音阶中,将 int64 与 double 相乘会得到 int64:

>> class(int64(5) * double(5))
ans = int64