Skip to content

Commit eb909cc

Browse files
committed
refactor(hpc/activations): convert 3 pub fns to ArrayView-first (W2-2b)
In-place rename. sigmoid_f32 becomes generic-D ArrayView; softmax_f32 and log_softmax_f32 become ArrayView1 (1-D only — softmax_axis variant deferred to a follow-up). Hot-path as_slice_memory_order dispatch preserved; cold-path Zip / scalar fallback added. Tests: contiguous + strided + shape-mismatch coverage per fn (16 tests, up from 9). Updated burn caller in crates/burn/src/ops/activation.rs to wrap its &[f32]/&mut [f32] via ArrayView::from / ArrayViewMut::from at the call site (zero-copy borrow).
1 parent 7e7a512 commit eb909cc

2 files changed

Lines changed: 290 additions & 46 deletions

File tree

crates/burn/src/ops/activation.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ where
2727
if view.is_standard_layout() {
2828
if let Some(input) = view.as_slice() {
2929
let mut output = alloc::vec![0.0f32; input.len()];
30-
ndarray::hpc::activations::sigmoid_f32(input, &mut output);
30+
let in_view = ndarray::ArrayView::from(input);
31+
let out_view = ndarray::ArrayViewMut::from(&mut output[..]);
32+
ndarray::hpc::activations::sigmoid_f32(in_view, out_view);
3133
let shape: alloc::vec::Vec<usize> = view.shape().to_vec();
3234
let array = ndarray::Array::from_shape_vec(ndarray::IxDyn(&shape), output)
3335
.expect("sigmoid output shape mismatch");

0 commit comments

Comments
 (0)