-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuMemoryMatrices.pas
More file actions
142 lines (125 loc) · 4.09 KB
/
uMemoryMatrices.pas
File metadata and controls
142 lines (125 loc) · 4.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
unit uMemoryMatrices;
interface
uses
Classes, uBaseLibrary;
function InstantiateMatrix(const NumRows, NumCols: integer; Initialize:boolean=false; Value: float=0): integer;
procedure FreeMatrix(const MatrixHandle: integer);
procedure ReadMatrixInfo(const MatrixHandle: integer; var NumRows, NumCols: integer);
function ReadMatrix(const MatrixHandle: integer): TArrayVariantArray;
procedure WriteMatrix(const MatrixHandle: integer; Data: TArrayVariantArray);
procedure RandomizeMatrix(const MatrixHandle: integer; Bias: float=0.5);
function MulMatrices(const MatrixHandleA, MatrixHandleB: integer): integer;
function TransposeMatrix(const MatrixHandle: integer): integer;
function AddMatrices(const MatrixHandleA, MatrixHandleB: integer): integer;
function SubMatrices(const MatrixHandleA, MatrixHandleB: integer): integer;
function HadamardMatrices(const MatrixHandleA, MatrixHandleB: integer): integer;
function ScaleMatrix(const MatrixHandle: integer; S: float): integer;
implementation
const
LibGUID='{2970D979-84FB-4B42-B730-F596BEC20E2F}';
function InstantiateMatrix(const NumRows, NumCols: integer; Initialize:boolean; Value: float):integer;
var
Args: TVariantArray;
begin
Args.Push(NumRows);
Args.Push(NumCols);
Args.Push(Initialize);
Args.Push(Value);
Result:=__LibInterface_InvokeLibProc(LibGUID,0,'InstantiateMatrix',Args);
end;
procedure FreeMatrix(const MatrixHandle: integer);
var
Args: TVariantArray;
begin
Args.Push(MatrixHandle);
__LibInterface_InvokeLibProc(LibGUID,0,'FreeMatrix',Args);
end;
procedure ReadMatrixInfo(const MatrixHandle: integer; var NumRows, NumCols: integer);
var
Args: TVariantArray;
begin
Args.Push(MatrixHandle);
Args.Push(0);
Args.Push(0);
__LibInterface_InvokeLibProc(LibGUID, 0, 'ReadMatrixInfo', Args);
NumRows:=Args[1];
NumCols:=Args[2];
end;
function ReadMatrix(const MatrixHandle: integer): TArrayVariantArray;
var Value: TVariantArray;
k, RowsNum, ColsNum: integer;
Args: TVariantArray;
begin
Args.Push(MatrixHandle);
Args.Push(0);
Args.Push(0);
Value:=__VariantToArray(__LibInterface_InvokeLibProc(LibGUID, 0, 'ReadMatrix', Args)).Map(VarToFloat);
RowsNum:=Args[1];
ColsNum:=Args[2];
for k:=0 to RowsNum-1 do
Result.Push(Value.Copy(k*ColsNum,ColsNum));
end;
procedure WriteMatrix(const MatrixHandle: integer; Data: TArrayVariantArray);
var
Args: TVariantArray;
begin
Args.Push(MatrixHandle);
Args.Push(__ArrayToVariant(__ArrayVariantArrayToVariantArray(Data)));
__LibInterface_InvokeLibProc(LibGUID, 0, 'WriteMatrix' , Args);
end;
procedure RandomizeMatrix(const MatrixHandle: integer; Bias: float=0.5);
var
Args: TVariantArray;
begin
Args.Push(MatrixHandle);
Args.Push(Bias);
__LibInterface_InvokeLibProc(LibGUID, 0, 'RandomizeMatrix', Args);
end;
function MulMatrices(const MatrixHandleA, MatrixHandleB: integer): integer;
var
Args: TVariantArray;
begin
Args.Push(MatrixHandleA);
Args.Push(MatrixHandleB);
Result:=__LibInterface_InvokeLibProc(LibGUID,0,'MulMatrices',Args);
end;
function TransposeMatrix(const MatrixHandle: integer): integer;
var
Args: TVariantArray;
begin
Args.Push(MatrixHandle);
Result:=__LibInterface_InvokeLibProc(LibGUID,0,'TransposeMatrix',Args);
end;
function AddMatrices(const MatrixHandleA, MatrixHandleB: integer): integer;
var
Args: TVariantArray;
begin
Args.Push(MatrixHandleA);
Args.Push(MatrixHandleB);
Result:=__LibInterface_InvokeLibProc(LibGUID,0,'AddMatrices',Args);
end;
function SubMatrices(const MatrixHandleA, MatrixHandleB: integer): integer;
var
Args: TVariantArray;
begin
Args.Push(MatrixHandleA);
Args.Push(MatrixHandleB);
Result:=__LibInterface_InvokeLibProc(LibGUID,0,'SubMatrices',Args);
end;
function HadamardMatrices(const MatrixHandleA, MatrixHandleB: integer): integer;
var
Args: TVariantArray;
begin
Args.Push(MatrixHandleA);
Args.Push(MatrixHandleB);
Result:=__LibInterface_InvokeLibProc(LibGUID,0,'HadamardMatrices',Args);
end;
function ScaleMatrix(const MatrixHandle: integer; S: float): integer;
var
Args: TVariantArray;
begin
Args.Push(MatrixHandle);
Args.Push(S);
Result:=__LibInterface_InvokeLibProc(LibGUID,0,'ScaleMatrix',Args);
end;
end.