ml: 全流程代码与运行手册(数据打包/可微运动学与对拍/MeanFlow+WTA 模型/训练/闭环仿真/APG/挖错循环/ONNX 导出);webapp 策略运行时 ik-policy.js + ?policy=1 接入;tests/policy_bench.cjs;ik-solver 增 pairList/clusterExport/criticalPairs/pairGap/leverTable
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
/* 最小 .npy 写出(float32 / int32,C 序) */
|
||||
'use strict';
|
||||
const fs = require('fs');
|
||||
function writeNpy(file, arr, shape, dtype) {
|
||||
const descr = dtype === 'int32' ? '<i4' : '<f4';
|
||||
let hdr = `{'descr': '${descr}', 'fortran_order': False, 'shape': (${shape.join(', ')}${shape.length === 1 ? ',' : ''}), }`;
|
||||
const pre = 10, total = Math.ceil((pre + hdr.length + 1) / 64) * 64;
|
||||
hdr = hdr + ' '.repeat(total - pre - hdr.length - 1) + '\n';
|
||||
const h = Buffer.alloc(pre); h.write('\x93NUMPY', 0, 'latin1'); h[6] = 1; h[7] = 0; h.writeUInt16LE(hdr.length, 8);
|
||||
const ta = dtype === 'int32' ? Int32Array.from(arr) : (arr instanceof Float32Array ? arr : Float32Array.from(arr));
|
||||
fs.writeFileSync(file, Buffer.concat([h, Buffer.from(hdr, 'latin1'), Buffer.from(ta.buffer, ta.byteOffset, ta.byteLength)]));
|
||||
}
|
||||
module.exports = { writeNpy };
|
||||
Reference in New Issue
Block a user