1

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?

4
  • 1
    "On may be anybody implemented it so I do not need do i for me myself?" Maybe your boss needs to find someone else to make it.
    – RvdK
    Sep 14, 2009 at 12:03
  • Extension methods for such purposes would be very useful, I agree. However, wouldn't you want to operate on 2D arrays, e.g. int[,] and such?
    – Noldorin
    Sep 14, 2009 at 12:07
  • "Maybe your boss needs to find someone else to make it. – PoweRoy" I just think that idea of matrix like number array extensions is not senseless. So anybody could have some home implementation of this so i do not need to start it from scratch. I cant find it in the internet. Sep 14, 2009 at 12:59
  • Wouldn't it be better to create Types like a Matrix or Vector and define the operations on them?
    – codymanix
    Sep 28, 2009 at 0:37

4 Answers 4

3

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.

1
  • 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 methods public 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 Sep 14, 2009 at 12:47
0

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.

3
  • 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. Sep 14, 2009 at 12:55
  • 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
    Sep 14, 2009 at 14:56
  • 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. Sep 14, 2009 at 17:50
0

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.

0

I wrote Matrix Extensions C# library to test extensions based code generation design.

1
  • 1
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. Aug 28, 2012 at 14:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.