Skip to content

Replace apply() with storage.mode() for integer to numeric conversion#526

Merged
jgabry merged 2 commits into
stan-dev:masterfrom
utkarshpawade:fix/storage-mode-integer-conversion
Apr 6, 2026
Merged

Replace apply() with storage.mode() for integer to numeric conversion#526
jgabry merged 2 commits into
stan-dev:masterfrom
utkarshpawade:fix/storage-mode-integer-conversion

Conversation

@utkarshpawade

Copy link
Copy Markdown
Contributor

Fixes #525

replace apply(predictions, 2, as.numeric) in validate_predictions() with storage.mode(predictions) <- "numeric", an in place conversion that avoids column wise iteration and intermediates. this also removes the unnecessary nrow == 1 special case since storage.mode<- handles all matrix dimensions uniformly

Copilot AI review requested due to automatic review settings April 6, 2026 13:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 optimizes integer-to-numeric conversion inside validate_predictions() by switching from a column-wise apply(..., as.numeric) approach to an in-place storage.mode<- conversion, removing the prior special-case for single-row matrices.

Changes:

  • Replace apply(predictions, 2, as.numeric) with storage.mode(predictions) <- "numeric" for integer matrices.
  • Remove the nrow(predictions) == 1 special-case branch since storage.mode<- handles all dimensions uniformly.

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

@utkarshpawade utkarshpawade changed the title Replace apply() with storage.mode() for integer-to-numeric conversion Replace apply() with storage.mode() for integer to numeric conversion Apr 6, 2026
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.67%. Comparing base (a86c556) to head (989cce1).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #526      +/-   ##
==========================================
- Coverage   98.67%   98.67%   -0.01%     
==========================================
  Files          35       35              
  Lines        5905     5903       -2     
==========================================
- Hits         5827     5825       -2     
  Misses         78       78              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jgabry jgabry left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@jgabry jgabry merged commit 62fce06 into stan-dev:master Apr 6, 2026
6 checks passed
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.

Replace inefficient apply() with storage.mode() for integer-to-numeric matrix conversion

4 participants