Skip to content

Commit

Permalink
Ensure doctests are run. (#303)
Browse files Browse the repository at this point in the history
Previously because pytest was pointed only to the test directory, it would not find the doctests in clifford itself.
The only reason this was done was because the `docs` directory contains files that pytest crashes on.
Ignoring this directory makes everything work.

This fixes the doctests to pass.
  • Loading branch information
eric-wieser committed Apr 7, 2020
1 parent 8473631 commit cc1c6ee
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 34 deletions.
17 changes: 13 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ x-clifford-templates:
else
PYTEST_ARGS+=(-m "not veryslow");
fi;
if [[ "${MODE}" == "doctests" ]]; then
PYTEST_ARGS+=(--doctest-modules --ignore clifford/test);
fi;
pytest clifford/test \
pytest \
"${PYTEST_ARGS[@]}" \
--doctest-modules \
--junitxml=junit/test-results.xml \
--durations=25 \
--cov=clifford \
Expand Down Expand Up @@ -76,15 +78,22 @@ matrix:
stage: Lint
<<: *lint_job

# fastest job first
# fastest jobs first
- os: linux
python: '3.8'
env:
- NUMBA_DISABLE_JIT=1
stage: Test
<<: *test_job

# really slow job second, so it runs in parallel with the others
- os: linux
python: '3.8'
env:
- MODE=doctests
stage: Test
<<: *test_job

# really slow job next, so it runs in parallel with the others
- os: linux
python: '3.8'
env:
Expand Down
2 changes: 1 addition & 1 deletion clifford/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ def randomMV(
Examples
--------
>>> randomMV(layout, min=-2.0, max=2.0, grades=None, uniform=None, n=2)
>>> randomMV(layout, min=-2.0, max=2.0, grades=None, uniform=None, n=2) # doctest: +SKIP
"""

Expand Down
10 changes: 5 additions & 5 deletions clifford/_blademap.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ class BladeMap(object):
>>> P, P_blades = Cl(3, names='p')
>>> locals().update(P_blades)
>>> sta_split = BladeMap([(d01, p1),
(d02, p2),
(d03, p3),
(d12, p12),
(d23, p23),
(d13, p13)])
... (d02, p2),
... (d03, p3),
... (d12, p12),
... (d23, p23),
... (d13, p13)])
'''
def __init__(self, blades_map, map_scalars=True):
Expand Down
2 changes: 1 addition & 1 deletion clifford/_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ def bases(self, mvClass=MultiVector, grades: Optional[Container[int]] = None) ->
if you are lazy, you might do this to populate your namespace
with the variables of a given layout.
>>> locals().update(layout.blades())
>>> locals().update(layout.blades()) # doctest: +SKIP
.. versionchanged:: 1.1.0
This dictionary includes the scalar
Expand Down
8 changes: 4 additions & 4 deletions clifford/_layout_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ class BasisVectorIds(Generic[IdT]):
>>> ids = BasisVectorIds([11, 22, 33])
>>> ids.bitmap_as_tuple(0b110)
(22, 33)
>>> ids.tuple_as_sign_and_bitmap((33, 22))
(-1, 0b110)
>>> sign, bitmap = ids.tuple_as_sign_and_bitmap((33, 22))
>>> assert sign, bitmap == (-1, 0b110)
"""
def __init__(self, blade_ids: Sequence[IdT]):
if not _is_unique(blade_ids):
Expand Down Expand Up @@ -186,7 +186,7 @@ def order_from_tuples(self, blades: Sequence[Tuple[IdT]]) -> BasisBladeOrder:
This is the inverse of :meth:`order_as_tuples`.
>>> ids = BasisVectorIds(['x', 'y'])
>>> ids.order_from_tuples([(), ('y'), ('x', 'y'), ('x')])
>>> ids.order_from_tuples([(), ('y',), ('x', 'y'), ('x',)])
BasisBladeOrder([0b00, 0b10, 0b11, 0b01])
"""
bitmaps = []
Expand All @@ -208,7 +208,7 @@ def order_as_tuples(self, ordering: BasisBladeOrder) -> List[Tuple[IdT]]:
>>> ids = BasisVectorIds(['x', 'y'])
>>> ids.order_as_tuples(BasisBladeOrder([0b00, 0b10, 0b11, 0b01]))
[(), ('y'), ('x', 'y'), ('x')])
[(), ('y',), ('x', 'y'), ('x',)]
"""
return [self.bitmap_as_tuple(b) for b in ordering.index_to_bitmap]

Expand Down
4 changes: 4 additions & 0 deletions clifford/_multivector.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,12 @@ def __call__(self, other, *others) -> 'MultiVector':
Examples
--------
>>> from clifford.g2 import *
>>> M = 1 + 2*e1 + 3*e12
>>> M(0)
1
>>> M(0, 2)
1 + (3^e12)
"""
if isinstance(other, MultiVector):
return other.project(self)
Expand Down
3 changes: 2 additions & 1 deletion clifford/_mvarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ def array(obj):
>>> import clifford as cf
>>> from clifford import g3
>>> import numpy as np
>>> np.random.rand(10)*cf.array(g3.e12)
>>> np.array([1, 2, 3])*cf.array(g3.e12)
MVArray([(1^e12), (2^e12), (3^e12)], dtype=object)
'''
if isinstance(obj, MultiVector):
# they passed a single MV so make a list of it.
Expand Down
28 changes: 23 additions & 5 deletions clifford/cga.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
-----------
>>> from clifford import Cl
>>> from clifford.cga import CGA
>>> g3, blades = Cl(3)
>>> g3, blades = Cl(3)
>>> locals().update(blades)
>>> g3c = CGA(g3)
>>> C = g3c.round(3) # create random sphere
>>> T = g3c.translation(e1+e2) # create translation
>>> C_ = T(C) # translate the sphere
>>> C_.center # compute center of sphere
-(1.0^e4) - (1.0^e5)
The CGA
========
Expand Down Expand Up @@ -142,10 +144,12 @@ class Flat(CGAThing):
Examples
----------
>>> cga.flat() # from None
>>> cga.flat(2) # from dim of space
>>> cga.flat(e1, e2) # from points
>>> cga.flat(cga.flat().mv) # from existing multivector
>>> cga = CGA(3)
>>> locals().update(cga.blades)
>>> F = cga.flat() # from None
>>> F = cga.flat(2) # from dim of space
>>> F = cga.flat(e1, e2) # from points
>>> F = cga.flat(cga.flat().mv) # from existing multivector
'''
# could inherent some generic CGAObject class
def __init__(self, cga, *args) -> None:
Expand Down Expand Up @@ -206,10 +210,16 @@ class Round(CGAThing):
Examples
----------
>>> cga = CGA(3)
>>> locals().update(cga.blades)
>>> cga.round() # from None
Sphere
>>> cga.round(2) # from dim of space
Sphere
>>> cga.round(e1, e2, -e1) # from points
Circle
>>> cga.round(cga.flat().mv) # from existing multivector
Sphere
'''
# could inherent some generic CGAObject class
def __init__(self, cga, *args) -> None:
Expand Down Expand Up @@ -323,6 +333,8 @@ class Translation(CGAThing):
Examples
----------
>>> cga = CGA(3)
>>> locals().update(cga.blades)
>>> T = cga.translation() # from None
>>> T = cga.translation(e1+e2) # from base vector
>>> T = cga.translation(cga.up(e1+e2)) # from null vector
Expand Down Expand Up @@ -366,6 +378,7 @@ class Dilation(CGAThing):
Examples
----------
>>> cga = CGA(3)
>>> D = cga.dilation() # from none
>>> D = cga.dilation(.4) # from number
'''
Expand Down Expand Up @@ -416,6 +429,8 @@ class Rotation(CGAThing):
Examples
----------
>>> cga = CGA(3)
>>> locals().update(cga.blades)
>>> R = cga.rotation() # from None
>>> R = cga.rotation(e12+e23) # from bivector
>>> R = cga.rotation(R.mv) # from bivector
Expand Down Expand Up @@ -480,9 +495,12 @@ class Transversion(Translation):
Examples
----------
>>> cga = CGA(3)
>>> locals().update(cga.blades)
>>> K = cga.transversion() # from None
>>> K = cga.transversion(e1+e2) # from base vector
>>> K = cga.transversion(cga.up(e1+e2)) # from null vector
>>> T = cga.translation()
>>> K = cga.transversion(T.mv) # from existing translation rotor
'''
def __init__(self, cga, *args) -> None:
Expand Down
5 changes: 3 additions & 2 deletions clifford/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
>>> import functools
>>> import clifford.operator
>>> Ms = [M1, M2, M3] # list of multivectors
>>> assert functools.reduce(clifford.operator.op, Ms) == M1 ^ M2 ^ M3
>>> from clifford.g3 import *
>>> Ms = [e1, e1 + e2, e2 + e3] # list of multivectors
>>> assert functools.reduce(clifford.operator.op, Ms) == Ms[0] ^ Ms[1] ^ Ms[2]
.. autofunction:: gp
Expand Down
12 changes: 6 additions & 6 deletions clifford/tools/classify.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
>>> from clifford.g3c import *
>>> Round(location=e1, direction=e1^e2, radius=1)
Circle(location=(1^e1), direction=(1^e12), radius=1)
>>> Round(location=e1, direction=e1^e2^e3, radius=1)
Sphere(location=(1^e1), direction=(1^e123), radius=1)
Circle(direction=(1^e12), location=(1^e1), radius=1)
>>> Round(direction=e1^e2^e3, location=e1, radius=1)
Sphere(direction=(1^e123), location=(1^e1), radius=1)
Aliased types
Expand Down Expand Up @@ -424,13 +424,13 @@ def classify(x) -> Blade:
>>> from clifford.g3c import *
>>> classify(e1)
DualFlat[1](location=0, direction=-(1.0^e23))
DualFlat[1](flat=Plane(direction=-(1.0^e23), location=0))
>>> classify(einf)
InfinitePoint(direction=1.0)
>>> classify(up(e1))
Point(location=(1.0^e1), direction=1.0)
Point(direction=1.0, location=(1.0^e1))
>>> classify(up(3*e1)^up(4*e2))
PointPair(direction=-(3.0^e1) + (4.0^e2), location=(1.5^e1) + (2.0^e2), radius=2.5)
Expand All @@ -445,7 +445,7 @@ def classify(x) -> Blade:
Tangent[2](direction=(1.0^e2), location=(1.0^e1))
# how the inheritance works
>>> Point.mro()
>>> Point.mro() # doctest: +SKIP
[Point, Tangent[1], Round[1], Blade[1], Tangent, Round, Blade, object]
The reverse of this operation is :attr:`Blade.mv`.
Expand Down
12 changes: 7 additions & 5 deletions clifford/transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,16 @@ class OutermorphismMatrix(LinearMatrix):
Applying it to some multivectors::
# the transformation we specified
>>> # the transformation we specified
>>> lt(e1), lt(e2), lt(e3)
((3^f3), (1^f1), (2^f2))
# the one deduced by outermorphism
>>> lt(e12), lt(e23), lt(e13)
>>> # the one deduced by outermorphism
>>> lt(e1^e2), lt(e2^e3), lt(e1^e3)
(-(3^f13), (2^f12), -(6^f23))
# and by distributivity
>>> lt(1 + e123)
>>> # and by distributivity
>>> lt(1 + (e1^e2^e3))
1 + (6^f123)
"""
Expand Down
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,5 @@ per-file-ignores =
[tool:pytest]
markers =
veryslow: mark a test as unreasonably slow (> 30s on travis)

norecursedirs = docs

0 comments on commit cc1c6ee

Please sign in to comment.