Skip to content

Major upgrade - #182

Draft
oschulz wants to merge 75 commits into
mainfrom
major-upgrade
Draft

Major upgrade#182
oschulz wants to merge 75 commits into
mainfrom
major-upgrade

Conversation

@oschulz

@oschulz oschulz commented Aug 23, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

oschulz added 30 commits July 5, 2026 12:38
Shouldn't call Core.Compiler.return_type directly in many places.
Will be used a lot when bridging from Distributions to MeasureBase.
Currently unused and undocumented, can add it back later when needed.
Created by generative AI.
Assisted by generative AI.
Unused and untested.

(cherry picked from commit 1d27188)
Not used currently.

(cherry picked from commit 9844583)
A rebase can easily be written explicitly.

(cherry picked from commit fb3c98c)
`mintegral` should be used instead to express posteriors.

(cherry picked from commit 3c61180)
To be re-introduced in sub-module MeasureOperators.

(cherry picked from commit 0cdca3d)
oschulz added 28 commits July 6, 2026 20:06
Dirac measures with equal points are equal measures; the default
object identity failed for array-valued points.

Created by generative AI.
Products of weighted measures (tuples, named tuples and arrays) now pull
the total weight out, following the canonical measure nesting. Empty
products are explicit unit measures (Dirac of the empty variate). Arrays
of measures are no longer copied via broadcast asmeasure, and arrays of
a single singleton measure type collapse to power measures without
requiring a non-empty array. The static-weight optimization now stays
static when the array length is static.

Created by generative AI.
Pushforwards of point masses collapse to point masses and pushforwards
commute with weighting. The identity shortcut moves from _pushfwd_impl
to pushfwd itself and the two style-specific pushfwd/pullbck methods
merge into single PushFwdStyle methods, keeping dispatch unambiguous.

Created by generative AI.
Matches the other smart constructors, which are documented and exported.

Created by generative AI.
Covers the power/product/superpose/pushfwd/restrict simplifications.
Also wires the previously orphaned superpose tests into the test suite,
updated to current basemeasure collapse behavior.

Created by generative AI.
Measure transport now falls back to a pivot through a flat vector of
standard uniform variates, using the with-rest transport protocol, when
the DOF of either side is not fast-computable. This enables transport
between hierarchical measures (Bind) and between known-DOF and
unknown-DOF measures, as already promised by the transport_def
docstring.

The mvstd gateway now also verifies that the produced variate length
matches the target standard power measure, instead of silently
returning a variate of the wrong length.

Created by generative AI.
Superposition simplifications now only happen when measure equality is
decidable from the measure types alone (via the new _static_isequal),
instead of branching on runtime measure equality. As a consequence,
value-equal measures of non-singleton type (e.g. equal Diracs) now stay
superpositions instead of collapsing to weighted measures, and
basemeasure of superpositions with equal-typed components is type stable.

Created by generative AI.
…ith-rest

logdensityof is now a single generic entry function; measure types
specialize the new MeasureBase.logdensityof_impl instead of logdensityof
itself. The new logdensityof_with_rest protocol evaluates densities of
measures that live at the beginning of a flat variate stream (a vector
for vcat-combined and a NamedTuple for merge-combined measures),
returning the log-density, the consumed variate and the unconsumed rest
of the stream. Its default implementation determines the variate size
via mspace_elsize (falling back to testvalue).

Bind and CombinedMeasure evaluate densities of vcat- and merge-combined
variates through logdensityof_with_rest in a single pass now, without
materializing intermediate transport measures and without splitting
sub-variates twice. Variates that are too long now result in an
informative exception, and so do binds whose value combination function
does not support variate splitting.

Created by generative AI.
The generic three-argument logdensity_def now descends the base measure
chains of both measures in lockstep after equalizing their static depths.
Since the members of a shared chain suffix have the same depth-from-root
on both sides, shared suffixes cancel symbolically. The descent is fully
unrolled at compile time and constructs only the base measures it
actually visits.

Specialized relative densities move from three-argument logdensity_def
methods to the new extension point MeasureBase.logdensity_rel_def. The
descent checks for an applicable specialization at each visited measure
pair; availability is decided purely by dispatch via a sentinel return
type instead of method-table introspection, so the checks are free at
run time and defining new specializations behaves like any ordinary
method definition.

This removes basemeasure_sequence-based chain materialization, the
commonbase search, schema and the static_hasmethod gate from the
relative density code path. Root measure pairs without a specialization
now throw an informative exception instead of warning and returning NaN.

Created by generative AI.
Products over vectors of same-typed unknown-DOF marginals (e.g. binds)
now transport from multivariate standard measures via a typed loop
instead of accumulating into a Vector{Any}; marginal vectors with
abstract element type keep the untyped fallback.

Created by generative AI.
Fixes ambiguities between the static-size power density methods and
powers of primitive measures (the existing disambiguation method did not
cover them), between the massof methods generated by @useproxy and
massof over intervals, and in the legacy kernel constructors. Package
ambiguity testing (including the Aqua ambiguity check) is now enabled in
the test suite.

Created by generative AI.
Removes kernel.jl (AbstractTransitionKernel and its subtypes, the
kernel/kleisli constructors), the parameterized-measure kernel
constructors and the kernel-based productmeasure methods. MKernel and
mbind supersede this functionality. The basekernel helper stays, it is
independent of the kernel types.

Created by generative AI.
Adds mspace_elsize methods for standard measures (scalar), Dirac and
powers of scalar-variate measures (static where the axes are static),
and NamedTuple-product variate names based on the marginal names alone.
Flat vector streams now support scalar variates (consuming a single
stream element, also in vcat variate splitting) and multi-rank variates
(consumed in flattened form and reshaped). This enables densities and
transport for binds with scalar-variate primary measures and density
evaluation of multi-dimensional powers inside flat streams.

Created by generative AI.
Relative densities between product measures were a specialization of
logdensity_rel itself, bypassing the support-check layer at the product
level. They are now logdensity_rel_def methods (with a type-stable
tuple-marginals variant) evaluating marginals via unsafe_logdensity_rel,
support checking happens for the products as a whole in logdensity_rel.

Created by generative AI.
…sities

The smf-based interval mass now fails with an informative exception for
measures without a statistical measure function instead of a MethodError
on NoSMF values. The generic non-real-variate log-density of primitive
measures returns a static zero instead of false. test_smf now tolerates
insupport results that are not booleans (NoFastInsupport) and the
logdensity_def docstring points to logdensity_rel_def as the extension
point for specialized relative densities.

Created by generative AI.
Created by generative AI.
…riate sizes

Densities and standard-measure transport for products of hierarchical
measures (in vector, tuple and named-tuple marginal form) work through
the with-rest machinery; keep it that way.

Created by generative AI.
combinesets(f_c, α, β) combines two sets along the value combination
semantics of mcombine, with specific set representations where possible:
cartesian products concatenate under vcat and merge, one-dimensional
cartesian powers of equal (singleton-typed) base sets concatenate under
vcat, and implicit domains of measures combine into the implicit domain
of the combined measure. CombinedMeasure now provides mdomain.

Also fixes two latent bugs uncovered by the new tests: setcartprod for
NamedTuple sets had an unbound type parameter and never matched, and
membership tests for CartesianPower used reversed argument order in
Base.in.

Created by generative AI.
logdensities(mu, X) computes the log-density of mu at each point in X,
preserving the shape of X. Measure types specialize logdensities_impl.

Power measures unwrap into power axes arguments of the internal machinery
(ordered outermost first), so implementation methods never dispatch on
nested PowerMeasure type signatures. Scalar-variate measures evaluate as
a single flat broadcast; power batches with flat variate storage
(ArrayOfSimilarArrays) additionally fuse the per-point reduction into a
single segmented sum, keeping GPU-backed data on-device.

Created by generative AI.
logdensityof_impl and logdensity_def for PowerMeasure now unwrap the power
structure into the power axes arguments of the batched density machinery.
Nested powers with flat variate storage evaluate as a single fused
broadcast and segmented reduction, GPU-compatible.

Replaces the per-level power density methods, including the static-size
specialization and its disambiguation methods, and removes the now unused
infer_logdensity_type.

Created by generative AI.
Batched protocol functions pair with their scalar counterparts by name:
batched_logdensityof_impl implements logdensities, further batched_*
functions (with-rest, transport, rand) will follow the same scheme.

Created by generative AI.
Reactant traced scalars subtype Number, not Real. Widens primitive leaf
density kernels, batched density eltype gates, with-rest stream
signatures, log-weight arguments and numtype conversion sources.
Real stays where realness is semantic (domain membership, numtype
request parameters).

Created by generative AI.
Replaces insupport ternaries in the primitive and standard density
kernels with _checksupport (ifelse-based) and the value branches in
_combine_logd_with_ladj with nested ifelse. StdUniform's insupport uses
non-short-circuiting comparisons. Required for traced values (Reactant),
where control flow must not depend on runtime values.

Created by generative AI.
The weight-shifted density of a support-safe base density is
support-safe, so weighted measures need no explicit support check.
Removes a redundant per-point insupport sweep over the base measure.

Created by generative AI.
Widens Real argument types to Number in the cdf/quantile/affine
transport machinery and makes the StdUniform transport gateways
branch-free (out-of-support results are masked via ifelse, the quantile
argument is clamped to keep eager evaluation valid). Distributions with
standard-measure or affine transport origins now work with traced
values; families that require inverse incomplete beta/gamma functions
remain host-only.

Created by generative AI.
Domain membership methods for traced numbers: Reactant's traced scalars
subtype Number, not Real or Integer, so membership in RealValues and
IntegerValues is decided by their value type parameter.

Created by generative AI.
@oschulz
oschulz marked this pull request as draft August 23, 2026 14:30
@codecov

codecov Bot commented Aug 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 71.53447% with 384 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.46%. Comparing base (7abad19) to head (6be425e).

Files with missing lines Patch % Lines
src/domains.jl 51.64% 44 Missing ⚠️
src/combinators/bind.jl 59.37% 39 Missing ⚠️
src/combinators/combined.jl 55.40% 33 Missing ⚠️
src/combinators/product_transport.jl 78.23% 32 Missing ⚠️
src/combinators/likelihood.jl 20.68% 23 Missing ⚠️
...easureBaseDistributionsExt/distribution_measure.jl 45.00% 22 Missing ⚠️
src/combinators/smart-constructors.jl 81.81% 14 Missing ⚠️
ext/MeasureBaseDistributionsExt/standard_dist.jl 81.69% 13 Missing ⚠️
src/primitives/lebesgue.jl 31.57% 13 Missing ⚠️
src/getdof.jl 47.82% 12 Missing ⚠️
... and 33 more
Additional details and impacted files
@@             Coverage Diff             @@
##             main     #182       +/-   ##
===========================================
+ Coverage   54.11%   68.46%   +14.35%     
===========================================
  Files          44       64       +20     
  Lines        1253     2134      +881     
===========================================
+ Hits          678     1461      +783     
- Misses        575      673       +98     

☔ View full report in Codecov by Harness.
📢 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.

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