Пример #1
0
// Change values in some range
    public void modify(SpreadSheetRange <AI1, AI2> range, FunctionEval <V> function)
    { // Using a delegate to change the values in a range!
        // Objective is to iterate in a range and apply a function to each
        // element in that range

        AI1 rmin = range.upperLeft.first;
        AI2 cmin = range.upperLeft.second;

        AI1 rmax = range.lowerRight.first;
        AI2 cmax = range.lowerRight.second;

        int Rmin = r[rmin]; int Rmax = r[rmax];
        int Cmin = c[cmin]; int Cmax = c[cmax];


        // Now must find the integer indices corresponding to these
        V d;

        for (int ri = Rmin; ri <= Rmax; ri++)
        {
            for (int ci = Cmin; ci <= Cmax; ci++)
            {
                d = mat[ri, ci];
                function(ref d);
                mat[ri, ci] = d;
            }
        }
    }
Пример #2
0
    public NumericMatrix <V> extract(SpreadSheetRange <AI1, AI2> range)
    {
        // Slice a matrix
        AI1 rmin = range.upperLeft.first;
        AI2 cmin = range.upperLeft.second;

        AI1 rmax = range.lowerRight.first;
        AI2 cmax = range.lowerRight.second;

        int Rmin = r[rmin]; int Rmax = r[rmax];
        int Cmin = c[cmin]; int Cmax = c[cmax];

        // Now must find the integer indices corresponding to these
        NumericMatrix <V> result = new NumericMatrix <V>(Rmax - Rmin + 1, Cmax - Cmin + 1, Rmin, Cmin);

        for (int ri = Rmin; ri <= Rmax; ri++)
        {
            for (int ci = Cmin; ci <= Cmax; ci++)
            {
                result[ri, ci] = mat[ri, ci];
            }
        }

        return(result);
    }
    public static void Main()
    {
        AssocArray <int, double> assArr = new  AssocArray <int, double> ();

        assArr[0]    = 2.0;
        assArr[100]  = 3.0;
        assArr[10]   = 43.0;
        assArr[1000] = 34.0;

        Console.WriteLine(assArr[100]);
        foreach (KeyValuePair <int, double> kvp in assArr)
        {
            Console.WriteLine("{0}, {1}", kvp.Key, kvp.Value);
        }

        Set <string> names = new Set <string>();

        names.Insert("A1");
        names.Insert("A2");
        names.Insert("A3");
        names.Insert("A4");
        names.Insert("B1");

        double defaultValue = 10.0;

        AssocArray <string, double> myAssocArray = new AssocArray <string, double>(names, defaultValue);

        myAssocArray.print();
        myAssocArray["A4"] = 99.99;
        myAssocArray.print();


        // Test other functions
        AssocArray <string, double> myAssocArray2 = new AssocArray <string, double> (myAssocArray);

        myAssocArray2.print();

        AssocMatrix <string, string, double> myMat = new AssocMatrix <string, string, double>();

        myMat.print();

        // Create an associative matrix with 2 sets and a numeric matrix
        NumericMatrix <double> mat1 = new NumericMatrix <double>(names.Size(), names.Size());
        AssocMatrix <string, string, double> myMat2 = new AssocMatrix <string, string, double>(names, names, mat1);

        myMat2.print();


        // Now work with ranges in this associative matrix
        SpreadSheetVertex <long, string> ul = new SpreadSheetVertex <long, string> ();          // Upper left

        ul.first  = 1;
        ul.second = "B";

        SpreadSheetVertex <long, string> lr = new SpreadSheetVertex <long, string> ();          // Lower right

        lr.first  = 3;
        lr.second = "D";

        SpreadSheetRange <long, string> myRange = new SpreadSheetRange <long, string>();

        myRange.upperLeft  = ul;
        myRange.lowerRight = lr;

        //	myMat22.modify(myRange, Modifier1);
        //print (*(myMat2.Data()));

        // print(myMat2.extract(myRange));

        SpreadSheetVertex <string, string> ul2 = new SpreadSheetVertex <string, string>();        // Upper left

        ul2.first  = "A1";
        ul2.second = "A1";

        SpreadSheetVertex <string, string> lr2 = new SpreadSheetVertex <string, string>();        // Upper left

        lr2.first  = "A4";
        lr2.second = "A4";


        SpreadSheetRange <string, string> myRange2 = new SpreadSheetRange <string, string>();

        myRange2.upperLeft  = ul2;
        myRange2.lowerRight = lr2;



        // Now work with Dates; 101 example, later more extensive, eg. I/O witb Excel
        Set <DateTime> dates = new Set <DateTime>();

        dates.Insert(DateTime.Now);
        dates.Insert(new DateTime(2009, 3, 17));

        NumericMatrix <double> payments = new NumericMatrix <double>(dates.Size(), dates.Size());
        AssocMatrix <DateTime, DateTime, double> Sheet = new AssocMatrix <DateTime, DateTime, double>(dates, dates, payments);
    }