Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -4,7 +4,7 @@ MODE VECTOR = [default upb]FIELD;
|
|||
MODE MATRIX = [default upb,default upb]FIELD;
|
||||
|
||||
# crude exception handling #
|
||||
PROC VOID raise index error := VOID: GOTO exception index error;
|
||||
PROC VOID raise index error := VOID: ( putf(stand error, $x"Exception: index error."l$); stop );
|
||||
|
||||
# define the vector/matrix operators #
|
||||
OP * = (VECTOR a,b)FIELD: ( # basically the dot product #
|
||||
|
|
@ -53,8 +53,4 @@ test:(
|
|||
# finally print the result #
|
||||
print(("Product of a and b: ",new line));
|
||||
real matrix printf(real fmt, prod)
|
||||
EXIT
|
||||
|
||||
exception index error:
|
||||
putf(stand error, $x"Exception: index error."l$)
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,31 +0,0 @@
|
|||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
with Ada.Numerics.Real_Arrays; use Ada.Numerics.Real_Arrays;
|
||||
|
||||
procedure Matrix_Product is
|
||||
|
||||
procedure Put (X : Real_Matrix) is
|
||||
type Fixed is delta 0.01 range -100.0..100.0;
|
||||
begin
|
||||
for I in X'Range (1) loop
|
||||
for J in X'Range (2) loop
|
||||
Put (Fixed'Image (Fixed (X (I, J))));
|
||||
end loop;
|
||||
New_Line;
|
||||
end loop;
|
||||
end Put;
|
||||
|
||||
A : constant Real_Matrix :=
|
||||
( ( 1.0, 1.0, 1.0, 1.0),
|
||||
( 2.0, 4.0, 8.0, 16.0),
|
||||
( 3.0, 9.0, 27.0, 81.0),
|
||||
( 4.0, 16.0, 64.0, 256.0)
|
||||
);
|
||||
B : constant Real_Matrix :=
|
||||
( ( 4.0, -3.0, 4.0/3.0, -1.0/4.0 ),
|
||||
(-13.0/3.0, 19.0/4.0, -7.0/3.0, 11.0/24.0),
|
||||
( 3.0/2.0, -2.0, 7.0/6.0, -1.0/4.0 ),
|
||||
( -1.0/6.0, 1.0/4.0, -1.0/6.0, 1.0/24.0)
|
||||
);
|
||||
begin
|
||||
Put (A * B);
|
||||
end Matrix_Product;
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
package Matrix_Ops is
|
||||
type Matrix is array (Natural range <>, Natural range <>) of Float;
|
||||
function "*" (Left, Right : Matrix) return Matrix;
|
||||
end Matrix_Ops;
|
||||
|
||||
package body Matrix_Ops is
|
||||
---------
|
||||
-- "*" --
|
||||
---------
|
||||
function "*" (Left, Right : Matrix) return Matrix is
|
||||
Temp : Matrix(Left'Range(1), Right'Range(2)) := (others =>(others => 0.0));
|
||||
begin
|
||||
if Left'Length(2) /= Right'Length(1) then
|
||||
raise Constraint_Error;
|
||||
end if;
|
||||
|
||||
for I in Left'range(1) loop
|
||||
for J in Right'range(2) loop
|
||||
for K in Left'range(2) loop
|
||||
Temp(I,J) := Temp(I,J) + Left(I, K)*Right(K, J);
|
||||
end loop;
|
||||
end loop;
|
||||
end loop;
|
||||
return Temp;
|
||||
end "*";
|
||||
end Matrix_Ops;
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
proc *(a:[], b:[]) {
|
||||
|
||||
if (a.eltType != b.eltType) then
|
||||
writeln("type mismatch: ", a.eltType, " ", b.eltType);
|
||||
|
||||
var ad = a.domain.dims();
|
||||
var bd = b.domain.dims();
|
||||
var (arows, acols) = ad;
|
||||
var (brows, bcols) = bd;
|
||||
if (arows != bcols) then
|
||||
writeln("dimension mismatch: ", ad, " ", bd);
|
||||
|
||||
var c:[{arows, bcols}] a.eltType = 0;
|
||||
|
||||
for i in arows do
|
||||
for j in bcols do
|
||||
for k in acols do
|
||||
c(i,j) += a(i,k) * b(k,j);
|
||||
|
||||
return c;
|
||||
}
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
var m1:[{1..2, 1..2}] int;
|
||||
m1(1,1) = 1; m1(1,2) = 2;
|
||||
m1(2,1) = 3; m1(2,2) = 4;
|
||||
writeln(m1);
|
||||
|
||||
var m2:[{1..2, 1..2}] int;
|
||||
m2(1,1) = 2; m2(1,2) = 3;
|
||||
m2(2,1) = 4; m2(2,2) = 5;
|
||||
writeln(m2);
|
||||
|
||||
var m3 = m1 * m2;
|
||||
writeln(m3);
|
||||
|
||||
var m4:[{1..2, 1..3}] int;
|
||||
m4(1, 1) = 1; m4(1, 2) = 2; m4(1, 3) = 3;
|
||||
m4(2, 1) = 4; m4(2, 2) = 5; m4(2, 3) = 6;
|
||||
writeln(m4);
|
||||
|
||||
var m5:[{1..3, 1..2}] int;
|
||||
m5(1, 1) = 6; m5(1, 2) = -1;
|
||||
m5(2, 1) = 3; m5(2, 2) = 2;
|
||||
m5(3, 1) = 0; m5(3, 2) = -3;
|
||||
writeln(m5);
|
||||
|
||||
writeln(m4 * m5);
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
(defvar M1 '((2 1 4)
|
||||
(0 1 1)))
|
||||
|
||||
(defvar M2 '(( 6 3 -1 0)
|
||||
( 1 1 0 4)
|
||||
(-2 5 0 2)))
|
||||
|
||||
(seq-map (lambda (a1)
|
||||
(seq-map (lambda (a2) (apply #'+ (seq-mapn #'* a1 a2)))
|
||||
(apply #'seq-mapn #'list M2)))
|
||||
M1)
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
function matrix_mul(sequence a, sequence b)
|
||||
sequence c
|
||||
if length(a[1]) != length(b) then
|
||||
return 0
|
||||
else
|
||||
c = repeat(repeat(0,length(b[1])),length(a))
|
||||
for i = 1 to length(a) do
|
||||
for j = 1 to length(b[1]) do
|
||||
for k = 1 to length(a[1]) do
|
||||
c[i][j] += a[i][k]*b[k][j]
|
||||
end for
|
||||
end for
|
||||
end for
|
||||
return c
|
||||
end if
|
||||
end function
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
(defun matrix* (matrix-1 matrix-2)
|
||||
(list-comp
|
||||
((<- a matrix-1))
|
||||
(list-comp
|
||||
((<- b (transpose matrix-2)))
|
||||
(lists:foldl #'+/2 0
|
||||
(lists:zipwith #'*/2 a b)))))
|
||||
(defun matrix*-map (m1 m2)
|
||||
(let ((m2T (transpose m2)))
|
||||
(lists:map
|
||||
(lambda (row)
|
||||
(lists:map (lambda (col) (dot-product row col))
|
||||
m2T))
|
||||
m1)))
|
||||
|
|
|
|||
|
|
@ -1,9 +1,7 @@
|
|||
> (set ma '((1 2)
|
||||
(3 4)
|
||||
(5 6)
|
||||
(7 8)))
|
||||
((1 2) (3 4) (5 6) (7 8))
|
||||
> (set mb (transpose ma))
|
||||
((1 3 5 7) (2 4 6 8))
|
||||
> (matrix* ma mb)
|
||||
((5 11 17 23) (11 25 39 53) (17 39 61 83) (23 53 83 113))
|
||||
(defun matrix*-lc (m1 m2)
|
||||
(let ((m2T (transpose m2)))
|
||||
(list-comp
|
||||
((<- row m1))
|
||||
(list-comp
|
||||
((<- col m2T))
|
||||
(dot-product row col)))))
|
||||
|
|
|
|||
|
|
@ -1,33 +0,0 @@
|
|||
function multarrays($a, $b) {
|
||||
$n,$m,$p = ($a.Count - 1), ($b.Count - 1), ($b[0].Count - 1)
|
||||
if ($a[0].Count -ne $b.Count) {throw "Multiplication impossible"}
|
||||
$c = @(0)*($a[0].Count)
|
||||
foreach ($i in 0..$n) {
|
||||
$c[$i] = foreach ($j in 0..$p) {
|
||||
$sum = 0
|
||||
foreach ($k in 0..$m){$sum += $a[$i][$k]*$b[$k][$j]}
|
||||
$sum
|
||||
}
|
||||
}
|
||||
$c
|
||||
}
|
||||
|
||||
function show($a) { $a | foreach{"$_"}}
|
||||
|
||||
$a = @(@(1,2),@(3,4))
|
||||
$b = @(@(5,6),@(7,8))
|
||||
$c = @(5,6)
|
||||
"`$a ="
|
||||
show $a
|
||||
""
|
||||
"`$b ="
|
||||
show $b
|
||||
""
|
||||
"`$c ="
|
||||
$c
|
||||
""
|
||||
"`$a * `$b ="
|
||||
show (multarrays $a $b)
|
||||
" "
|
||||
"`$a * `$c ="
|
||||
show (multarrays $a $c)
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
(define (matrix-multiply matrix1 matrix2)
|
||||
(map
|
||||
(lambda (row)
|
||||
(apply map
|
||||
(lambda column
|
||||
(apply + (map * row column)))
|
||||
matrix2))
|
||||
matrix1))
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
Dim matrix1(2,2)
|
||||
matrix1(0,0) = 3 : matrix1(0,1) = 7 : matrix1(0,2) = 4
|
||||
matrix1(1,0) = 5 : matrix1(1,1) = -2 : matrix1(1,2) = 9
|
||||
matrix1(2,0) = 8 : matrix1(2,1) = -6 : matrix1(2,2) = -5
|
||||
Dim matrix2(2,2)
|
||||
matrix2(0,0) = 9 : matrix2(0,1) = 2 : matrix2(0,2) = 1
|
||||
matrix2(1,0) = -7 : matrix2(1,1) = 3 : matrix2(1,2) = -10
|
||||
matrix2(2,0) = 4 : matrix2(2,1) = 5 : matrix2(2,2) = -6
|
||||
|
||||
function getMatrixProduct(firstMatrix,secondMatrix)
|
||||
if ubound(firstMatrix,2) <> ubound(secondMatrix,1) then exit function
|
||||
redim resultMatrix(ubound(firstMatrix,1),ubound(secondMatrix,2))
|
||||
for i = 0 to ubound(firstMatrix,1) : for j = 0 to ubound(secondMatrix,2) : for k = 0 to ubound(firstMatrix,2)
|
||||
resultMatrix(i,j) = resultMatrix(i,j) + (firstMatrix(i,k) * secondMatrix(k,j))
|
||||
next : next : next
|
||||
getMatrixProduct = resultMatrix
|
||||
End function
|
||||
|
||||
dim resultMatrix : resultMatrix = getMatrixProduct(matrix1,matrix2)
|
||||
dim outputString
|
||||
for a = 0 to ubound(resultMatrix,1)
|
||||
for b = 0 to ubound(resultMatrix,2)
|
||||
outputString = outputString & resultMatrix(a,b) & vbTab
|
||||
next
|
||||
outputString = outputString & vbCrlf
|
||||
next
|
||||
msgbox outputString
|
||||
Loading…
Add table
Add a link
Reference in a new issue