double [、]、int []、bool []…マトリックス、C#のベクトル操作拡張
質問
(ラピッドプロトタイピングとライブラリ統合のため)このようなものが必要です(通常の配列の拡張)
double[] d;
d.SetRow(1,{ 1.1 , 2.0 ,3.3});
var r = d.GetRow(1);
d = d.AppendRight(new int[]{1,2,3});
...
そのようなものはどこかに存在しますか? 誰かがそれを実装しているかもしれないので、私は自分で私をする必要はありませんか?
解決
これは、自分で書くのが難しくないはずです。
非常に注意すべきことは、プロパティとして配列を編集する方法です。
次のようなもの(テストされていない非常に大まかなコードですが、アイデアが得られるはずです):
public class ArrayRow<T> {
//add your own ..ctor etc
T[,] matrix; //don't make this public see http://msdn.microsoft.com/en-us/library/k2604h5s.aspx
public int Index { get; private set; }
//note that this will be a copy
public T[] GetValues() {
T[] retval = new T[matrix.GetLength(1)];
for ( int i = 0; i < retval.Length; i++ )
retval[i] = matrix[Index, i];
return retval;
}
public void SetValues(T[] values)
//..and so on, you get the idea
}
次に配列を拡張します:
public static ArrayExtensions {
public void SetRow<T> ( this T[,] matrix, int rowIndex, T[] values ) {
//check rowIndex in range and array lengths match
}
public ArrayRow<T> GetRow<T> ( this T[,] matrix, int rowIndex ) {
//check rowIndex in range
return new ArrayRow<T> ( matrix, rowIndex );
}
}
その後、推論されるtypeパラメーターに依存できます。
他のヒント
Pythonなどの言語は、混合型のリストをサポートしています。 IronPythonスクリプトを作成してから、C#アプリケーションから呼び出すことができます。 このリンクを使用して、アプリからIronPythonスクリプトを呼び出す方法を確認してください。
Matrix Extensions C#ライブラリを作成しました拡張機能ベースのコード生成設計をテストします。
所属していません StackOverflow