X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=dev4%2Fpsychlops%2Fcore%2Fmath%2Fmatrix.cs;fp=dev4%2Fpsychlops%2Fcore%2Fmath%2Fmatrix.cs;h=9bd895ff53a059649bbec85be393cfc0a8991ee6;hb=cb8916a7a5cd929f57b3f9edd99209680db90546;hp=0000000000000000000000000000000000000000;hpb=e05ab8e68d381f8f5c9a2ddb7c63b89a7bb6371a;p=psychlops%2Fsilverlight.git diff --git a/dev4/psychlops/core/math/matrix.cs b/dev4/psychlops/core/math/matrix.cs new file mode 100644 index 0000000..9bd895f --- /dev/null +++ b/dev4/psychlops/core/math/matrix.cs @@ -0,0 +1,81 @@ +using System; + +namespace Psychlops +{ + + + public abstract class Matrix + { + public abstract double this[int row, int col] + { + get; + set; + } + + /* + public static Matrix operator +(Matrix m, double d) + { + return new Internal.MatrixExpression(); + } + */ + } + + + namespace Internal + { + + public class MatrixImplementation : Matrix + { + internal double[] elements; + readonly int nrow, ncol; + + public MatrixImplementation(int dnrow, int dncol) + { + nrow = dnrow; + ncol = dncol; + elements = new double[nrow * ncol]; + } + + public override double this[int row, int col] + { + get + { + return elements[(row - 1) * ncol + (col - 1)]; + } + set + { + elements[(row - 1) * ncol + (col - 1)] = value; + } + } + } + + public class MatrixExpression : Matrix + { + MatrixImplementation imp; + readonly int nrow, ncol; + readonly int drow, dcol; + + public MatrixExpression(MatrixImplementation target, int ddrow, int ddcol, int dnrow, int dncol) + { + nrow = dnrow; + ncol = dncol; + drow = ddrow; + dcol = ddcol; + imp = target; + } + + public override double this[int row, int col] + { + get + { + return imp.elements[(row - drow) * ncol + (col - dcol)]; + } + set + { + imp.elements[(row - drow) * ncol + (col - dcol)] = value; + } + } + } + } + +} \ No newline at end of file