Reputation: 939
I need(for rapid prototyping and libraries integration) something like this(extensions for usual arrays)
double[] d;
d.SetRow(1,{ 1.1 , 2.0 ,3.3});
var r = d.GetRow(1);
d = d.AppendRight(new int[]{1,2,3});
...
Does exist such thing anywhere? On may be anybody implemented it so I do not need do i for me myself?
Upvotes: 1
Views: 1813
Reputation: 939
I wrote Matrix Extensions C# library to test extensions based code generation design.
Upvotes: 0
Reputation: 7208
Have a look at Math.NET. It is an open-source math library. You will probably find what you need.
They have an example using a matrix at the end of this page.
Upvotes: 3
Reputation: 155772
This shouldn't be too difficult to write yourself.
The thing to be very careful of is how arrays can be edited as properties.
Something like (very rough untested code, but should give you an idea):
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
}
Then you extend the array:
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 );
}
}
Then you can rely on the type parameter being inferred.
Upvotes: 0