Skip to content

Commit 870fd97

Browse files
authored
Merge pull request #602 from SciSharp/npalign
[Random, Alignment] Refactor np.random.* to match NumPy parity
2 parents 736d17d + 29f3353 commit 870fd97

151 files changed

Lines changed: 21165 additions & 1698 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
name: np-function
3+
description: Implement numpy np.* functions in NumSharp with full API parity. Use when adding new numpy functions, implementing np.* methods, or aligning NumSharp behavior with numpy 2.4.2.
4+
---
5+
6+
We are looking to support numpy's np.* to the fullest. we are aligning with numpy 2.4.2 as source of truth and are to provide exact same API (np.* overloading) as numpy does.
7+
This session we focusing on: """$ARGUMENTS"""
8+
You job is around interacting with np.* functions (no more than a few. more than one ONLY if they are closely related).
9+
10+
To interact/develop/create a np.* / function, high-level development cycle is as follows:
11+
1. Read how numpy (K:\source\NumSharp\src\numpy) exposes the np function/s you are about to implement. Remember, numpy is the source of truth and if numpy does A, we do A but in NumSharp's C# way.
12+
Definition of Done:
13+
- At the end of this step you understand to 100% how the np function both works, behaves and accepts.
14+
If numpy function uses other np.* functions then you are to report them to the team leader and wait for further instructions. If the function is relative to you then take ownership over it and add it to your group of functions.
15+
2. Implement np methods in the appropriate np class and if custom calculation/math is required via backend then follow the Tensor and IL Kernel way. You are not allowed to implement a hardcoded loop per dtype. Usually other np.* calls is all a numpy function requires. Always reuse existing architecture rather than create a new one.
16+
Definition of Done:
17+
- What Numpy supports, we support.
18+
- We support all dtypes (no hardcoded loops, use il generation via our backend if necessary).
19+
- We have all the apis the np function has and all the overloads.
20+
- We calculate exactly like numpy because only that way we can capture all the design edge cases and implicit behaviors.
21+
3. Then migrate the tests that numpy has from numpy to C# and then produce your own set of tests covering all aspects of the api that you will battletest. Any bugs should be fixed on the spot.
22+
Definition of Done:
23+
- All numpy tests have been migrated to NumSharp C#.
24+
- We used battletesting to find edge cases and other bugs in our implementation where numpy works. Our source of truth for behavior is numpy!
25+
4. Review the implementation, definitions of done and confirm alignment to numpy is as close as possible. Ensure documentation in code.
26+
5. Commit and report completion.
27+
28+
## Tools:
29+
### Battletesting
30+
Use battletesting to test and validate assumptions or even hunt edge cases: which is using 'dotnet run << 'EOF'' and 'python << 'EOF'' to run any code for any of these purposes.
31+
32+
## Instructions to Team Leader
33+
- Create at-least 4 users if the task can be parallelised to that level and if not then use less
34+
- Do not wait for other teammates to complete, always have N teammates developing until all the work is completed by definition of done.
35+
- If user asked for 1 of something there there is only a reason to launch one teammate and not five.
36+
- When the teammate have completed development all the way to last step and all definition of done: finish and shutdown the teammate.
37+
- You are to give the instructions to the teammates word-for-word based on this document with your own adaptation below the original version.

.claude/skills/np-tests/SKILL.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
name: np-tests
3+
description: Write and migrate numpy tests for NumSharp functions. Use when adding tests for np.* methods, migrating numpy test suites, or battletesting NumSharp implementations against numpy 2.4.2.
4+
---
5+
6+
We are looking to test numpy's np.* implementations to the fullest. we are aligning with numpy 2.4.2 as source of truth and are to validate exact same behavior as numpy does.
7+
This session we focusing on: """$ARGUMENTS"""
8+
Your job is around writing tests for np.* functions (no more than a few. more than one ONLY if they are closely related).
9+
10+
To interact/develop/create tests for np.* functions, high-level development cycle is as follows:
11+
1. Find and read numpy's tests for the function/s you are about to test. Tests are in K:\source\NumSharp\src\numpy under numpy/_core/tests/, numpy/lib/tests/, etc. Remember, numpy is the source of truth.
12+
Definition of Done:
13+
- At the end of this step you understand 100% what numpy tests: inputs, outputs, edge cases, error conditions, dtype behaviors.
14+
- You have identified all test files and test methods related to your function.
15+
2. Migrate numpy's tests to C# following TUnit framework patterns in test/NumSharp.UnitTest. Match numpy's test structure and assertions exactly.
16+
Definition of Done:
17+
- Every numpy test case has a corresponding C# test.
18+
- We cover all dtypes NumSharp supports (Boolean, Byte, Int16, UInt16, Int32, UInt32, Int64, UInt64, Char, Single, Double, Decimal).
19+
- Test names reflect what they test (e.g., Test_Sort_Axis0_Int32).
20+
- Assertions match numpy's expected values exactly.
21+
3. Battletest to find gaps. Run python and dotnet side-by-side to discover edge cases numpy handles that we might miss.
22+
Definition of Done:
23+
- All numpy tests pass in NumSharp.
24+
- Additional edge cases discovered via battletesting are covered.
25+
- Any bugs found are reported to implementation teammate or fixed on the spot.
26+
4. Review test coverage: empty arrays, scalar inputs, negative axis, broadcasting, NaN/Inf handling, dtype promotion, error conditions.
27+
5. Commit and report completion.
28+
29+
## Tools:
30+
### Battletesting
31+
Use battletesting to validate behavior matches numpy: 'dotnet run << 'EOF'' and 'python << 'EOF'' side-by-side comparison.
32+
33+
### Test Patterns
34+
```csharp
35+
[Test]
36+
public async Task FunctionName_Scenario_Dtype()
37+
{
38+
// Arrange
39+
var input = np.array(new[] { 3, 1, 2 });
40+
41+
// Act
42+
var result = np.sort(input);
43+
44+
// Assert - values from running actual numpy
45+
Assert.That(result.IsContiguous, Is.True);
46+
Assert.That(result.GetAtIndex<int>(0), Is.EqualTo(1));
47+
}
48+
```
49+
50+
## Instructions to Team Leader
51+
- Create at-least 4 users if the task can be parallelised to that level and if not then use less
52+
- Do not wait for other teammates to complete, always have N teammates developing until all the work is completed by definition of done.
53+
- If user asked for 1 of something there there is only a reason to launch one teammate and not five.
54+
- When the teammate have completed development all the way to last step and all definition of done: finish and shutdown the teammate.

0 commit comments

Comments
 (0)