Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
3 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
 
'use strict';
 
// Model data for "test_abs/model.onnx"
const testModelData =
  'CAcSDGJhY2tlbmQtdGVzdDpJCgsKAXgSAXkiA0FicxIIdGVzdF9hYnNaFwoBeBISChAIARIMCgIIAwoCCAQKAggFYhcKAXkSEgoQCAESDAoCCAMKAggECgIIBUIECgAQDQ==';
 
const base64StringToUint8Array = (base64String) => {
  const charArray = atob(base64String);
  const length = charArray.length;
  const buffer = new Uint8Array(new ArrayBuffer(length));
  for (let i = 0; i < length; i++) {
    buffer[i] = charArray.charCodeAt(i);
  }
  return buffer;
};
 
const assert = (cond) => {
  if (!cond) throw new Error();
};
 
const setupMultipleThreads = (ort) => {
  ort.env.wasm.numThreads = 2;
  assert(typeof SharedArrayBuffer !== 'undefined');
};
 
const testInferenceAndValidate = async (ort, options) => {
  const model = base64StringToUint8Array(testModelData);
  const session = await ort.InferenceSession.create(model, options);
 
  // test data: [0, -1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11, ... 58, -59]
  const inputData = [...Array(60).keys()].map((i) => (i % 2 === 0 ? i : -i));
  const expectedOutputData = inputData.map((i) => Math.abs(i));
 
  const fetches = await session.run({ x: new ort.Tensor('float32', inputData, [3, 4, 5]) });
 
  const y = fetches.y;
 
  assert(y instanceof ort.Tensor);
  assert(y.dims.length === 3 && y.dims[0] === 3 && y.dims[1] === 4 && y.dims[2] === 5);
 
  for (let i = 0; i < expectedOutputData.length; i++) {
    assert(y.data[i] === expectedOutputData[i]);
  }
};
 
export default testInferenceAndValidate;
export { setupMultipleThreads };