Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import std.getopt;
- import std.stdio;
- import std.experimental.ndslice;
- int n = 1000, l=1000, m=1000;
- void main(string[] args)
- {
- auto A = new double [l*m].sliced(l,m);
- auto B = new double [m*n].sliced(m,n);
- auto C = new double [l*n].sliced(l,n);
- A[][] = 0;
- matrix!(typeof(A)).ini(A);
- matrix!(typeof(A)).ini(B);
- matrix!(typeof(A)).MatMul(A,B,C);
- writeln(C[1,1]);
- writefln("%d %d ", C.length, C[0].length);
- }
- template matrix(T){
- void ini(T mtx){
- for(int i = 0; i <mtx.length; i++) {
- for(int j = 0; j< mtx[i].length; j++) {
- mtx[i,j] = i*j + 0.6*j +3.4;
- }
- }
- }
- void print(T mtx){
- for(int i = 0; i <mtx.length; i++) {
- writefln("%(%8.1f %)", mtx[i]);
- }
- }
- void MatMul(T A, T B, T C){
- C[] = 0;
- for(int k = 0; k < C[0].length; k++) {
- for(int i = 0; i < C.length; i++) {
- for(int j = 0; j < A[0].length; j++) {
- C[i,k] += A[i,j] * B[j,k];
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement