File tree 1 file changed +22
-0
lines changed
1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -57,6 +57,28 @@ def freeze_dims_and_data(
57
57
-------
58
58
Model
59
59
A new model with the specified dimensions and data frozen.
60
+
61
+
62
+ Examples
63
+ --------
64
+ .. code-block:: python
65
+
66
+ import pymc as pm
67
+ import pytensor.tensor as pt
68
+
69
+ from pymc.model.transform.optimization import freeze_dims_and_data
70
+
71
+ with pm.Model() as m:
72
+ x = pm.Data("x", [0, 1, 2] * 1000)
73
+ y = pm.Normal("y", mu=pt.unique(x).mean())
74
+
75
+ # pt.unique(x).mean() has to be computed in every logp function evaluation
76
+ print("Logp eval time (1000x): ", m.profile(m.logp()).fct_call_time)
77
+
78
+ # pt.uniqe(x).mean() is cached in the logp function
79
+ frozen_m = freeze_dims_and_data(m)
80
+ print("Logp eval time (1000x): ", frozen_m.profile(frozen_m.logp()).fct_call_time)
81
+
60
82
"""
61
83
fg , memo = fgraph_from_model (model )
62
84
You can’t perform that action at this time.
0 commit comments