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)); }
private static ICloner <T> GetGenericCloner(Type type) { if (type.IsImplementationOf(typeof(ICloneable <T>))) { return(GenericCloner.GetInstance()); } return(null); }
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); }
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); }
public virtual object Clone() { return(GenericCloner.Clone <LineTerminal> (this)); }
private static Vector DeepCopy(Vector other) { var gc = new GenericCloner <Vector>(); return(gc.Clone(other)); }
public virtual object Clone() { return(GenericCloner.Clone <AbstractFigure> (this)); }
public virtual object Clone() { return(GenericCloner.Clone <AbstractConnector> (this)); }
public FigureCollection Clone() { return((FigureCollection)GenericCloner.Clone <FigureCollection> (this)); }
object System.ICloneable.Clone() { return(GenericCloner.Clone <FigureCollection> (this)); }