SciSharp / SciSharp/NumSharp

[Performance] ClipNDArray with @out does redundant copy

Open
#595 0 comments 0 reactions 1 assignee View on GitHub

@Nucs is already working on this.

Since Mar 23, 2026.

api performance
Dominant language
C#
Stars
1.5k
Forks
205
Avg merge
7d 7h
Merged PRs (30d)
2

Description

Problem

np.maximum/minimum/clip with @out parameter does two passes:

  1. np.copyto(@out, lhs) - copy input to output
  2. ClipArrayMin(@out, min) - clip in-place

Root Cause

ClipArrayMin<T>(T* output, T* minArr, int size) operates in-place. No separate src parameter.

Fix

Add 3-operand kernel variants:

ClipArrayMinFromSource<T>(T* dest, T* src, T* minArr, int size)
// dest[i] = max(src[i], minArr[i]) - single pass

Same for ClipArrayMax and ClipArrayBounds.

Impact

Affects np.maximum, np.minimum, np.fmax, np.clip when @out is provided.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.