-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest_saxpy.js
26 lines (18 loc) · 832 Bytes
/
test_saxpy.js
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
// Assume add.wasm file exists that contains a single function adding 2 provided arguments
const fs = require('fs');
const wasmBuffer = fs.readFileSync('test_saxpy.wasm');
WebAssembly.instantiate(wasmBuffer).then(wasmModule => {
// Exported function live under instance.exports
const { julia_sum_matrix, memory } = wasmModule.instance.exports;
// Create an array that can be passed to the WebAssembly instance.
const array = new Int32Array(memory.buffer, 0, 4)
// data starts after 4 Int32
offset = 4*4
array.set([offset, 6, 2, 3])
const arrayf = new Float32Array(memory.buffer, offset, 6)
arrayf.set([2, 3, 4, 5, 6, 7.01])
// Call the function and display the results.
const result = julia_sum_matrix(array.byteOffset)
console.log(result);
console.log(arrayf);
});