Пример #1
0
        public static Matrix MatMul(Matrix a, Matrix b)
        {
            if (a.Shape != b.Shape)
            {
                throw new Exception("Matrices must be of equal shape");
            }

            var gc     = new GenericCloner <Matrix>();
            var aClone = gc.Clone(a);
            var bClone = gc.Clone(b);

            var resultList = new List <Vector>();

            for (var i = 0; i < aClone.Rows; i++)
            {
                var resultRowList = new List <double>();

                for (var j = 0; j < bClone.Columns; j++)
                {
                    resultRowList.Add(Vector.DotProduct(aClone.GetRow(i), bClone.GetColumn(j)));
                }

                var resultRowVector = new Vector(resultRowList);

                resultList.Add(resultRowVector);
            }

            return(new Matrix(resultList, VectorStyles.Row));
        }
Пример #2
0
 private static ICloner <T> GetGenericCloner(Type type)
 {
     if (type.IsImplementationOf(typeof(ICloneable <T>)))
     {
         return(GenericCloner.GetInstance());
     }
     return(null);
 }
Пример #3
0
        public static Matrix operator *(double a, Matrix b)
        {
            var gc     = new GenericCloner <Matrix>();
            var bClone = gc.Clone(b);

            for (var i = 0; i < bClone.Rows; i++)
            {
                for (var j = 0; j < bClone.Columns; j++)
                {
                    bClone[i, j] *= a;
                }
            }

            return(bClone);
        }
Пример #4
0
        public static Matrix operator +(Matrix a, Matrix b)
        {
            if (a.Shape != b.Shape)
            {
                throw new Exception("Both matrices must be of same shape!");
            }

            var gc     = new GenericCloner <Matrix>();
            var aClone = gc.Clone(a);
            var bClone = gc.Clone(b);

            var resultMatrix = new Matrix(a.Rows, a.Columns);

            for (var i = 0; i < resultMatrix.Rows; i++)
            {
                for (var j = 0; j < resultMatrix.Columns; j++)
                {
                    resultMatrix[i, j] = aClone[i, j] + bClone[i, j];
                }
            }

            return(resultMatrix);
        }
Пример #5
0
 public virtual object Clone()
 {
     return(GenericCloner.Clone <LineTerminal> (this));
 }
Пример #6
0
        private static Vector DeepCopy(Vector other)
        {
            var gc = new GenericCloner <Vector>();

            return(gc.Clone(other));
        }
Пример #7
0
 public virtual object Clone()
 {
     return(GenericCloner.Clone <AbstractFigure> (this));
 }
Пример #8
0
 public virtual object Clone()
 {
     return(GenericCloner.Clone <AbstractConnector> (this));
 }
Пример #9
0
 public FigureCollection Clone()
 {
     return((FigureCollection)GenericCloner.Clone <FigureCollection> (this));
 }
Пример #10
0
 object System.ICloneable.Clone()
 {
     return(GenericCloner.Clone <FigureCollection> (this));
 }