Skip to content

Accept integer theta in dcsbm(), chung_lu() and directed_dcsbm() - #63

Draft
alexpghayes wants to merge 1 commit into
mainfrom
fix/integer-theta
Draft

alexpghayes wants to merge 1 commit into
mainfrom
fix/integer-theta

Conversation

@alexpghayes

Copy link
Copy Markdown
Collaborator

Bug

Integer theta crashed model construction:

dcsbm(theta = 1:10, B = diag(2))
#> Error: REAL() can only be applied to a 'numeric', not a 'integer'
chung_lu(theta = 1:10)
#> Error: invalid class "dgeMatrix" object: 'x' slot is not of type "double"
m <- chung_lu(theta = 1:10, sort_nodes = FALSE)   # builds, but then
expected_degree(m); sample_sparse(m)              # both error

set_membership_weights() (R/utils.R) wrote theta straight into the double x slot of the membership matrix. It only worked with force_identifiability = TRUE because normalizing made theta double. Inputs like rpois(n, 2) + 1L hit this.

Fix

Coerce to double inside set_membership_weights(), as the shared-blocks branch of directed_dcsbm() already did at the call site.

Tests

New tests/testthat/test-integer-theta.R: integer theta for dcsbm(), chung_lu() and directed_dcsbm() (k = 1 and 2), with both force_identifiability and sort_nodes values, gives the same model as the double version and can be sampled. Fails on main (3 errors), passes here. Full suite passes.

NEWS

Left out to avoid conflicting with the 1.0.0 reorganization in #59. Suggested bullet under Bug fixes:

  • dcsbm(), chung_lu() and directed_dcsbm() now accept integer theta (e.g. rpois(n, 2) + 1L). Previously model construction errored, or with sort_nodes = FALSE built a model that errored in expected_degree() and sample_sparse().

🤖 Generated with Claude Code

set_membership_weights() wrote integer theta straight into the double
`x` slot of the membership matrix, so integer theta (e.g. from
`rpois(n, 2) + 1L`) crashed model construction, or with
`sort_nodes = FALSE` built an invalid model that failed in
expected_degree() and sample_sparse(). Coerce to double first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant