views:

366

answers:

4

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?

A: 

Languages like Python support lists with mixed types. You can create an IronPython script and then call it from your C# application. Follow this link to see how you can call IronPython script from your app.

Vadim
+3  A: 

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.

Francis B.
I know about Math.NET, dnAnalytics and etc. But they all have matrix classes.But I do not need them. What I need:For ex i can compare my algorithm of classification with thous are in SVM.NET, NeronDotNet, alglib.net.They all use different arrays in methodspublic Problem(int count, double[] y, Node[][] x, int maxIndex)public static void nbcbuildm(ref double[,] xy,ref bool[,] m, int npoints,ref int[] f,int nvars,int nclasses,int flags,ref int info,ref double[] b,ref nbcreport rep)...I need conversion and data preparation routines - ideally - array extensions
asd.and.Rizzo
A: 

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.

Keith
I do not need any classes. I know about extensions and generic types.I can implement everything myself. But it will take time not only to write, but to test - so that everything works correctly.So I ask about existence of such codebase so I will not need to start from scratch.
asd.and.Rizzo
I'm afraid I don't know of an existing library for this. With your example you will need some sort of class for your `var r = d.GetRow...` - as the results of that will be a copy of a 'row' rather than a reference to the multidimensional array
Keith
Copy (as double[] instance) is Ok. I do not care about performance and memory usage. MATLAB like behavior(no way to get row reference) satisfies me.
asd.and.Rizzo