Example #1
0
 public void Add(IntegerMatrix other)
 {
     for (int i = 0; i < RowSize; i++)
     {
         for (int j = 0; j < ColumnSize; j++)
         {
             Replace(i, j, Get(i, j) + other.Get(i, j));
         }
     }
 }
Example #2
0
        //TODO: classify multiplications to have the products be as explicit as possible.
        //im sure theres a better way to do this lol
        public SquareIntegerMatrix Multiply(SquareIntegerMatrix other)
        {
            IntegerMatrix       product = Multiply(other as IntegerMatrix);
            SquareIntegerMatrix ret     = new SquareIntegerMatrix(other.RowSize);

            for (int i = 0; i < RowSize; i++)
            {
                for (int j = 0; j < RowSize; j++)
                {
                    ret.Replace(i, j, product.Get(i, j));
                }
            }
            return(ret);
        }
Example #3
0
        //TODO: Be able to cast a nxn as a squareintegermatrix or a 1xn as a row vector etc.

        public static IntegerMatrix Sum(IntegerMatrix obj1, IntegerMatrix obj2)
        {
            if (!SizeParity(obj1, obj2))
            {
                throw new ArgumentException("The matrices were not in the same dimension.");
            }
            else
            {
                IntegerMatrix ret = new IntegerMatrix(obj1.RowSize, obj1.ColumnSize);
                ret.Add(obj1);
                ret.Add(obj2);
                return(ret);
            }
        }
Example #4
0
 //TODO: Test this. Pretty sure it works?
 public IntegerMatrix Multiply(IntegerMatrix other)
 {
     if (!CanMultiply(other))
     {
         throw new MultiplicationDimensionMismatchException();                      //todo
     }
     else
     {
         IntegerMatrix ret = new IntegerMatrix(RowSize, other.ColumnSize);
         for (int i = 0; i < RowSize; i++)
         {
             for (int j = 0; j < other.ColumnSize; j++)
             {
                 int[]               ro = GetRow(i).ToArray <int>();
                 int[]               co = other.GetColumn(j).ToArray <int>();
                 IntegerRowVector    v  = new IntegerRowVector(ro);
                 IntegerColumnVector w  = new IntegerColumnVector(co);
                 ret.Replace(i, j, VectorMath.DotProduct <int>(v, w));
             }
         }
         return(ret);
     }
 }