Skip to content

Commit fe7fb8d

Browse files
committed
lint: Fix pycodestyle
1 parent f242f3c commit fe7fb8d

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

src/sage/stats/distributions/discrete_gaussian_lattice.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
sage: a.parent()
2727
Ambient free module of rank 10 over the principal ideal domain Integer Ring
2828
"""
29-
#******************************************************************************
29+
# ******************************************************************************
3030
#
3131
# DGS - Discrete Gaussian Samplers
3232
#
@@ -56,7 +56,7 @@
5656
# The views and conclusions contained in the software and documentation are
5757
# those of the authors and should not be interpreted as representing official
5858
# policies, either expressed or implied, of the FreeBSD Project.
59-
#*****************************************************************************/
59+
# *****************************************************************************/
6060

6161
from sage.functions.log import exp
6262
from sage.rings.real_mpfr import RealField
@@ -283,7 +283,7 @@ def f_or_hat(x):
283283
# is essentially the same, but I can't figure out how to
284284
# tweak the `.qfrep` call below correctly.
285285
from warnings import warn
286-
warn("Note: `_normalisation_factor_zz` has not been properly "\
286+
warn("Note: `_normalisation_factor_zz` has not been properly "
287287
"implemented for non-spherical distributions.")
288288
import itertools
289289
from sage.functions.log import log
@@ -415,7 +415,7 @@ def __init__(self, B, sigma=1, c=0, r=None, precision=None, sigma_basis=False):
415415
- ``precision`` -- bit precision `≥ 53`.
416416
417417
- ``sigma_basis`` -- (default: False) When set, ``sigma`` is treated as
418-
a basis, i.e. the covariance matrix is computed by ``Σ = SSᵀ``.
418+
a (row) basis, i.e. the covariance matrix is computed by ``Σ = SSᵀ``.
419419
420420
EXAMPLES::
421421
@@ -461,6 +461,16 @@ def __init__(self, B, sigma=1, c=0, r=None, precision=None, sigma_basis=False):
461461
sage: while v not in counter: add_samples(1000)
462462
sage: while abs(m*f(v)*1.0/nf/counter[v] - 1.0) >= 0.1: add_samples(1000)
463463
464+
The sampler supports passing a basis for the covariance.
465+
466+
sage: n = 3
467+
sage: S = Matrix(ZZ, [[2, 0, 0], [-1, 3, 0], [2, -1, 1]])
468+
sage: D = DGL(ZZ^n, S, sigma_basis=True)
469+
sage: D.sigma
470+
[ 4.00000000000000 -2.00000000000000 4.00000000000000]
471+
[-2.00000000000000 10.0000000000000 -5.00000000000000]
472+
[ 4.00000000000000 -5.00000000000000 6.00000000000000]
473+
464474
The non-spherical sampler supports offline computation to speed up
465475
sampling. This will be useful when changing the center `c` is supported.
466476
The difference is more significant for larger matrices. For 128x128 we
@@ -499,6 +509,8 @@ def __init__(self, B, sigma=1, c=0, r=None, precision=None, sigma_basis=False):
499509
if self.sigma == self.sigma[0, 0]:
500510
self.sigma = self._RR(self.sigma[0, 0])
501511
else:
512+
if sigma_basis:
513+
self.sigma = self.sigma * self.sigma.T
502514
if not self.sigma.is_positive_definite():
503515
raise RuntimeError(f"Sigma(={self._sigma}) is not positive definite")
504516
self.is_spherical = False
@@ -574,12 +586,10 @@ def _precompute_data(self):
574586
self.B2 = Sigma2.cholesky().T
575587
self.B2_B_inv = self.B2 * self.B_inv
576588
except ValueError:
577-
raise ValueError("Σ₂ is not positive definite. Is your "\
578-
f"r(={self.r}) too large? It should be at most "\
589+
raise ValueError("Σ₂ is not positive definite. Is your "
590+
f"r(={self.r}) too large? It should be at most "
579591
f"{self._maximal_r()}")
580592

581-
582-
583593
def __call__(self):
584594
r"""
585595
Return a new sample.
@@ -724,7 +734,6 @@ def c(self, c):
724734
self._c = c
725735
self._precompute_data()
726736

727-
728737
def __repr__(self):
729738
r"""
730739
EXAMPLES::
@@ -754,7 +763,6 @@ def __repr__(self):
754763
sigma_str = f"Σ =\n{self._sigma}"
755764
return f"Discrete Gaussian sampler with Gaussian parameter {sigma_str}, c={self.c} over lattice with basis\n\n{self.B}"
756765

757-
758766
def _call_in_lattice(self):
759767
r"""
760768
Return a new sample assuming `c ∈ Λ(B)`.
@@ -807,7 +815,6 @@ def _call(self):
807815
v = v + z * B[i]
808816
return v
809817

810-
811818
def add_offline_samples(self, cnt=1):
812819
"""
813820
Precompute samples from B⁻¹D₁ to be used in :meth:`_call_non_spherical`

src/sage/stats/distributions/discrete_gaussian_polynomial.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
(24.0, 24.0)
2424
2525
"""
26-
#******************************************************************************
26+
# ******************************************************************************
2727
#
2828
# DGS - Discrete Gaussian Samplers
2929
#
@@ -53,7 +53,7 @@
5353
# The views and conclusions contained in the software and documentation are
5454
# those of the authors and should not be interpreted as representing official
5555
# policies, either expressed or implied, of the FreeBSD Project.
56-
#*****************************************************************************/
56+
# *****************************************************************************/
5757

5858
from sage.rings.real_mpfr import RR
5959
from sage.rings.integer_ring import ZZ

0 commit comments

Comments
 (0)