• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

peekxc / splex / 6566946791

18 Oct 2023 09:47PM UTC coverage: 82.528% (-2.2%) from 84.734%
6566946791

push

github

peekxc
Working on the abc for filtration types. I think I have a good idea of what a good wrapper type should implement. Started the Filtration abc, which going to be similar to a Sequence type mixed with a Set type, but have some additional constraints

58 of 58 new or added lines in 5 files covered. (100.0%)

666 of 807 relevant lines covered (82.53%)

2.48 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

41.67
/src/splex/filtrations/filter_abcs.py
1
# from abc import ABC
2
import abc
3✔
3
from collections.abc import Set
3✔
4
from typing import *
3✔
5
import sys
3✔
6
from more_itertools import nth
3✔
7
from ..meta import * 
3✔
8
from ..generics import * 
3✔
9
from ..Simplex import Simplex
3✔
10

11
class Filtration(ComplexLike):
3✔
12

13
  ## ---- Collection requirements -----
14
  @abstractmethod
3✔
15
  def __iter__(self) -> tuple[Any, SimplexConvertible]: 
3✔
16
    pass 
×
17

18
  @abstractmethod
3✔
19
  def __len__(self) -> int:
3✔
20
    pass 
×
21

22
  @abstractmethod
3✔
23
  def __contains__(self, k: SimplexConvertible) -> bool:
3✔
24
    pass 
×
25

26
  ## --- Sequence requirements ---
27
  def __getitem__(self, key: int) -> SimplexConvertible: 
3✔
28
    if len(self) <= key: 
×
29
      raise IndexError("index out of range")
×
30
    return nth(iter(self), key, None)
×
31

32
  def index(self, item: SimplexConvertible) -> int:  
3✔
33
    s = Simplex(item)
×
34
    for i,x in iter(self):
×
35
      if x == s:
×
36
        return i
×
37
    return -1  
×
38

39
  def count(self, item: SimplexConvertible) -> int: 
3✔
40
    s = Simplex(item)
×
41
    s_count = 0
×
42
    for i,x in iter(s):
×
43
      s_count += (x == s)
×
44
    return s_count
×
45
  
46
  ## --- Disable Mutable Sequence ---- 
47
  def __setitem__(self, key: Any, value: Any):
3✔
48
    raise TypeError("Object does not support item assignment")
×
49

50
  ## --- Misc utilities ---
51
  def __format__(self, format_spec = "default") -> str:
3✔
52
    from io import StringIO
×
53
    s = StringIO()
×
54
    self.print(file=s)
×
55
    res = s.getvalue()
×
56
    s.close()
×
57
    return res
×
58

59
  def __repr__(self) -> str:
3✔
60
    if len(self) == 0:
3✔
61
      return f"Empty filtration"
×
62
    d = dim(self)
3✔
63
    return f"{d}-d filtered complex with {card(self)}-simplices of dimension {tuple(range(d+1))}"
3✔
64

65
  def print(self, **kwargs) -> None:
3✔
66
    fv_s, fs_s = [], []
×
67
    for v in faces(self):
×
68
      k = v.value
×
69
      ks = len(str(v))
×
70
      fv_s.append(f"{str(k):<{ks}.{ks}}")
×
71
      fs_s.append(f"{str(v): <{ks}}")
×
72
      assert len(fv_s[-1]) == len(fs_s[-1])
×
73
    sym_le, sym_inc = (' ≤ ', ' ⊆ ') if sys.getdefaultencoding()[:3] == 'utf' else (' <= ', ' <= ') 
×
74
    print(repr(self), **kwargs)
×
75
    print("I: " + sym_le.join(fv_s[:5]) + sym_le + ' ... ' + sym_le + sym_le.join(fv_s[-2:]), **kwargs)
×
76
    print("S: " + sym_inc.join(fs_s[:5]) + sym_inc + ' ... ' + sym_inc + sym_inc.join(fs_s[-2:]), **kwargs)
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc