2016-07-13 1 views
2

私はそこにいると思いますですが、私のGoogle-fuは私に失敗し、Genieのドキュメントページもありました。このプログラムをValaからGenieにどのように翻訳できますか?

のは、thereからいくつかのValaのコードを非常に具体的な例を見てみましょう:ここ

using GLib; 
using Gsl; 

public class Test : GLib.Object 
{ 
     public static void main (string[] args) 
     { 
       double[] a_data = new double[] { 0.18, 0.60, 0.57, 0.96, 
               0.41, 0.24, 0.99, 0.58, 
               0.14, 0.30, 0.97, 0.66, 
               0.51, 0.13, 0.19, 0.85 }; 

       double[] b_data = new double[] { 1.0, 2.0, 3.0, 4.0 }; 

       MatrixView m = MatrixView.array (a_data, 4, 4); 
       VectorView b = VectorView.array (b_data); 

       Vector x = new Vector (4); 

       int s; 

       Permutation p = new Permutation (4); 

       LinAlg.LU_decomp ((Matrix)(&m.matrix), p, out s); 
       LinAlg.LU_solve ((Matrix)(&m.matrix), p, (Vector)(&b.vector), x); 

       stdout.printf("x = \n"); 
       Vector.fprintf(stdout, x, "%g"); 
     } 
} 

は、私は魔神にそのプログラムを変換しようとした方法である:

this referenceあたりとして正しいはず
[indent=4] 

uses Gsl 

init 
    a_data: array of double = { 0.18, 0.60, 0.57, 0.96, 
           0.41, 0.24, 0.99, 0.58, 
           0.14, 0.30, 0.97, 0.66, 
           0.51, 0.13, 0.19, 0.85 } 
    b_data: array of double = { 1.0, 2.0, 3.0, 4.0 } 

    var m = Gsl.MatrixView.array(a_data, 4, 4) 
    var b = Gsl.VectorView.array(b_data) 

    var x = new Gsl.Vector(4) 

    s:int = 0 

    var p = new Gsl.Permutation(4) 

    Gsl.LinAlg.LU_decomp(m, p, out s) 
    Gsl.LinAlg.LU_solve(m, p, b, x) 

    print "x =\n%g", x 

しかし、それは失敗します。

LA.gs:12.28-12.32: error: syntax error, expected identifier 
    var m = Gsl.MatrixView.array(a_data, 4, 4) 
          ^^^^^ 
LA.gs:13.28-13.32: error: syntax error, expected identifier 
    var b = Gsl.VectorView.array(b_data) 
          ^^^^^ 
Compilation failed: 2 error(s), 0 warning(s) 

だから、誰もがその特定のエラーが何を意味するのか私に説明してくださいだろうか? Genieのコンテキスト内の識別子は何ですか?

そして、Genieでこのような静的メソッドを呼び出す正しい方法は何ですか?

答えて

2

配列は予約キーワードであるので、あなたは予約語の前での@ -signを追加する必要があります。

var m = [email protected](a_data, 4, 4) 
var b = [email protected](b_data) 

印刷ラインは、私はほとんどの問題を修正し、また、間違っています:

[indent=4] 

uses Gsl 

init 
    a_data: array of double = { 0.18, 0.60, 0.57, 0.96, 
           0.41, 0.24, 0.99, 0.58, 
           0.14, 0.30, 0.97, 0.66, 
           0.51, 0.13, 0.19, 0.85 } 
    b_data: array of double = { 1.0, 2.0, 3.0, 4.0 } 

    var m = [email protected](a_data, 4, 4) 
    var b = [email protected](b_data) 

    var x = new Gsl.Vector(4) 

    s:int = 0 

    var p = new Gsl.Permutation(4) 

    Gsl.LinAlg.LU_decomp((Matrix) m, p, out s) 
    Gsl.LinAlg.LU_solve((Matrix) m, p, (Vector) b.vector, x) 

    stdout.printf("x =\n") 
    Vector.fprintf(stdout, x, "%g") 

LU_メソッドは、私が100%確実に行うことができない型変換を必要とするため、これはまだコンパイルされません。最初

[indent=4] 

uses Gsl 

init 
    a_data: array of double = { 0.18, 0.60, 0.57, 0.96, 
           0.41, 0.24, 0.99, 0.58, 
           0.14, 0.30, 0.97, 0.66, 
           0.51, 0.13, 0.19, 0.85 } 
    b_data: array of double = { 1.0, 2.0, 3.0, 4.0 } 

    var m = [email protected](a_data, 4, 4) 
    var b = [email protected](b_data) 

    var x = new Gsl.Vector(4) 

    s:int = 0 

    var p = new Gsl.Permutation(4) 

    mp : MatrixView* = &m 
    vp : Vector** = &(b.vector) 

    Gsl.LinAlg.LU_decomp((Matrix) mp, p, out s) 
    Gsl.LinAlg.LU_solve((Matrix) mp, p, (Vector) vp, x) 

    stdout.printf("x =\n") 
    Vector.fprintf(stdout, x, "%g") 
+0

ので、最初のもの:

アップデート:このコードはコンパイルして実行されますが、その実際に正しい場合、私は見当がつかない!**おかげで**これは実際に期待通りに働いています。私はプログラムの最後の部分についてはまったく期待していませんでした。後でそれを修正しようとしましたが、あなたもそれをやっていました。もう一度ありがとう!今は私が好きなだけのものを作業ベースから微調整できます。ちょうど最後のこと:予約されたキーワードの衝突は修正されませんか?つまり、 'array'が単独であれば、クラッシュしても問題ありません。結局予約されています。しかし、ここでは配列はおそらく他のものではありません。だからそれは問題か何かが期待されていると考えられますか? – JohnW

+1

Hum ...実際には、MatrixViewとVectorからポインタを取得する必要はありません。MatrixView.matrixとVector.vectorのフィールドはそのまま使用できますValaで(それはより良いです)。しかし、とにかく、あなたは本当に状況をブロック解除しました!ジニーは本当に親切です:) – JohnW

+0

私はコンパイラの開発者ではないので、わかりません。あなたが本当に知りたいのであれば、https://bugzilla.gnome.org(製品Vala、コンポーネントGenie)にバグレポートを提出できます。もちろん、コンパイラのソースコードを読んでパッチを提案することもできます。 –

関連する問題