ArtificialRay
local snapshot before syncing with HF
7502e01
Raw
History Blame Contribute Delete
1.4 kB
{
"name": "loop_113",
"op_type": "loop_113",
"description": "Sum adjacent uint32 pairs across an array (horizontal pairwise add)",
"tags": [
"simd-loop"
],
"axes": {
"N": {
"type": "var",
"description": "Array length"
}
},
"inputs": {
"a0": {
"shape": [
"N"
],
"dtype": "int32"
},
"b0": {
"shape": [
"N"
],
"dtype": "int32"
}
},
"outputs": {
"c0": {
"shape": [
"N"
],
"dtype": "uint32",
"description": "Output array"
}
},
"reference": "import numpy as np\n\ndef run(a0, b0):\n n = len(a0)\n ap = np.concatenate([a0.astype(np.int32), np.zeros(2, np.int32)])\n bp = np.concatenate([b0.astype(np.int32), np.zeros(2, np.int32)])\n n_pairs = (n + 1) // 2\n even = np.arange(n_pairs) * 2\n c = np.zeros(n, dtype=np.int32)\n # c[2k] = a[2k]+a[2k+1]\n c_ev = (ap[even].astype(np.int64) + ap[even + 1].astype(np.int64)).astype(np.int32)\n valid_ev = even[even < n]\n c[valid_ev] = c_ev[:len(valid_ev)]\n # c[2k+1] = b[2k]+b[2k+1]\n c_od = (bp[even].astype(np.int64) + bp[even + 1].astype(np.int64)).astype(np.int32)\n odd = even + 1\n valid_od = odd[odd < n]\n c[valid_od] = c_od[:len(valid_od)]\n return c\n",
"simd_loop_meta": {
"output_inplace": false,
"array_pad": 2,
"scratch": []
}
}