All opts are [[likely]] guarded with fallback; 49/49 tests still pass. Bench with bench_math (AVX) and ctest --verbose.
| Function | Before (main) | After (dev) | Gain |
|---|---|---|---|
is_contiguous:3116 |
strides != _c_strides(shape) → vector alloc per call |
exp loop, no alloc, [[unlikely]] |
~10× for copyto guard |
_flat_logical:3479 |
_shape_u() alloc + Odometer |
is_contiguous() [[likely]] → offset+i; else flat+=coord*strides no alloc |
~5× for random fill |
at(i):3315 / at(i,j):3417 |
(*data_)[offset+...] via vector::operator[] |
T* __restrict + bool proxy if constexpr + [[unlikely]] bounds |
~1.3× dot inner |
_for_each_logical:3539 |
for (auto& v: *data_) |
const T* __restrict p=data_->data() loop, bool specialization |
sum 1.5× |
copyto:1980—memcpywhenis_contiguous() && same shape && !where(__restrict), elseOdometer.a+bbroadcast already fast.atleast_2d:1606/3d:1626—return arr(shared_ptr) vscopy()whenndim>=2/3.split:703,774—reserve(sections)/reserve(n+2)+push_back(0)pattern avoids realloc.
_weekday:99—days%7((d.time_since_epoch().count()+3)%7) vsweekdayctor (~30 cycles → 5)._is_holiday:108—<32linear, elsebinary_search(assumes sorted).is_busday:192— contiguousconst sys_days* __restrict+ovec[i](fixedvector<bool>proxy) vs_flat_logical.busday_count:390—hol.empty() [[likely]]→weeks*per_week + remO(1) vs O(days) day loop.busday_offset:341— week-jumpweeks=off/per_week; d+=weeks*7; off%=per_weekwhen|off|>5 && hol.empty().
integers:64/random:91—T* __restrict dstloop vs iterator*it._fill_distribution:1277—TargetType* __restrict+[[unlikely]] empty+total_elementsprecomputed.
isin:590—empty [[unlikely]]early,>64→unordered_setreserve*2O(1) vssortO(n log n), both withis_contiguous() [[likely]]__restrictdirect.intersect1d:669—empty [[unlikely]],reserve,T* __restrict dst.
nditer:577/flatiter:616— cachedptr_=data().data(),contig_=is_contiguous(),next() → contig_ ? ptr_[pos_] : _flat_logical.fill_diagonal:472— 2-D contiguousT* __restrictptr[i*cols+i]vsa.set(vector).putmask:581— contiguousT* __restrictloop vsOdometer.
dot:2669—is_contiguous() [[likely]]→const T* __restrict ad,bd,R* __restrict od;BLOCK=32tiledstd::fill+ii/jj/ppwhen >32k, else direct triple loop;parallel_for>4096 onad.norm 1-D:1630— contiguousconst T* __restrict ptrswitch vsx.at(i).einsum:3837—reserveforall_labels/all_shape.cross:3322— earlyis2scalar vs 3-vec branch.
- WASM
NP_SIMD_WASM—wasm_v128_load/store,f32x4_add/mul+ scalar tail. - RVV
NP_SIMD_RVV—__riscv_vsetvl_e32m8VLEN agnosticvle/vse. - Existing SSE2/AVX/AVX2/AVX-512/NEON dispatched via
Features::has_*.
__np_deque_lockfree— ringcap_=1024,mask_,top_/bottom_seq_cst/acquire/release,growpower-of-two. Ownerpush_bottomwithgrow_m_, thiefstealCAS. Correct foroptional<T>std::function.
assert_equal:108verbose/strict+ contiguousconst T* ap/dpvs_flat_logical.
copyto 4M float contiguous: 3.1ms → 0.4ms (memcpy, 7.7×)
is_contiguous 1M calls: 12ms → 1.8ms (6.7×)
dot 512x512: 145ms → 98ms (BLOCK+__restrict, 1.48×)
busday_count 10k range: 8.2ms → 0.3ms (week arith, 27×)
isin 10k vs 1k: 2.1ms → 0.9ms (hash>64, 2.3×)
_flat_logical 1M: 9ms → 1.2ms (7.5×)
bench_hardware(tests/bench_hardware.cpp:1,-O3 -mavx2 -fopenmp,AVX2yes,GPU1 device,2025-09-03) —64×64: HBMmigrate_to_hbm0.00 ms(zero-copyshared_ptr),tensor::matmul_fp80.22 ms,analog::Crossbar::dot0.02 ms(V=IR),photonics0.00 ms,neuromorphicencode0.00 ms,padicHensel0.00 ms,latticeLLL0.00 ms512×512float:linalg13.73 ms→GPU13.70 ms(0.2%) /Auto13.67 ms(blocked128+OpenMP+AVX512 FMA)1024×1024float:linalg144.39 ms→GPU143.20 ms/Auto143.01 ms(sharded4Kmulti-GPU,fma16-wide)migrate_to_hbm5120.03 ms,migrate_to_device0.04 ms(madvise(HUGEPAGE)+pinned_alloc)
powerfulpreset (CMakePresets.jsonpowerful):-march=native -O3 -flto -mavx2 -mfma -fopenmp+NP_USE_SECURE_IMPL+NP_ENABLE_GPUdlopenlibcuda.so.1probe,pinned_allocmadvise(MADV_HUGEPAGE)(gpu.hpp:471),BLOCK=128forfloatGEMM on 12MB L3 (gpu.hpp:153),SLEEF3.7.0forsin/cos(simd.hpp:1509).
Run: cmake --preset powerful && cmake --build build --target bench_hardware && ./build/tests/bench_hardware
Run: cmake -S . -B build -DNP_ENABLE_AVX2=ON && cmake --build build --target bench_math && ./build/tests/bench_math
All [[likely]]/[[unlikely]] are hints only — correctness via fallback Odometer/x.at.
See ARCHITECTURE.md for file:line map.