88
99import pickle
1010import re
11+ import textwrap
1112
1213import gpytorch
1314import numpy as np
@@ -471,7 +472,6 @@ def _predict(self, X):
471472 Module : gpytorch.models.ExactGP (class or instance)
472473 The module needs to return a
473474 :class:`~gpytorch.distributions.MultivariateNormal` distribution.
474-
475475"""
476476
477477exact_gp_regr_criterion_text = """
@@ -483,7 +483,6 @@ def _predict(self, X):
483483 criterion : gpytorch.mlls.ExactMarginalLogLikelihood
484484 The objective function to learn the posterior of of the GP regressor.
485485 Usually doesn't need to be changed.
486-
487486"""
488487
489488exact_gp_regr_batch_size_text = """
@@ -492,7 +491,6 @@ def _predict(self, X):
492491 Mini-batch size. For exact GPs, it must be set to -1, since the exact
493492 solution cannot deal with batching. To make use of batching, use
494493 :class:`.GPRegressor` in conjunction with a variational strategy.
495-
496494"""
497495
498496# this is the same text for exact and approximate GP regression
@@ -505,37 +503,40 @@ def _predict(self, X):
505503 None. There is no default train split for GP regressors because random
506504 splitting is typically not desired, e.g. because there is a temporal
507505 relationship between samples.
508-
509506"""
510507
511508# this is the same text for all GPs
512509gp_likelihood_attribute_text = """
513-
514510 likelihood_: torch module (instance)
515511 The instantiated likelihood.
516-
517512"""
518513
519514
520515def get_exact_gp_regr_doc (doc ):
521516 """Customizes the net docs to avoid duplication."""
517+ # dedent/indent roundtrip required for consistent indention in both
518+ # Python <3.13 and Python >=3.13
519+ # Because <3.13 => no automatic dedent, but it is the case in >=3.13
520+ indentation = " "
521+ doc = textwrap .indent (textwrap .dedent (doc .split ("\n " , 5 )[- 1 ]), indentation )
522+
522523 params_start_idx = doc .find (' Parameters\n ----------' )
523524 doc = doc [params_start_idx :]
524- doc = exact_gp_regr_doc_start + " " + doc
525+ doc = exact_gp_regr_doc_start + doc
525526
526- pattern = re .compile (r'(\n\s+)(module .*\n)(\s.+){1,99}' )
527+ pattern = re .compile (r'(\n\s+)(module .*\n)(\s.+|. ){1,99}' )
527528 start , end = pattern .search (doc ).span ()
528529 doc = doc [:start ] + exact_gp_regr_module_text + doc [end :]
529530
530- pattern = re .compile (r'(\n\s+)(criterion .*\n)(\s.+){1,99}' )
531+ pattern = re .compile (r'(\n\s+)(criterion .*\n)(\s.+|. ){1,99}' )
531532 start , end = pattern .search (doc ).span ()
532533 doc = doc [:start ] + exact_gp_regr_criterion_text + doc [end :]
533534
534- pattern = re .compile (r'(\n\s+)(batch_size .*\n)(\s.+){1,99}' )
535+ pattern = re .compile (r'(\n\s+)(batch_size .*\n)(\s.+|. ){1,99}' )
535536 start , end = pattern .search (doc ).span ()
536537 doc = doc [:start ] + exact_gp_regr_batch_size_text + doc [end :]
537538
538- pattern = re .compile (r'(\n\s+)(train_split .*\n)(\s.+){1,99}' )
539+ pattern = re .compile (r'(\n\s+)(train_split .*\n)(\s.+|. ){1,99}' )
539540 start , end = pattern .search (doc ).span ()
540541 doc = doc [:start ] + gp_regr_train_split_text + doc [end :]
541542
@@ -672,7 +673,6 @@ def fit(self, X, y=None, **fit_params):
672673 Module : gpytorch.models.ApproximateGP (class or instance)
673674 The GPyTorch module; in contrast to exact GP, the return distribution does
674675 not need to be Gaussian.
675-
676676"""
677677
678678gp_regr_criterion_text = """
@@ -684,25 +684,30 @@ def fit(self, X, y=None, **fit_params):
684684 criterion : gpytorch.mlls.VariationalELBO
685685 The objective function to learn the approximate posterior of of the GP
686686 regressor.
687-
688687"""
689688
690689
691690def get_gp_regr_doc (doc ):
692691 """Customizes the net docs to avoid duplication."""
692+ # dedent/indent roundtrip required for consistent indention in both
693+ # Python <3.13 and Python >=3.13
694+ # Because <3.13 => no automatic dedent, but it is the case in >=3.13
695+ indentation = " "
696+ doc = textwrap .indent (textwrap .dedent (doc .split ("\n " , 5 )[- 1 ]), indentation )
697+
693698 params_start_idx = doc .find (' Parameters\n ----------' )
694699 doc = doc [params_start_idx :]
695- doc = gp_regr_doc_start + " " + doc
700+ doc = gp_regr_doc_start + doc
696701
697- pattern = re .compile (r'(\n\s+)(module .*\n)(\s.+){1,99}' )
702+ pattern = re .compile (r'(\n\s+)(module .*\n)(\s.+|. ){1,99}' )
698703 start , end = pattern .search (doc ).span ()
699704 doc = doc [:start ] + gp_regr_module_text + doc [end :]
700705
701- pattern = re .compile (r'(\n\s+)(criterion .*\n)(\s.+){1,99}' )
706+ pattern = re .compile (r'(\n\s+)(criterion .*\n)(\s.+|. ){1,99}' )
702707 start , end = pattern .search (doc ).span ()
703708 doc = doc [:start ] + gp_regr_criterion_text + doc [end :]
704709
705- pattern = re .compile (r'(\n\s+)(train_split .*\n)(\s.+){1,99}' )
710+ pattern = re .compile (r'(\n\s+)(train_split .*\n)(\s.+|. ){1,99}' )
706711 start , end = pattern .search (doc ).span ()
707712 doc = doc [:start ] + gp_regr_train_split_text + doc [end :]
708713
@@ -744,7 +749,6 @@ def __init__(
744749 Module : gpytorch.models.ApproximateGP (class or instance)
745750 The GPyTorch module; in contrast to exact GP, the return distribution does
746751 not need to be Gaussian.
747-
748752"""
749753
750754gp_binary_clf_criterion_text = """
@@ -756,21 +760,26 @@ def __init__(
756760 criterion : gpytorch.mlls.VariationalELBO
757761 The objective function to learn the approximate posterior of of the GP
758762 binary classification.
759-
760763"""
761764
762765
763766def get_gp_binary_clf_doc (doc ):
764767 """Customizes the net docs to avoid duplication."""
768+ # dedent/indent roundtrip required for consistent indention in both
769+ # Python <3.13 and Python >=3.13
770+ # Because <3.13 => no automatic dedent, but it is the case in >=3.13
771+ indentation = " "
772+ doc = textwrap .indent (textwrap .dedent (doc .split ("\n " , 5 )[- 1 ]), indentation )
773+
765774 params_start_idx = doc .find (' Parameters\n ----------' )
766775 doc = doc [params_start_idx :]
767- doc = gp_binary_clf_doc_start + " " + doc
776+ doc = gp_binary_clf_doc_start + doc
768777
769- pattern = re .compile (r'(\n\s+)(module .*\n)(\s.+){1,99}' )
778+ pattern = re .compile (r'(\n\s+)(module .*\n)(\s.+|. ){1,99}' )
770779 start , end = pattern .search (doc ).span ()
771780 doc = doc [:start ] + gp_binary_clf_module_text + doc [end :]
772781
773- pattern = re .compile (r'(\n\s+)(criterion .*\n)(\s.+){1,99}' )
782+ pattern = re .compile (r'(\n\s+)(criterion .*\n)(\s.+|. ){1,99}' )
774783 start , end = pattern .search (doc ).span ()
775784 doc = doc [:start ] + gp_binary_clf_criterion_text + doc [end :]
776785
0 commit comments