1

SWIG を使用して Matrix クラスを拡張し、python インターフェイスを作成しようとしています。公式のDocuコードを使用しました。しかし、まったくばかげたエラー メッセージが表示されます。行クラスを宣言する場所は重要ではないようです。コンパイル中に常にこのエラーが発生します。SWIG の何が問題になっていますか?

エラー:

  ANPyNetCPUPYTHON_wrap.cxx: In function ‘ANN::F2DArray ANN_F2DArray___getitem__(ANN::F2DArray*, int)’:
  ANPyNetCPUPYTHON_wrap.cxx:5192: error: ‘Grid2dRow’ was not declared in this scope
  ANPyNetCPUPYTHON_wrap.cxx:5192: error: expected `;' before ‘r’
  ANPyNetCPUPYTHON_wrap.cxx:5193: error: ‘r’ was not declared in this scope

コード:

  %{
  #include <AN2DArray.h>
  %}

  %include <AN2DArray.h>  

  %inline %{
      struct Grid2dRow {
          ANN::F2DArray *g;   // Grid
          int    y;      // Row number

          // These functions are used by Python to access sequence types (lists, tuples, ...)
          float __getitem__(int x) {
              return g->GetValue(x, y);
          }

          void __setitem__(int x, float val) {
              g->SetValue(x, y, val);
          }
      };
  %}
  %extend ANN::F2DArray 
  {
      ANN::F2DArray __getitem__(int y) {
          Grid2dRow r;
          r.g = self;
          r.y = y;
          return r;
      }
  };
4

1 に答える 1

0

生成された *.cxx を調べたところ、問題が見つかりました。SWIG ドキュメントは 2 つの点で間違っています。以下は、動作しているコードです。たぶん、同じ問題について疑問に思っている人が助けられるでしょう。

  %{
  #include <AN2DArray.h>
  %}

  %inline %{
      struct Grid2dRow {
          ANN::F2DArray *g;   // Grid
          int    y;      // Row number

          // These functions are used by Python to access sequence types (lists, tuples, ...)
          float __getitem__(int x) {
              return g->GetValue(x, y);
          }

          void __setitem__(int x, float val) {
              g->SetValue(x, y, val);
          }
      };
  %}

  %include <AN2DArray.h>  

  %addmethods ANN::F2DArray {
      Grid2dRow __getitem__(int y) {
          Grid2dRow r;
          r.g = self;
          r.y = y;
          return r;
      }
  };
于 2013-06-06T08:22:53.253 に答える