Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
107 commits
Select commit Hold shift + click to select a range
b3b19ca
fix: extend keepdims fix to all reduction operations
Nucs Feb 14, 2026
ac68e4f
chore: normalize line endings to LF
Nucs Feb 21, 2026
4f5fc05
feat(simd): add SIMD helpers for reductions, fix np.any bug, NumPy Na…
Nucs Mar 7, 2026
cbeb12a
feat(kernel): complete ILKernelGenerator coverage with SIMD optimizat…
Nucs Mar 8, 2026
4cf6bda
feat(api): complete kernel API audit with NumPy 2.x alignment
Nucs Mar 8, 2026
066dcd2
fix: comprehensive bug fixes from parallel agent battle-testing
Nucs Mar 8, 2026
8217913
feat: SIMD-optimized MatMul with 35-100x speedup over scalar path
Nucs Mar 13, 2026
bb54a79
feat: IL kernel migration for reductions, scans, and math ops
Nucs Mar 13, 2026
c0e965f
fix: test assertion bugs and API mismatches in PowerEdgeCaseTests and…
Nucs Mar 14, 2026
e1cbf0e
feat: Phase 1 int64 indexing - Shape, Slice, NDArray core types
Nucs Mar 14, 2026
7ecaaac
fix: additional int64 conversions for Phase 1
Nucs Mar 14, 2026
a623bb4
fix: ArraySlice<T> interface implementation for long indexing
Nucs Mar 14, 2026
fb5ce30
fix: NDArray.cs - all params int[] methods now have long[] primary + …
Nucs Mar 14, 2026
6d1cc85
refactor(int64): NDArray.String.cs - handle long Count with overflow …
Nucs Mar 14, 2026
3aa6b86
refactor(int64): NDArray.String.cs - complete straightforward fixes
Nucs Mar 14, 2026
5744258
refactor(int64): UnmanagedStorage.Getters/Setters - migrate to long i…
Nucs Mar 14, 2026
89ef0ad
refactor(int64): core type fixes - NDArray, Storage, Iterator
Nucs Mar 14, 2026
319a990
refactor(int64): migrate all Incrementors to long indices
Nucs Mar 14, 2026
c3fc45b
int64 indexing: partial fixes for ArraySlice, random, incrementor
Nucs Mar 14, 2026
4a7869a
int64 indexing: MatMul, unique, itemset, convolve fixes
Nucs Mar 14, 2026
6c6ec77
int64 indexing: IKernelProvider, Transpose, Clip, TensorEngine, Shape…
Nucs Mar 14, 2026
0a41ded
int64 indexing: SimdMatMul, np.nonzero, NDArray indexer, Transpose
Nucs Mar 14, 2026
96bf0aa
int64: AllSimdHelper totalSize and loop counters to long
Nucs Mar 14, 2026
b62e5bf
int64: ILKernelGenerator.Clip.cs and Default.Dot.NDMD.cs migration
Nucs Mar 14, 2026
818fd07
int64: ILKernelGenerator.Clip.cs TransformOffset and Default.ATan2.cs…
Nucs Mar 14, 2026
ed48daf
int64 indexing: StrideDetector pointer params int* -> long*
Nucs Mar 14, 2026
cde429a
docs: Add int64 indexing developer guide
Nucs Mar 14, 2026
3676304
int64 indexing: comprehensive migration progress
Nucs Mar 14, 2026
e284909
int64 indexing: complete migration from NumSharp
Nucs Mar 14, 2026
b7dc1ee
fix: add long[] overloads for NDArray typed getters
Nucs Mar 14, 2026
4d61893
Create INT64_MIGRATION_GUIDE.md
Nucs Mar 15, 2026
e54c14d
fix: int64 migration compliance - audit and fixes
Nucs Mar 15, 2026
269fc84
fix: remaining int64 migration cleanup
Nucs Mar 15, 2026
ad2b2a1
fix: round 2 int64 migration - indexing and loop variables
Nucs Mar 15, 2026
3469cba
fix: rounds 3-4 int64 migration - critical fixes
Nucs Mar 15, 2026
5f9947e
fix: int64 migration - remove int.MaxValue limitations in algorithms
Nucs Mar 15, 2026
960cd4c
int64 indexing: complete loop counter migration and LongIndexBuffer
Nucs Mar 15, 2026
bb404d4
docs: update INT64_AUDIT.md - all HIGH/MEDIUM priority violations fixed
Nucs Mar 15, 2026
a7f6b81
int64 indexing: fix reduction idx/index variables to long
Nucs Mar 15, 2026
2ea73d6
int64 indexing: fix loop counters and size variables
Nucs Mar 15, 2026
b1b7b32
docs: update INT64_AUDIT.md with latest commit
Nucs Mar 15, 2026
87d1386
int64 indexing: API methods and bug fixes
Nucs Mar 15, 2026
bfbab88
docs: update INT64_AUDIT.md with latest fixes
Nucs Mar 15, 2026
aa68cc8
int64 indexing: make int overloads delegate to long overloads
Nucs Mar 15, 2026
6a571b2
int64 indexing: ArraySlice/UnmanagedMemoryBlock int->long delegation
Nucs Mar 15, 2026
b1ba742
int64 indexing: API methods and bug fixes
Nucs Mar 16, 2026
c0c9fba
feat(shuffle): add axis parameter and fix NumPy alignment (closes #582)
Nucs Mar 16, 2026
c00ca0e
fix(shuffle): align with NumPy legacy API (no axis parameter)
Nucs Mar 16, 2026
100c73e
fix(random): fix standard_normal typo and add random() alias
Nucs Mar 16, 2026
85b2904
refactor(random): align parameter names and docs with NumPy API
Nucs Mar 17, 2026
6c79613
fix: additional int64 conversions for Phase 1
Nucs Mar 14, 2026
d037ce5
int64 indexing: partial fixes for ArraySlice, random, incrementor
Nucs Mar 14, 2026
610e36d
int64 indexing: comprehensive migration progress
Nucs Mar 14, 2026
a917dcd
fix: int64 migration compliance - audit and fixes
Nucs Mar 15, 2026
8bab67d
int64 indexing: complete loop counter migration and LongIndexBuffer
Nucs Mar 15, 2026
be8a77a
docs: add consolidated LONG_INDEXING_MIGRATION.md guide
Nucs Mar 17, 2026
639034a
docs: expand LONG_INDEXING_MIGRATION.md with commit-derived patterns
Nucs Mar 17, 2026
0613ef4
docs: add LONG_INDEXING_ISSUES.md audit of remaining migration gaps
Nucs Mar 17, 2026
14a3942
docs: expand LONG_INDEXING_ISSUES.md with additional audit findings
Nucs Mar 17, 2026
4dec5dd
docs: comprehensive audit round 2 - 11 HIGH, 8 MEDIUM, 11 LOW issues
Nucs Mar 17, 2026
f82f7f8
docs: comprehensive audit round 3 - 22 HIGH, 11 MEDIUM, 11 LOW issues
Nucs Mar 17, 2026
51df4d5
fix: post-rebase fixes for ilkernel compatibility
Nucs Mar 17, 2026
2a9a62e
docs: add H23, L11-L12 from post-rebase diff scan
Nucs Mar 17, 2026
412c8b6
fix: long indexing migration batch 1 - 10 issues fixed
Nucs Mar 17, 2026
b6ff9e1
fix: long indexing migration batch 2 - 4 more issues fixed
Nucs Mar 17, 2026
9fea9e7
fix: long indexing migration batch 3 - H2, H13 fixed
Nucs Mar 17, 2026
189c265
fix: long indexing migration batch 4 - MEDIUM priority issues
Nucs Mar 17, 2026
1b74f4c
feat: SIMD optimization for NaN statistics functions
Nucs Mar 17, 2026
c591b5f
feat: upgrade Hashset<T> to long-based indexing with 33% growth for l…
Nucs Mar 17, 2026
72d6145
fix: resolve rebase conflicts and duplicate definitions
Nucs Mar 18, 2026
2c51415
fix(arange): return int64 for integer inputs (NumPy 2.x alignment)
Nucs Mar 18, 2026
8b78a0a
fix: remove int32 cast landmines for long indexing migration
Nucs Mar 18, 2026
469233b
fix: int64 migration batch 5 - ILKernel and DefaultEngine fixes
Nucs Mar 24, 2026
fa43eef
fix: int64 indexing migration batch 5 - BUILD PASSING
Nucs Mar 24, 2026
032d5d6
fix: int64 indexing migration batch 6 - test fixes for NumPy 2.x int6…
Nucs Mar 24, 2026
4bcd5f9
fix: int64 indexing migration batch 6 - loop counters and index types
Nucs Mar 24, 2026
905ecce
fix: int64 indexing migration batch 6 - overflow checks and loop coun…
Nucs Mar 24, 2026
c09be58
test: update tests for int64 arange return type
Nucs Mar 24, 2026
4440b29
fix: int64 test migration batch 7 - update tests for NumPy 2.x arange…
Nucs Mar 26, 2026
b147aef
fix: int64 test migration batch 8 - shape comparisons and np.repeat d…
Nucs Mar 26, 2026
d2d60a8
test: fix dtype-specific getter mismatches for int64 migration
Nucs Mar 26, 2026
d834cab
fix: use pointer-based access in np.all/np.any for long indexing support
Nucs Mar 27, 2026
e2d7671
chore: remove unused LongList<T> utility class
Nucs Mar 27, 2026
3f68cf3
chore: remove regen_disabled files and improve overflow exception mes…
Nucs Mar 27, 2026
bb6b2e0
docs: add comprehensive NumPy .npy/.npz format implementation reference
Nucs Mar 27, 2026
f446f9d
docs: add README for NumPy reference documentation directory
Nucs Mar 27, 2026
2dd4cc1
chore: remove temporary migration docs and test scripts
Nucs Mar 27, 2026
3f5e1e6
docs: Add IL kernel generation guide
Nucs Mar 27, 2026
d63607c
refactor(ILKernel): complete int64 migration for >2GB array support
Nucs Mar 27, 2026
371be5c
fix(int64): address critical and high priority int64 migration issues
Nucs Mar 27, 2026
87558dc
docs(int64): expand migration issues tracking with new findings
Nucs Mar 27, 2026
9dcef32
docs(int64): rewrite migration tracking document
Nucs Mar 27, 2026
745c979
fix(int64): complete remaining int64 migration phases 2-4 and 8
Nucs Mar 27, 2026
e62595f
docs(int64): update migration tracking - all phases complete
Nucs Mar 27, 2026
5b74b8e
docs: IL generation docs
Nucs Mar 27, 2026
dcfa324
fix(int64): add long[] overloads to random sampling functions
Nucs Mar 27, 2026
dba653e
fix(int64): support long population sizes in np.random.choice
Nucs Mar 27, 2026
c07673e
fix(int64): support long repeat counts in np.repeat
Nucs Mar 27, 2026
70930ef
docs(int64): add Phase 10 tracking for remaining issues
Nucs Mar 27, 2026
a55560c
fix(int64): support long indexing in NDArray.unique()
Nucs Mar 28, 2026
a39a5c8
feat(int64): add UnmanagedSpan source files from dotnet/runtime
Nucs Mar 28, 2026
5314fe0
feat(int64): convert UnmanagedSpan core types to long indexing
Nucs Mar 28, 2026
1b45284
feat(int64): rename and convert helper files to long indexing
Nucs Mar 28, 2026
87f49c4
refactor(int64): create minimal ThrowHelper and delete unused files
Nucs Mar 28, 2026
7b09239
feat(int64): change namespace to NumSharp.Utilities and fix compilation
Nucs Mar 28, 2026
176336a
feat(int64): add UnmanagedSpan overloads and fix SimdMatMul
Nucs Mar 28, 2026
f644571
feat(int64): add UnmanagedSpan extension methods for Span<T> parity
Nucs Mar 28, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
723 changes: 723 additions & 0 deletions .claude/SESSION_HISTORY_REPORT.md

Large diffs are not rendered by default.

513 changes: 513 additions & 0 deletions .claude/plans/numpy-alignment-audit.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions .claude/settings.local.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Binary file added benchmark/results-20260214-backup.tar.gz
Binary file not shown.
337 changes: 337 additions & 0 deletions docs/INT64_DEVELOPER_GUIDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,337 @@
# Int64 Indexing Migration - Developer Guide

This guide provides patterns and rules for developers continuing the int32 to int64 indexing migration.

---

## Core Principle

**Think before casting.** The goal is to use `long` everywhere indices, sizes, strides, and offsets are involved. Only cast to `int` when absolutely required by external APIs.

---

## Decision Tree: Should This Be `long`?

```
Is it an index, size, stride, offset, or count?
├── YES → Use `long`
│ └── Exception: Does external API require int?
│ ├── YES → Cast at the boundary, document why
│ └── NO → Keep as `long`
└── NO → Keep original type
```

---

## Pattern 1: Loop Counters Over Array Elements

**WRONG:**
```csharp
for (int i = 0; i < array.size; i++) // size is now long
Process(array[i]);
```

**CORRECT:**
```csharp
for (long i = 0; i < array.size; i++)
Process(array[i]);
```

**Rule:** If iterating over array indices, use `long` loop counter.

---

## Pattern 2: Coordinate Arrays

**WRONG:**
```csharp
var coords = new int[2];
coords[0] = i; // i is long
coords[1] = j; // j is long
array.GetValue(coords); // GetValue now takes long[]
```

**CORRECT:**
```csharp
var coords = new long[2];
coords[0] = i;
coords[1] = j;
array.GetValue(coords);
```

**Rule:** Coordinate arrays are `long[]`, not `int[]`.

---

## Pattern 3: Matrix Dimensions (M, K, N)

**WRONG:**
```csharp
int M = (int)left.shape[0]; // Defeats the purpose!
int K = (int)left.shape[1];
int N = (int)right.shape[1];
```

**CORRECT:**
```csharp
long M = left.shape[0]; // shape[] returns long
long K = left.shape[1];
long N = right.shape[1];
```

**Rule:** Matrix dimensions are `long`. They come from shape which is now `long[]`.

---

## Pattern 4: Pointer Arithmetic (Works Naturally)

Pointer arithmetic already supports `long` offsets:

```csharp
T* ptr = (T*)Address;
long offset = 3_000_000_000L;
T value = ptr[offset]; // OK! Pointer indexing accepts long
```

**Rule:** Pointer arithmetic is already correct. Focus on the index variables.

---

## Pattern 5: Method Signatures

When updating method signatures, change ALL index-related parameters:

**BEFORE:**
```csharp
private static void MatMulCore<T>(NDArray left, NDArray right, T* result, int M, int K, int N)
```

**AFTER:**
```csharp
private static void MatMulCore<T>(NDArray left, NDArray right, T* result, long M, long K, long N)
```

**Rule:** Update the signature AND all callers simultaneously.

---

## Pattern 6: Unsafe Pointer Parameters

**BEFORE:**
```csharp
public static unsafe bool IsContiguous(int* strides, int* shape, int ndim)
```

**AFTER:**
```csharp
public static unsafe bool IsContiguous(long* strides, long* shape, int ndim)
```

**Note:** `ndim` stays `int` (max ~32 dimensions).

---

## Pattern 7: Local Variables in Algorithms

**BEFORE:**
```csharp
int expectedStride = 1;
for (int d = ndim - 1; d >= 0; d--)
{
expectedStride *= shape[d]; // shape[d] is now long
}
```

**AFTER:**
```csharp
long expectedStride = 1;
for (int d = ndim - 1; d >= 0; d--) // d stays int (dimension index)
{
expectedStride *= shape[d];
}
```

**Rule:** Variables that accumulate products of dimensions must be `long`. Dimension indices (`d`) can stay `int`.

---

## Valid Exceptions: When int Cast IS Correct

### 1. Span<T> Operations

Span has hard `int` limitation:

```csharp
if (Count > int.MaxValue)
throw new InvalidOperationException("Storage size exceeds Span<T> maximum.");
return new Span<T>(Address, (int)Count);
```

### 2. Managed Array Allocation

.NET arrays limited to int indexing:

```csharp
if (size > int.MaxValue)
throw new InvalidOperationException("Cannot allocate managed array exceeding int.MaxValue.");
var array = new T[(int)size];
```

### 3. Algorithm Complexity Constraints

When O(n*m) complexity makes large arrays impractical anyway:

```csharp
// Convolution is O(na * nv), so practical limits are well under int.MaxValue
int na = (int)a.size;
int nv = (int)v.size;
```

**Document these exceptions with comments explaining why the cast is safe.**

---

## What Stays `int`

| Item | Reason |
|------|--------|
| `ndim` | Maximum ~32 dimensions |
| `Slice.Start/Stop/Step` | Python slice semantics |
| Dimension indices (`d` in loops) | Iterating over dimensions, not elements |
| `NPTypeCode` values | Small enum |
| Vector lane counts | Hardware-limited |

---

## Checklist for Each File

When migrating a file:

1. [ ] **Find all `int` variables** related to indices/sizes/strides/offsets
2. [ ] **Change to `long`** unless exception applies
3. [ ] **Update method signatures** if parameters are index-related
4. [ ] **Update callers** of changed methods
5. [ ] **Check loop counters** iterating over array elements
6. [ ] **Check coordinate arrays** - must be `long[]`
7. [ ] **Check pointer params** - `int*` → `long*` for strides/shapes
8. [ ] **Add overflow checks** where external APIs require `int`
9. [ ] **Document exceptions** with comments

---

## Common Error Patterns

### Error: Cannot convert long to int

```
error CS0266: Cannot implicitly convert type 'long' to 'int'
```

**Fix:** Change the receiving variable to `long`, OR if external API requires `int`, add explicit cast with overflow check.

### Error: Argument type mismatch

```
error CS1503: Argument 1: cannot convert from 'int[]' to 'long[]'
```

**Fix:** Change the array type at declaration site to `long[]`.

### Error: Iterator type mismatch

```
error CS0029: Cannot implicitly convert type 'int' to 'long' in foreach
```

**Fix:** Check if the enumerated collection now yields `long`. Update the loop variable type.

---

## File Categories and Priority

### Priority 1: Core Types (Done)
- Shape.cs - dimensions, strides, offset, size
- IArraySlice.cs - index parameters
- UnmanagedStorage.cs - Count field
- UnmanagedStorage.Getters.cs - index parameters
- UnmanagedStorage.Setters.cs - index parameters

### Priority 2: Supporting Infrastructure (In Progress)
- ArraySlice.cs / ArraySlice`1.cs - Allocate count, index operations
- Incrementors (6 files) - coordinate arrays
- StrideDetector.cs - pointer parameters

### Priority 3: IL Kernel System (Major Effort)
- IKernelProvider.cs - interface
- ILKernelGenerator.*.cs (13 files) - IL emission, delegate signatures
- SimdKernels.cs, SimdMatMul.cs - SIMD helpers

### Priority 4: DefaultEngine Operations
- Default.Clip.cs, Default.ATan2.cs
- Default.Reduction.*.cs
- Default.NonZero.cs, Default.Transpose.cs

### Priority 5: API Functions
- np.*.cs files
- NDArray.*.cs files

---

## Testing Strategy

After each batch of changes:

1. **Build** - Fix all compilation errors
2. **Run tests** - `dotnet test -- --treenode-filter "/*/*/*/*[Category!=OpenBugs]"`
3. **Check for regressions** - Compare output with NumPy

---

## Git Commit Guidelines

Commit in logical batches with descriptive messages:

```
int64 indexing: <component> <what changed>

- <specific change 1>
- <specific change 2>
- <specific change 3>
```

Example:
```
int64 indexing: StrideDetector pointer params int* -> long*

- IsContiguous: int* strides/shape -> long* strides/shape
- IsScalar: int* strides -> long* strides
- CanSimdChunk: int* params -> long*, innerSize/lhsInner/rhsInner -> long
- Classify: int* params -> long*
- expectedStride local -> long
```

---

## Quick Reference

| Old | New | Notes |
|-----|-----|-------|
| `int size` | `long size` | Array/storage size |
| `int offset` | `long offset` | Memory offset |
| `int[] dimensions` | `long[] dimensions` | Shape dimensions |
| `int[] strides` | `long[] strides` | Memory strides |
| `int[] coords` | `long[] coords` | Index coordinates |
| `int* shape` | `long* shape` | Unsafe pointer |
| `int* strides` | `long* strides` | Unsafe pointer |
| `for (int i` | `for (long i` | Element iteration |
| `int M, K, N` | `long M, K, N` | Matrix dimensions |
| `int ndim` | `int ndim` | **KEEP** - dimension count |
| `int d` (dim index) | `int d` | **KEEP** - dimension loop |

---

## Getting Help

- GitHub Issue: #584
- Migration Plan: `docs/INT64_INDEX_MIGRATION.md`
- NumPy Reference: `src/numpy/_core/include/numpy/npy_common.h:217`
2 changes: 1 addition & 1 deletion docs/issues/issue-0075-implement-numpy.asarray.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
## Description

Convert the input to an array.
https://numpy.org/doc/stable-1.15.0/reference/generated/numpy.asarray.html
https://docs.scipy.org/doc/numpy-1.15.0/reference/generated/numpy.asarray.html

## Comments

Expand Down
2 changes: 1 addition & 1 deletion docs/issues/issue-0078-implement-numpy.where.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
## Description

Return elements, either from x or y, depending on condition.
https://numpy.org/doc/stable-1.13.0/reference/generated/numpy.where.html
https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.where.html

## Comments

Expand Down
2 changes: 1 addition & 1 deletion docs/issues/issue-0105-implement-numpy.vdot.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
## Description

Return the dot product of two vectors.
https://numpy.org/doc/stable-1.15.1/reference/generated/numpy.vdot.html#numpy.vdot
https://docs.scipy.org/doc/numpy-1.15.1/reference/generated/numpy.vdot.html#numpy.vdot

`ndarray.vdot` should be put in `LinearAlgebra` folder.

Expand Down
2 changes: 1 addition & 1 deletion docs/issues/issue-0106-implement-numpy.inner.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
## Description

Inner product of two arrays.
https://numpy.org/doc/stable-1.15.1/reference/generated/numpy.inner.html#numpy.inner
https://docs.scipy.org/doc/numpy-1.15.1/reference/generated/numpy.inner.html#numpy.inner

`ndarray.inner` should be put in `LinearAlgebra` folder.
2 changes: 1 addition & 1 deletion docs/issues/issue-0108-implement-numpy.tensordot.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
## Description

Compute tensor dot product along specified axes for arrays >= 1-D.
https://numpy.org/doc/stable-1.15.1/reference/generated/numpy.tensordot.html#numpy.tensordot
https://docs.scipy.org/doc/numpy-1.15.1/reference/generated/numpy.tensordot.html#numpy.tensordot

`ndarray.tensordot` should be put in `LinearAlgebra` folder.
2 changes: 1 addition & 1 deletion docs/issues/issue-0114-implement-numpy.fft.fft.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
## Description

Compute the one-dimensional discrete Fourier Transform.
https://numpy.org/doc/stable-1.15.0/reference/generated/numpy.fft.fft.html#numpy.fft.fft
https://docs.scipy.org/doc/numpy-1.15.0/reference/generated/numpy.fft.fft.html#numpy.fft.fft
2 changes: 1 addition & 1 deletion docs/issues/issue-0202-implement-np.pad.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
## Description

Add a buffer or padding around a numpy array:
https://numpy.org/doc/stable/reference/generated/numpy.pad.html
https://docs.scipy.org/doc/numpy/reference/generated/numpy.pad.html

## Comments

Expand Down
Loading
Loading