Repository navigation
Speed up EM hot paths without changing results - #30
Open
olivierC80 wants to merge 2 commits into
Open
olivierC80 wants to merge 2 commits into
olivierC80 wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR reduces allocation and native-call overhead in
poLCAwhile preservingthe package's results exactly for the tested execution paths.
The implementation deliberately excludes algebraically equivalent changes that
altered floating-point results in the last bits. It also excludes the
poLCA.compress()optimization because that function is already being changedin #28.
Changes
as.integer(t(y))once per fit and reuse it in native wrappers.PACKAGE = "poLCA"to the existing.C()calls.postclassandprobhatloops into one internal.Call()for models with and without covariates.
the order of floating-point operations.
rmulti()with.Call()and R's RNG API while preserving both itsnumeric return type and RNG stream.
poLCA.se()without replacing orreordering its matrix calculations.
max.col(..., ties.method = "first")for modal assignment.Exact-result validation
The candidate was compared with commit
2ffbf2fd44fe707c54e3939fe929b8032b5db63fusing separately installed sourcepackages. No rounding or numeric tolerance was used: results were checked with
identical()after removing only the nondeterministic elapsed-time field.The strict comparison covered:
nrep = 3;and variance-covariance matrices;
rmulti(), including the resulting RNG state.All compared objects were strictly identical, including types, dimensions,
attributes, and floating-point values.
The new package test additionally compares the fused native helpers directly
with the historical
postclassandprobhatwrappers for shared/varying priorsand complete/missing data. It also checks exact
rmulti()output and RNG state.Performance
Mean elapsed time over 10 repetitions, original versus candidate installed
source packages:
fit_basicfit_covariatesfit_covariates_largefit_em_largefit_em_xlargefit_heavyfit_heavy_sefit_missing_keep_narmulti_largesimdataPackage check
R CMD check --no-manual --no-build-vignettescompletes with no errors orwarnings. It reports the same existing NOTE as the unmodified baseline:
Deliberate exclusions
The following previously explored changes are not included because they did
not satisfy strict bit-for-bit equality:
t(s) %*% swithcrossprod(s);tcrossprod();Jac.mixthrough an algebraically equivalent reordered formula;