Skip to content

Commit 4bcd5f9

Browse files
committed
fix: int64 indexing migration batch 6 - loop counters and index types
- Default.All.cs: int i -> long i for size iteration - Default.Any.cs: int i -> long i for size iteration - StackedMemoryPool.cs: int i -> long i (count param is long) - np.random.poisson.cs: int i -> long i for size iteration - np.random.bernoulli.cs: int i -> long i for size iteration - np.random.randn.cs: int i -> long i for size iteration - NDArray.Indexing.Masking.cs: - int idx -> long idx for trueCount iteration - GetInt32 -> GetInt64 (nonzero returns NDArray<long>[]) - int valueIdx -> long valueIdx for mask.size iteration All changes follow INT64_DEVELOPER_GUIDE.md patterns.
1 parent 032d5d6 commit 4bcd5f9

8 files changed

Lines changed: 70 additions & 14 deletions

File tree

docs/INT64_MIGRATION_PROGRESS.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,62 @@ This document tracks the progress of migrating recent commits to comply with the
1818

1919
---
2020

21+
## Completed Fixes (Session 4)
22+
23+
### 32. Default.All.cs - Loop counter fix
24+
25+
**Location**: `src/NumSharp.Core/Backends/Default/Logic/Default.All.cs`
26+
27+
**Changes**:
28+
- `var len = nd.size; for (int i = 0; i < len; i++)``long len = nd.size; for (long i = 0; i < len; i++)`
29+
30+
### 33. Default.Any.cs - Loop counter fix
31+
32+
**Location**: `src/NumSharp.Core/Backends/Default/Logic/Default.Any.cs`
33+
34+
**Changes**:
35+
- Same fix as Default.All.cs
36+
37+
### 34. np.random.poisson.cs - Loop counter fix
38+
39+
**Location**: `src/NumSharp.Core/RandomSampling/np.random.poisson.cs`
40+
41+
**Changes**:
42+
- `var len = result.size; for (int i = 0; i < len; i++)``long len; for (long i ...)`
43+
44+
### 35. np.random.bernoulli.cs - Loop counter fix
45+
46+
**Location**: `src/NumSharp.Core/RandomSampling/np.random.bernoulli.cs`
47+
48+
**Changes**:
49+
- Same pattern fix for loop counter
50+
51+
### 36. StackedMemoryPool.cs - Loop counter fix
52+
53+
**Location**: `src/NumSharp.Core/Backends/Unmanaged/Pooling/StackedMemoryPool.cs`
54+
55+
**Changes**:
56+
- `for (int i = 0; i < count; i++, addr += SingleSize)``for (long i = 0; i < count; i++, ...)`
57+
- `count` parameter is `long`, so loop counter must be `long`
58+
59+
### 37. NDArray.Indexing.Masking.cs - Multiple fixes
60+
61+
**Location**: `src/NumSharp.Core/Selection/NDArray.Indexing.Masking.cs`
62+
63+
**Changes**:
64+
- `for (int idx = 0; idx < trueCount; idx++)``for (long idx = 0; idx < trueCount; idx++)`
65+
- `indices[dim].GetInt32(idx)``indices[dim].GetInt64(idx)` (nonzero now returns `NDArray<long>[]`)
66+
- `int valueIdx = 0; for (int i = 0; i < mask.size; i++)``long valueIdx = 0; for (long i ...)`
67+
68+
### 38. np.random.randn.cs - Loop counter fix
69+
70+
**Location**: `src/NumSharp.Core/RandomSampling/np.random.randn.cs`
71+
72+
**Changes**:
73+
- `for (int i = 0; i < array.size; i++)``for (long i = 0; i < array.size; i++)`
74+
75+
---
76+
2177
## Completed Fixes (Session 3)
2278

2379
### 30. np.random.shuffle.cs - NextLong fix

src/NumSharp.Core/Backends/Default/Logic/Default.All.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ private static unsafe bool AllImpl<T>(NDArray nd) where T : unmanaged
5454

5555
// Scalar fallback for contiguous arrays
5656
var addr = (T*)nd.Address;
57-
var len = nd.size;
58-
for (int i = 0; i < len; i++)
57+
long len = nd.size;
58+
for (long i = 0; i < len; i++)
5959
{
6060
if (addr[i].Equals(default(T)))
6161
return false;

src/NumSharp.Core/Backends/Default/Logic/Default.Any.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ private static unsafe bool AnyImpl<T>(NDArray nd) where T : unmanaged
5454

5555
// Scalar fallback for contiguous arrays
5656
var addr = (T*)nd.Address;
57-
var len = nd.size;
58-
for (int i = 0; i < len; i++)
57+
long len = nd.size;
58+
for (long i = 0; i < len; i++)
5959
{
6060
if (!addr[i].Equals(default(T)))
6161
return true;

src/NumSharp.Core/Backends/Unmanaged/Pooling/StackedMemoryPool.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public unsafe void AllocateCount(long count)
204204
var block = new UnmanagedMemoryBlock<byte>(blocksize);
205205

206206
var addr = new IntPtr(block.Address);
207-
for (int i = 0; i < count; i++, addr += SingleSize)
207+
for (long i = 0; i < count; i++, addr += SingleSize)
208208
availables_blocks.Push(addr);
209209

210210
_blocks.Add(block);

src/NumSharp.Core/RandomSampling/np.random.bernoulli.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ public NDArray bernoulli(double p, params int[] size)
4242
unsafe
4343
{
4444
var addr = result.Address;
45-
var len = result.size;
45+
long len = result.size;
4646
Func<double> nextDouble = randomizer.NextDouble;
47-
for (int i = 0; i < len; i++)
47+
for (long i = 0; i < len; i++)
4848
addr[i] = nextDouble() < p ? 1 : 0;
4949
}
5050

src/NumSharp.Core/RandomSampling/np.random.poisson.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ public NDArray poisson(double lam, params int[] size)
3838
var result = new NDArray<double>(size);
3939
unsafe
4040
{
41-
var len = result.size;
41+
long len = result.size;
4242
var resultArray = result.Address;
43-
for (int i = 0; i < len; i++)
43+
for (long i = 0; i < len; i++)
4444
resultArray[i] = Knuth(lam);
4545
}
4646

src/NumSharp.Core/RandomSampling/np.random.randn.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public NDArray normal(double loc, double scale, params int[] size)
8989
var dst = array.Address;
9090

9191
Func<double> nextDouble = randomizer.NextDouble;
92-
for (int i = 0; i < array.size; i++)
92+
for (long i = 0; i < array.size; i++)
9393
dst[i] = loc + scale * Math.Sqrt(-2.0 * Math.Log(1.0 - nextDouble()))
9494
* Math.Sin(2.0 * Math.PI * (1.0 - nextDouble()));
9595

src/NumSharp.Core/Selection/NDArray.Indexing.Masking.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,13 @@ private NDArray BooleanMaskPartialShape(NDArray<bool> mask)
175175
var result = new NDArray(this.dtype, new Shape(resultShape));
176176

177177
// Copy selected slices using the nonzero indices
178-
for (int idx = 0; idx < trueCount; idx++)
178+
for (long idx = 0; idx < trueCount; idx++)
179179
{
180180
// Build the index tuple from nonzero results
181181
var srcSlice = this;
182182
for (int dim = 0; dim < mask.ndim; dim++)
183183
{
184-
srcSlice = srcSlice[indices[dim].GetInt32(idx)];
184+
srcSlice = srcSlice[indices[dim].GetInt64(idx)];
185185
}
186186
np.copyto(result[idx], srcSlice);
187187
}
@@ -284,8 +284,8 @@ private void SetBooleanMaskAxis0(NDArray<bool> mask, NDArray value)
284284
// NumSharp represents scalars as shape [1], not shape []
285285
bool isScalarValue = value.size == 1;
286286

287-
int valueIdx = 0;
288-
for (int i = 0; i < mask.size; i++)
287+
long valueIdx = 0;
288+
for (long i = 0; i < mask.size; i++)
289289
{
290290
if (mask.GetBoolean(i))
291291
{

0 commit comments

Comments
 (0)