Just another update

This commit is contained in:
Ingy döt Net 2015-02-20 00:35:01 -05:00
parent a25938f123
commit 00a190b0a6
6591 changed files with 94363 additions and 23227 deletions

View file

@ -1,6 +1,6 @@
import std.stdio, std.range, std.array, std.numeric, std.algorithm;
T[][] matMul(T)(in T[][] A, in T[][] B) /*pure*/ nothrow {
T[][] matMul(T)(in T[][] A, in T[][] B) pure nothrow /*@safe*/ {
const Bt = B[0].length.iota.map!(i=> B.transversal(i).array).array;
return A.map!(a => Bt.map!(b => a.dotProduct(b)).array).array;
}

View file

@ -5,9 +5,13 @@ alias TMMul_helper(M1, M2) = Unqual!(ForeachType!(ForeachType!M1))
void matrixMul(T, T2, size_t k, size_t m, size_t n)
(in ref T[m][k] A, in ref T[n][m] B,
/*out*/ ref T2[n][k] result) pure nothrow
/*out*/ ref T2[n][k] result) pure nothrow /*@safe*/ @nogc
if (is(T2 == Unqual!T)) {
T2[m] aux;
static if (hasIndirections!T)
T2[m] aux;
else
T2[m] aux = void;
foreach (immutable j; 0 .. n) {
foreach (immutable i, const ref bi; B)
aux[i] = bi[j];

View file

@ -0,0 +1,7 @@
program mm
real , allocatable :: a(:,:),b(:,:)
integer :: l=5,m=6,n=4
a = reshape([1:l*m],[l,m])
b = reshape([1:m*n],[m,n])
print'(<n>f15.7)',transpose(matmul(a,b))
end program

View file

@ -1,7 +1 @@
M1 = {{1, 2},
{3, 4},
{5, 6},
{7, 8}}
M2 = {{1, 2, 3},
{4, 5, 6}}
M = M1.M2
Dot[{{a, b}, {c, d}}, {{w, x}, {y, z}}]

View file

@ -1 +1 @@
{{1, 2}, {3, 4}, {5, 6}, {7, 8}}.{{1, 2, 3}, {4, 5, 6}}
{{a w + b y, a x + b z}, {c w + d y, c x + d z}}

View file

@ -1 +1 @@
{{9, 12, 15}, {19, 26, 33}, {29, 40, 51}, {39, 54, 69}}
{{a, b}, {c, d}} . {{w, x}, {y, z}}

View file

@ -1,7 +1 @@
matrixMul[m1_, m2_] := Table[Times @@ {a, b} // Tr, {a, m1}, {b, Transpose@m2}]
matrixMul2[m1_, m2_] :=Table[Sum[Times @@ i, {i, Transpose@{a, b}}], {a, m1}, {b, Transpose@m2}]
a = {{1, 2}, {3, 4}, {5, 6}, {7, 8}};
b = {{1, 2, 3}, {4, 5, 6}};
matrixMul[a, b]
matrixMul2[a, b]
Times[{{a, b}, {c, d}}, {{w, x}, {y, z}}]

View file

@ -0,0 +1 @@
{{a w, b x}, {c y, d z}}

View file

@ -0,0 +1 @@
{{a, b}, {c, d}}*{{w, x}, {y, z}}

View file

@ -0,0 +1 @@
{{a, b}, {c, d}} {{w, x}, {y, z}}

View file

@ -0,0 +1 @@
Dot[{{85, 60, 65}, {54, 99, 33}, {46, 52, 87}}, {{89, 77, 98}, {55, 27, 25}, {80, 68, 85}}]

View file

@ -0,0 +1 @@
{{16065, 12585, 15355}, {12891, 9075, 10572}, {13914, 10862, 13203}}

View file

@ -1,37 +1,39 @@
/*REXX program multiplies two matrixes together, shows matrixes & result*/
x.=
x.1 = '1 2'
x.2 = '3 4'
x.3 = "5 6" /*either kind of quote works. */
x.4 = '7 8'
do r=1 while x.r\=='' /*build the "A" matric from X. #s*/
do c=1 while x.r\==''; parse var x.r a.r.c x.r; end
end
Arows=r-1; Acols=c-1
y.=
y.1 = 1 2 3 /*if all values are positive, */
y.2 = 4 5 6 /*can eliminate the quotes. */
do r=1 while y.r\=='' /*build the "B" matric from Y. #s*/
do c=1 while y.r\==''; parse var y.r b.r.c y.r; end
end
Brows=r-1; Bcols=c-1
c.=0; L=0 /*L is max width of an element. */
do i =1 for Arows /*multiply matrix A & B ──<E29480> C */
do j =1 for Bcols
do k=1 for Acols
/*REXX program multiplies 2 matrixes together, shows matrixes and result*/
x. = /*the beginnings of the A matrix.*/
x.1 = 1 2 /*╔═════════════════════════════╗*/
x.2 = 3 4 /*║As none of the values haven't║*/
x.3 = 5 6 /*║a sign, quotes aren't needed.║*/
x.4 = 7 8 /*╚═════════════════════════════╝*/
do r=1 while x.r\=='' /*build the "A" matric from X. #s*/
do c=1 while x.r\==''; parse var x.r a.r.c x.r; end
end /*r*/
Arows=r-1 /*adjust number of rows (DO loop)*/
Acols=c-1 /* " " " cols " " */
y. = /*the beginnings of the B matrix.*/
y.1 = 1 2 3
y.2 = 4 5 6
do r=1 while y.r\=='' /*build the "B" matric from Y. #s*/
do c=1 while y.r\==''; parse var y.r b.r.c y.r; end
end
Brows=r-1 /*adjust number of rows (DO loop)*/
Bcols=c-1 /* " " " cols " " */
c.=0; L=0 /*L is max width of an element.*/
do i =1 for Arows /*multiply matrix A & B ──► C */
do j =1 for Bcols
do k=1 for Acols
c.i.j = c.i.j + a.i.k * b.k.j; L=max(L,length(c.i.j))
end /*k*/
end /*j*/
end /*i*/
end /*i*/
call showMat 'A', Arows, Acols
call showMat 'B', Brows, Bcols
call showMat 'C', Arows, Bcols
call showMatrix 'A', Arows, Acols /*display matrix A ───► terminal.*/
call showMatrix 'B', Brows, Bcols /* " " B ───► " */
call showMatrix 'C', Arows, Bcols /* " " C ───► " */
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────SHOWMAT subroutine──────────────────*/
showMat: parse arg mat,rows,cols; say
/*──────────────────────────────────SHOWMATRIX subroutine───────────────*/
showMatrix: parse arg mat,rows,cols; say
say center(mat 'matrix',cols*(L+1)+4,"")
do r =1 for rows; _=
do c=1 for cols; _=_ right(value(mat'.'r'.'c),L); end; say _
end
end /*r*/
return

View file

@ -0,0 +1 @@
[[1,2][3,4][5,6][7,8]]*[[1,2,3][4,5,6]]