phylogenie 1.0.2__py3-none-any.whl → 1.0.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- from typing import Any, overload
1
+ from typing import Any, Literal, overload
2
2
 
3
3
  import numpy as np
4
4
 
@@ -23,10 +23,9 @@ def _eval_expression(expression: str, data: pgt.Data) -> Any:
23
23
  expression,
24
24
  {
25
25
  "__builtins__": __builtins__,
26
- # "np": np,
27
- # **{k: np.array(v) for k, v in data.items()},
26
+ "np": np,
27
+ **{k: np.array(v) for k, v in data.items()},
28
28
  },
29
- {k: np.array(v) for k, v in data.items()},
30
29
  )
31
30
  ).tolist()
32
31
 
@@ -101,20 +100,17 @@ def skyline_parameter_like_factory(
101
100
  )
102
101
 
103
102
 
104
- from typing import Literal
105
-
106
-
107
103
  @overload
108
104
  def _parse_skyline_vector_value_model(
109
105
  x: cfg.SkylineVectorValueModel, data: pgt.Data, coercible: Literal[True]
110
- ) -> SkylineVector | SkylineParameter: ...
106
+ ) -> SkylineVectorCoercible: ...
111
107
  @overload
112
108
  def _parse_skyline_vector_value_model(
113
109
  x: cfg.SkylineVectorValueModel, data: pgt.Data, coercible: Literal[False]
114
- ) -> SkylineVector: ...
110
+ ) -> SkylineVectorLike: ...
115
111
  def _parse_skyline_vector_value_model(
116
112
  x: cfg.SkylineVectorValueModel, data: pgt.Data, coercible: bool
117
- ) -> SkylineVector | SkylineParameter:
113
+ ) -> SkylineVectorCoercible:
118
114
  change_times = many_scalars_factory(x.change_times, data)
119
115
  if isinstance(x.value, str):
120
116
  e = _eval_expression(x.value, data)
@@ -132,13 +128,13 @@ def _parse_skyline_vector_value_model(
132
128
  return SkylineParameter(value=value, change_times=change_times)
133
129
  else:
134
130
  raise ValueError(
135
- f"Parsing SkylineVector value {x.value} yielded a sequence of scalars ({value}) when a nested (2D) sequence of scalars was expected."
131
+ f"Parsing SkylineVector config {x.value} yielded a sequence of scalars {value} when a nested (2D) sequence of scalars was expected."
136
132
  )
137
133
 
138
134
  Ns = {len(elem) for elem in value if tg.is_many(elem)}
139
135
  if len(Ns) > 1:
140
136
  raise ValueError(
141
- f"All elements in the value of a SkylineVector config must be scalars or have the same length (got value={value} with inconsistent lengths {Ns})."
137
+ f"All elements in the value of a SkylineVector config must be scalars or have the same length (config {x.value} yielded value={value} with inconsistent lengths {Ns})."
142
138
  )
143
139
  (N,) = Ns
144
140
  value = [[p] * N if isinstance(p, pgt.Scalar) else p for p in value]
@@ -238,13 +234,13 @@ def skyline_matrix_coercible_factory(
238
234
  n_rows = len(elem)
239
235
  if any(len(row) != n_rows for row in elem):
240
236
  raise ValueError(
241
- f"All elements in the value of a SkylineMatrix config must be scalars or square matrices (got non-square matrix: {elem})."
237
+ f"All elements in the value of a SkylineMatrix config must be scalars or square matrices (config {x.value} yeilded a non-square matrix: {elem})."
242
238
  )
243
239
  Ns.add(n_rows)
244
240
 
245
241
  if len(Ns) > 1:
246
242
  raise ValueError(
247
- f"All elements in the value of a SkylineMatrix config must be scalars or have the same square shape (got value={value} with inconsistent lengths {Ns})."
243
+ f"All elements in the value of a SkylineMatrix config must be scalars or have the same square shape (config {x.value} yielded value={value} with inconsistent lengths {Ns})."
248
244
  )
249
245
  (N,) = Ns
250
246
  value = [[[p] * N] * N if isinstance(p, pgt.Scalar) else p for p in value]
@@ -80,7 +80,7 @@ class SkylineMatrix:
80
80
  def get_value_at_time(self, time: pgt.Scalar) -> pgt.Vector2D:
81
81
  return [param.get_value_at_time(time) for param in self.params]
82
82
 
83
- def operate(
83
+ def _operate(
84
84
  self,
85
85
  other: SkylineMatrixOperand,
86
86
  func: Callable[
@@ -97,28 +97,28 @@ class SkylineMatrix:
97
97
  )
98
98
 
99
99
  def __add__(self, operand: SkylineMatrixOperand) -> "SkylineMatrix":
100
- return self.operate(operand, lambda x, y: x + y)
100
+ return self._operate(operand, lambda x, y: x + y)
101
101
 
102
102
  def __radd__(self, operand: SkylineVectorOperand) -> "SkylineMatrix":
103
- return self.operate(operand, lambda x, y: y + x)
103
+ return self._operate(operand, lambda x, y: y + x)
104
104
 
105
105
  def __sub__(self, operand: SkylineMatrixOperand) -> "SkylineMatrix":
106
- return self.operate(operand, lambda x, y: x - y)
106
+ return self._operate(operand, lambda x, y: x - y)
107
107
 
108
108
  def __rsub__(self, operand: SkylineVectorOperand) -> "SkylineMatrix":
109
- return self.operate(operand, lambda x, y: y - x)
109
+ return self._operate(operand, lambda x, y: y - x)
110
110
 
111
111
  def __mul__(self, operand: SkylineMatrixOperand) -> "SkylineMatrix":
112
- return self.operate(operand, lambda x, y: x * y)
112
+ return self._operate(operand, lambda x, y: x * y)
113
113
 
114
114
  def __rmul__(self, operand: SkylineVectorOperand) -> "SkylineMatrix":
115
- return self.operate(operand, lambda x, y: y * x)
115
+ return self._operate(operand, lambda x, y: y * x)
116
116
 
117
117
  def __truediv__(self, operand: SkylineMatrixOperand) -> "SkylineMatrix":
118
- return self.operate(operand, lambda x, y: x / y)
118
+ return self._operate(operand, lambda x, y: x / y)
119
119
 
120
120
  def __rtruediv__(self, operand: SkylineVectorOperand) -> "SkylineMatrix":
121
- return self.operate(operand, lambda x, y: y / x)
121
+ return self._operate(operand, lambda x, y: y / x)
122
122
 
123
123
  @property
124
124
  def T(self) -> "SkylineMatrix":
@@ -23,7 +23,7 @@ class SkylineParameter:
23
23
  self,
24
24
  value: pgt.OneOrManyScalars,
25
25
  change_times: pgt.ManyScalars | None = None,
26
- ) -> None:
26
+ ):
27
27
  if isinstance(value, pgt.Scalar):
28
28
  value = [value]
29
29
  elif not tg.is_many_scalars(value):
@@ -42,18 +42,29 @@ class SkylineParameter:
42
42
  raise ValueError(
43
43
  f"`value` must have exactly one more element than `change_times` (got value={value} of length {len(value)} and change_times={change_times} of length {len(change_times)})."
44
44
  )
45
+ if any(t1 >= t2 for t1, t2 in zip(change_times, change_times[1:])):
46
+ raise ValueError(
47
+ f"`change_times` must be sorted in strictly increasing order "
48
+ f"(got change_times={change_times})."
49
+ )
50
+ if any(t < 0 for t in change_times):
51
+ raise ValueError(
52
+ f"`change_times` must be non-negative (got change_times={change_times})."
53
+ )
45
54
 
46
55
  self.value = [value[0]]
47
56
  self.change_times: list[pgt.Scalar] = []
48
57
  for i in range(1, len(value)):
49
58
  if value[i] != value[i - 1]:
50
59
  self.value.append(value[i])
51
- self.value.append(change_times[i - 1])
60
+ self.change_times.append(change_times[i - 1])
52
61
 
53
62
  def get_value_at_time(self, t: pgt.Scalar) -> pgt.Scalar:
63
+ if t < 0:
64
+ raise ValueError(f"Time cannot be negative (got t={t}).")
54
65
  return self.value[bisect_right(self.change_times, t)]
55
66
 
56
- def operate(
67
+ def _operate(
57
68
  self,
58
69
  other: SkylineParameterLike,
59
70
  f: Callable[[pgt.Scalar, pgt.Scalar], pgt.Scalar],
@@ -67,28 +78,28 @@ class SkylineParameter:
67
78
  return SkylineParameter(value, change_times)
68
79
 
69
80
  def __add__(self, other: SkylineParameterLike) -> "SkylineParameter":
70
- return self.operate(other, lambda x, y: x + y)
81
+ return self._operate(other, lambda x, y: x + y)
71
82
 
72
83
  def __radd__(self, other: pgt.Scalar) -> "SkylineParameter":
73
- return self.operate(other, lambda x, y: y + x)
84
+ return self._operate(other, lambda x, y: y + x)
74
85
 
75
86
  def __sub__(self, other: SkylineParameterLike) -> "SkylineParameter":
76
- return self.operate(other, lambda x, y: x - y)
87
+ return self._operate(other, lambda x, y: x - y)
77
88
 
78
89
  def __rsub__(self, other: pgt.Scalar) -> "SkylineParameter":
79
- return self.operate(other, lambda x, y: y - x)
90
+ return self._operate(other, lambda x, y: y - x)
80
91
 
81
92
  def __mul__(self, other: SkylineParameterLike) -> "SkylineParameter":
82
- return self.operate(other, lambda x, y: x * y)
93
+ return self._operate(other, lambda x, y: x * y)
83
94
 
84
95
  def __rmul__(self, other: pgt.Scalar) -> "SkylineParameter":
85
- return self.operate(other, lambda x, y: y * x)
96
+ return self._operate(other, lambda x, y: y * x)
86
97
 
87
98
  def __truediv__(self, other: SkylineParameterLike) -> "SkylineParameter":
88
- return self.operate(other, lambda x, y: x / y)
99
+ return self._operate(other, lambda x, y: x / y)
89
100
 
90
101
  def __rtruediv__(self, other: pgt.Scalar) -> "SkylineParameter":
91
- return self.operate(other, lambda x, y: y / x)
102
+ return self._operate(other, lambda x, y: y / x)
92
103
 
93
104
  def __bool__(self) -> bool:
94
105
  return any(self.value)
@@ -34,7 +34,7 @@ class SkylineVector:
34
34
  params: pgt.Many[SkylineParameterLike] | None = None,
35
35
  value: pgt.Many2DScalars | None = None,
36
36
  change_times: pgt.ManyScalars | None = None,
37
- ) -> None:
37
+ ):
38
38
  if params is not None and value is None and change_times is None:
39
39
  if is_many_skyline_parameters_like(params):
40
40
  self.params = [skyline_parameter(param) for param in params]
@@ -77,7 +77,7 @@ class SkylineVector:
77
77
  def get_value_at_time(self, t: pgt.Scalar) -> pgt.Vector1D:
78
78
  return [param.get_value_at_time(t) for param in self.params]
79
79
 
80
- def operate(
80
+ def _operate(
81
81
  self,
82
82
  other: SkylineVectorOperand,
83
83
  func: Callable[[SkylineParameter, SkylineParameter], SkylineParameter],
@@ -90,28 +90,28 @@ class SkylineVector:
90
90
  )
91
91
 
92
92
  def __add__(self, operand: SkylineVectorOperand) -> "SkylineVector":
93
- return self.operate(operand, lambda x, y: x + y)
93
+ return self._operate(operand, lambda x, y: x + y)
94
94
 
95
95
  def __radd__(self, operand: SkylineParameterLike) -> "SkylineVector":
96
- return self.operate(operand, lambda x, y: y + x)
96
+ return self._operate(operand, lambda x, y: y + x)
97
97
 
98
98
  def __sub__(self, operand: SkylineVectorOperand) -> "SkylineVector":
99
- return self.operate(operand, lambda x, y: x - y)
99
+ return self._operate(operand, lambda x, y: x - y)
100
100
 
101
101
  def __rsub__(self, operand: SkylineParameterLike) -> "SkylineVector":
102
- return self.operate(operand, lambda x, y: y - x)
102
+ return self._operate(operand, lambda x, y: y - x)
103
103
 
104
104
  def __mul__(self, operand: SkylineVectorOperand) -> "SkylineVector":
105
- return self.operate(operand, lambda x, y: x * y)
105
+ return self._operate(operand, lambda x, y: x * y)
106
106
 
107
107
  def __rmul__(self, operand: SkylineParameterLike) -> "SkylineVector":
108
- return self.operate(operand, lambda x, y: y * x)
108
+ return self._operate(operand, lambda x, y: y * x)
109
109
 
110
110
  def __truediv__(self, operand: SkylineVectorOperand) -> "SkylineVector":
111
- return self.operate(operand, lambda x, y: x / y)
111
+ return self._operate(operand, lambda x, y: x / y)
112
112
 
113
113
  def __rtruediv__(self, operand: SkylineParameterLike) -> "SkylineVector":
114
- return self.operate(operand, lambda x, y: y / x)
114
+ return self._operate(operand, lambda x, y: y / x)
115
115
 
116
116
  def __len__(self) -> int:
117
117
  return self.N
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: phylogenie
3
- Version: 1.0.2
3
+ Version: 1.0.4
4
4
  Summary: Generate phylogenetic datasets with minimal setup effort
5
5
  Author: Gabriele Marino
6
6
  Author-email: gabmarino.8601@gmail.com
@@ -12,7 +12,7 @@ phylogenie/core/context/configs.py,sha256=zd-ADFzJbb6KPkol-tXxSdS8LUBeQYQq8fDzXo
12
12
  phylogenie/core/context/distributions.py,sha256=QF14tM2ibjE7f6WK3s4hTaz_sLQBTNVr2ZBNe2refeE,3059
13
13
  phylogenie/core/context/factories.py,sha256=QO96wZwrQbgX2Rkd0wY3qQDahiZ8fDg8Mg8KKY0lr2c,1390
14
14
  phylogenie/core/dataset.py,sha256=mgPAexXTat6x7YB9-BI6d5HWwrAvt8xydmiWVzwVD3M,2431
15
- phylogenie/core/factories.py,sha256=1ZXGWV8kWn-LZjb5dFk4LrWNtyhLGyH7jQ0DuuVjWN0,8912
15
+ phylogenie/core/factories.py,sha256=Ph9qlQ6AthVKbzQZvvzj6EQye5LS2nl6d_r2dFuBfEo,8881
16
16
  phylogenie/core/msas/__init__.py,sha256=-2XjTmiTA6zAwiLs2ksKecCrSbNLheo7KKjDyvuLipg,207
17
17
  phylogenie/core/msas/alisim.py,sha256=TG4LAHJaH3rGWa3cwXzX6MgaXuh2tLzhdoALyOkoiXY,1047
18
18
  phylogenie/core/msas/base.py,sha256=cKH0FGALmObmOLZ2dJ3vrpb3jTLg2oeWJsIE6HznJ0Q,1803
@@ -27,13 +27,13 @@ phylogenie/core/typeguards.py,sha256=yxTdE4G_1gjBFqplyei-GKz4KZo2KFh8qsEsPQ2Z5OQ
27
27
  phylogenie/main.py,sha256=n_joau3dWJIq0ZMHe4a_1_2GigTFagkfzUFuQEMlyRI,1158
28
28
  phylogenie/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
29
29
  phylogenie/skyline/__init__.py,sha256=7pF4CUb4ZCLzNYJNhOjpuTOLTRhlK7L6ugfccNqjIGo,620
30
- phylogenie/skyline/matrix.py,sha256=WH1aT23hv4QYuH4GDwcJgahrqcgB4mulfzKLGUx3R6M,7091
31
- phylogenie/skyline/parameter.py,sha256=wrtvQDho3OC5tzrMnnFTy95GXaYN20KN8P5Gwyf-rHI,4023
32
- phylogenie/skyline/vector.py,sha256=NgmVbWjWG_itZ9a57q9QqSybvG9-Cr9X264RGPVyp_Q,6399
30
+ phylogenie/skyline/matrix.py,sha256=8C8jFmIFbxYWmmfnPwi6qaew4oErQznvZN8JuvkD8kQ,7100
31
+ phylogenie/skyline/parameter.py,sha256=RXZoaC46FFGTjD8rNb0dkWAZH4Pfxfn2dFGID3l0dMs,4551
32
+ phylogenie/skyline/vector.py,sha256=VuCnIq9aIlKZIiqHWIbrpiOdwSDKXNPuIPunlULaYaQ,6400
33
33
  phylogenie/typeguards.py,sha256=WBOSJSaOC8VDtrYoA2w_AYEXTpyKdCfmsM29KaKXl3A,1350
34
34
  phylogenie/typings.py,sha256=93VRedBxrpzXkT4uaNu_1JiMzsOjp7fUy4kLv_eYxUE,565
35
- phylogenie-1.0.2.dist-info/LICENSE.txt,sha256=NUrDqElK-eD3I0WqC004CJsy6cs0JgsAoebDv_42-pw,1071
36
- phylogenie-1.0.2.dist-info/METADATA,sha256=5RcgFLDSlV90GTGBblQdur97pV2C0drYMg_EGKytHD8,6251
37
- phylogenie-1.0.2.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
38
- phylogenie-1.0.2.dist-info/entry_points.txt,sha256=Rt6_usN0FkBX1ZfiqCirjMN9FKOgFLG8rydcQ8kugeE,51
39
- phylogenie-1.0.2.dist-info/RECORD,,
35
+ phylogenie-1.0.4.dist-info/LICENSE.txt,sha256=NUrDqElK-eD3I0WqC004CJsy6cs0JgsAoebDv_42-pw,1071
36
+ phylogenie-1.0.4.dist-info/METADATA,sha256=Ly88IxdRijacsz4-TglRG5GbjjcDkxQxLf5U0kLEj-c,6251
37
+ phylogenie-1.0.4.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
38
+ phylogenie-1.0.4.dist-info/entry_points.txt,sha256=Rt6_usN0FkBX1ZfiqCirjMN9FKOgFLG8rydcQ8kugeE,51
39
+ phylogenie-1.0.4.dist-info/RECORD,,