Skip to content

Commit

Permalink
Moving imports inside functions to make them lazily loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
peekxc committed Oct 10, 2023
1 parent 466d8cb commit 420bbce
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
16 changes: 9 additions & 7 deletions src/primate/plotting.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import numpy as np

import bokeh
from bokeh.models import Span, Scatter, LinearAxis, Range1d, BoxAnnotation, Legend, Band, ColumnDataSource
from bokeh.plotting import figure
from bokeh.layouts import row
from bokeh.models import NumeralTickFormatter
from scipy.special import erfinv

def figure_trace(info: dict, real_trace: float = None, **kwargs) -> figure:
def figure_trace(info: dict, real_trace: float = None, **kwargs):
"""Plots the trace estimates """
import bokeh
from bokeh.models import Span, Scatter, LinearAxis, Range1d, BoxAnnotation, Legend, Band, ColumnDataSource
from bokeh.plotting import figure
from bokeh.layouts import row
from bokeh.models import NumeralTickFormatter

samples = np.ravel(info['convergence']['samples'])
sample_index = np.arange(1, len(samples)+1)
Expand Down Expand Up @@ -75,3 +74,6 @@ def figure_trace(info: dict, real_trace: float = None, **kwargs) -> figure:
q.add_layout(legend, "center")
return row([p,q])

def plot_trace(info: dict, real_trace: float = None, **kwargs) -> None:
from bokeh.plotting import show
show(figure_trace(info, real_trace, **kwargs))
7 changes: 3 additions & 4 deletions src/primate/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,9 @@ def slq (
# if verbose: te_util.print_summary(info)
# if plot: te_plot.plot_convergence(info)
if plot:
from bokeh.plotting import show
from .plotting import figure_trace
show(figure_trace(info))

from .plotting import plot_trace
plot_trace(info)

return (trace, info) if output_is_array else (trace[0], info)


Expand Down

0 comments on commit 420bbce

Please sign in to comment.