File size: 1,051 Bytes
a0f8a7d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
% SPDX-License-Identifier: Apache-2.0
% Fixed, data-only GNU Octave adapter. No eval/source/pkg/system/network calls.

args = argv();
if numel(args) != 2
  error("a11oy:numerics:arguments", "expected fixed input and output paths");
endif

input_path = args{1};
output_path = args{2};
request = jsondecode(fileread(input_path));
operation = request.operation;
matrix = request.inputs.matrix;

if strcmp(operation, "MATRIX_SOLVE") || strcmp(operation, "VALIDATE_REFERENCE_VECTOR")
  values = matrix \ request.inputs.rhs(:);
elseif strcmp(operation, "SYMMETRIC_EIGENVALUES")
  values = sort(eig(matrix));
else
  error("a11oy:numerics:operation", "unsupported fixed operation");
endif

response = struct(
  "schema", "szl.numerics.engine-response/v1",
  "state", "RESULT",
  "operation", operation,
  "values", reshape(values, 1, []),
  "substrate_evidence", "UNKNOWN"
);

handle = fopen(output_path, "w");
if handle < 0
  error("a11oy:numerics:output", "cannot open fixed output path");
endif
fprintf(handle, "%s", jsonencode(response));
fclose(handle);