尽管事实上解决了一个新问题,但仍要跟进a question I asked alreadykind of solved as far as I got the answer to my question,即:
使用Complex API的问题是它无法从NMatrixAPI中识别形状方法:
所以当我在my compiled C extension上运行以下规范代码时:

  it "Creates a new FFTW.r2c object and takes an a 1D NMatrix as its argument" do
    n = NMatrix.new([4], [3.10, 1.73, 1.04, 2.83])

    r = FFTW.Z(n)
    i = FFTW.Z(FFTW.r2c_one(r))
    #expect(fftw).to eq(fftw)
  end

有一个错误,因为shape属于nmatrix类。
 FFTW Creates a new FFTW.r2c object and takes an a 1D NMatrix as its argument
     Failure/Error: i = FFTW.Z(FFTW.r2c_one(r))
     NoMethodError:
       undefined method `shape' for NMatrix:Class
     # ./spec/fftw_spec.rb:26:in `r2c_one'
     # ./spec/fftw_spec.rb:26:in `block (2 levels) in <top (required)>'

Shape是从nmatrix类调用的,因此我可以理解为什么会发生这种情况,但不知道如何绕过它。
结果
  it "Creates a new FFTW.r2c object and takes an a 1D NMatrix as its argument" do
    n = NMatrix.new([4], [3.10, 1.73, 1.04, 2.83])

    fftw = FFTW.Z(n)
    expect(fftw).to eq(fftw)
  end


/home/magpie/.rvm/rubies/ruby-2.1.2/bin/ruby -I/home/magpie/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/lib:/home/magpie/.rvm/gems/ruby-2.1.2/gems/rspec-support-3.0.4/lib -S /home/magpie/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/exe/rspec ./spec/fftw_spec.rb
./lib/fftw/fftw.so found!

FFTW
  creates an NMatrix object
  Fills dense with individual assignments
  Creates a new FFTW.r2c object and takes an a 1D NMatrix as its argument

Finished in 0.00091 seconds (files took 0.07199 seconds to load)
3 examples, 0 failures

最佳答案

我认为问题在于fftw.cpp中的这段代码
第51-56行:

static VALUE
fftw_shape(VALUE self)
{
  // shape is a ruby array, e.g. [2, 2] for a 2x2 matrix
  return rb_funcall(cNMatrix, rb_intern("shape"), 0);
}

你想在NMatrix类中调用shape。rb_funcall的工作方式如下:
rb_funcall(object_to_invoke_method, method_to_invoke, number_of_args, ...)

问题是第一个参数位置有cNMatrix,所以它试图将shape方法发送到NMatrix类,而不是对象。所以您真的想在nmatrix对象上调用它,比如:
static VALUE
fftw_shape(VALUE self, VALUE nmatrix)
{
  // shape is a ruby array, e.g. [2, 2] for a 2x2 matrix
  return rb_funcall(nmatrix, rb_intern("shape"), 0);
}

在82号线上:
VALUE shape = fftw_shape(self, nmatrix);

有帮助吗?我认为唯一的问题是您在类上调用shape,但可能会出现其他问题。

09-17 20:08