コード例 #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
ファイル: LineTerminal.cs プロジェクト: thbin/TraceLab
 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
ファイル: AbstractFigure.cs プロジェクト: thbin/TraceLab
 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));
 }