Sooo, ich bin auf dem Wege, stoße aber gerade an.
Ich hab den Combiner um die Multiplikation erweitert:
Code:
public class Combiner<T>
{
public Func<T, T, T> Add {
get;
private set;
}
public Func<T, T, T> Mul {
get;
private set;
}
public Combiner(Func<T, T, T> _add, Func<T, T, T> _mul)
{
Add = _add;
Mul = _mul;
}
}
Dann in der Matrix<T> Klasse folgenden Operator hinzugefügt:
Code:
public static Matrix<T> operator *(Matrix<T> left, Matrix<T> right)
{
if (left.dimX != right.dimY) throw new ArrayTypeMismatchException("Operation * on mismatching matrices");
else{
Matrix<T> result = new Matrix<T>(right.ops, right.dimX, left.dimY);
result.values = new T[right.dimX*left.dimY];
for (int x = 0; x < result.dimX; x++) {
for (int y = 0; y < result.dimX; y++) {
for (int k=0; k<left.dimX; k++) {
result[x, y] = left.ops.Add(result[x, y], left.ops.Mul(left[k, y], right[x, k]));
}
}
}
return result;
}
}
Ich erzeuge 2 MatrixFactories:
Code:
MatrixFactory<double> mfd = new MatrixFactory<double>(new Combiner<double>((a, b) => a + b, (a, b) => a * b));
MatrixFactory<Matrix<double>> mfm = new MatrixFactory<Matrix<double>>(new Combiner<Matrix<double>>((a, b) => a + b, (a, b) => a * b));
Und dann 2 Matrizen daraus:
Code:
C = mfd.New(4, 4);
Q = mfm.New(4, 4);
for (int x=0; x<4; x++)
for (int y=0; y<4; y++)
Q[x, y] = mfd.New(2, 1);
Dann versuche ich sie zu multiplizieren:
Code:
Matrix<Matrix<double>> tmp;
tmp = Q*C;
Und der Compiler quittiert mit:
"Operator '*' cannot be applied to operands of type 'Matrix<double>' and 'Matrix<Matrix<double>>' (CS0019)
Was hab ich falsch gemacht?
"When one person suffers from a delusion, it is called insanity. When a million people suffer from a delusion, it is called religion." (Richard Dawkins)