Skip to content

Fix NumPy array to scalar conversion due to deprecation#162

Open
austinkimchi wants to merge 1 commit into
scalesim-project:mainfrom
austinkimchi:fix-numpy-deprecated
Open

Fix NumPy array to scalar conversion due to deprecation#162
austinkimchi wants to merge 1 commit into
scalesim-project:mainfrom
austinkimchi:fix-numpy-deprecated

Conversation

@austinkimchi

Copy link
Copy Markdown

Issue

double_buffered_scratchpad_mem.py computes total_cycles using int(max(ofmap_serviced_cycles)).

ofmap_serviced_cycles contains NumPy arrays, so max(...) can return a one-dimensional NumPy array. NumPy 1.25 deprecated converting arrays with ndim > 0 directly to scalars, and newer NumPy versions raise a TypeError.

Fixes

This uses np.max(ofmap_serviced_cycles) before converting to int.

Resolves failures like: TypeError: only 0-dimensional arrays can be converted to Python scalars

Resources

Only ndim-0 arrays are treated as scalars.

NumPy 1.25 Release Notes

Starting with NumPy 2.4.0 (Released in Dec 2025), this expired deprecation now raises a TypeError.

Raise TypeError on attempt to convert array with ndim > 0 to scalar

NumPy 2.4.0

image

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates SCALE-Sim’s double-buffered scratchpad memory simulation to be compatible with newer NumPy versions by avoiding deprecated array-to-scalar conversions when computing total_cycles.

Changes:

  • Replace int(max(ofmap_serviced_cycles)) with a NumPy reduction (np.max) before converting to int to prevent TypeError on NumPy versions that forbid converting ndim > 0 arrays to scalars.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 303 to +307
self.ofmap_trace_matrix = np.concatenate((ofmap_services_cycles_np, ofmap_demand_mat),
axis=1)
#self.total_cycles = int(ofmap_serviced_cycles[-1][0])
## Probable fault in sanity check
self.total_cycles = int(max(ofmap_serviced_cycles))
self.total_cycles = int(np.max(ofmap_serviced_cycles))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants