dycw-utilities 0.109.16__py3-none-any.whl → 0.109.17__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.
- {dycw_utilities-0.109.16.dist-info → dycw_utilities-0.109.17.dist-info}/METADATA +1 -1
- {dycw_utilities-0.109.16.dist-info → dycw_utilities-0.109.17.dist-info}/RECORD +6 -6
- utilities/__init__.py +1 -1
- utilities/numpy.py +89 -0
- {dycw_utilities-0.109.16.dist-info → dycw_utilities-0.109.17.dist-info}/WHEEL +0 -0
- {dycw_utilities-0.109.16.dist-info → dycw_utilities-0.109.17.dist-info}/licenses/LICENSE +0 -0
@@ -1,4 +1,4 @@
|
|
1
|
-
utilities/__init__.py,sha256=
|
1
|
+
utilities/__init__.py,sha256=9W0BorEWmH8eCgNBXgx9zWKa3BNPPP1rlZfrx6qGCio,61
|
2
2
|
utilities/altair.py,sha256=Gpja-flOo-Db0PIPJLJsgzAlXWoKUjPU1qY-DQ829ek,9156
|
3
3
|
utilities/astor.py,sha256=xuDUkjq0-b6fhtwjhbnebzbqQZAjMSHR1IIS5uOodVg,777
|
4
4
|
utilities/asyncio.py,sha256=41oQUurWMvadFK5gFnaG21hMM0Vmfn2WS6OpC0R9mas,14757
|
@@ -36,7 +36,7 @@ utilities/math.py,sha256=TexfvLCI12d9Sw5_W4pKVBZ3nRr3zk2iPkcEU7xdEWU,26771
|
|
36
36
|
utilities/memory_profiler.py,sha256=tf2C51P2lCujPGvRt2Rfc7VEw5LDXmVPCG3z_AvBmbU,962
|
37
37
|
utilities/modules.py,sha256=SnhsRHRUS1po_acejrINauihGQpPvVsp8RDNCei1OLQ,3173
|
38
38
|
utilities/more_itertools.py,sha256=CPUxrMAcTwRxbzbhiqPKi3Xx9hxqI0t6gkWjutaibGk,5534
|
39
|
-
utilities/numpy.py,sha256
|
39
|
+
utilities/numpy.py,sha256=XMOaauVbssv_yrS1FdSnPExht3G4P8nAALmQsqHwp7w,25143
|
40
40
|
utilities/operator.py,sha256=0M2yZJ0PODH47ogFEnkGMBe_cfxwZR02T_92LZVZvHo,3715
|
41
41
|
utilities/optuna.py,sha256=loyJGWTzljgdJaoLhP09PT8Jz6o_pwBOwehY33lHkhw,1923
|
42
42
|
utilities/orjson.py,sha256=Wj5pzG_VdgoAy14a7Luhem-BgYrRtRFvvl_POiszRd0,36930
|
@@ -86,7 +86,7 @@ utilities/warnings.py,sha256=yUgjnmkCRf6QhdyAXzl7u0qQFejhQG3PrjoSwxpbHrs,1819
|
|
86
86
|
utilities/whenever.py,sha256=TjoTAJ1R27-rKXiXzdE4GzPidmYqm0W58XydDXp-QZM,17786
|
87
87
|
utilities/zipfile.py,sha256=24lQc9ATcJxHXBPc_tBDiJk48pWyRrlxO2fIsFxU0A8,699
|
88
88
|
utilities/zoneinfo.py,sha256=-DQz5a0Ikw9jfSZtL0BEQkXOMC9yGn_xiJYNCLMiqEc,1989
|
89
|
-
dycw_utilities-0.109.
|
90
|
-
dycw_utilities-0.109.
|
91
|
-
dycw_utilities-0.109.
|
92
|
-
dycw_utilities-0.109.
|
89
|
+
dycw_utilities-0.109.17.dist-info/METADATA,sha256=9BOdlf6JtDA2hK4ElsW-HsjxWLvub9HUqc1ds9r2CkY,13005
|
90
|
+
dycw_utilities-0.109.17.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
91
|
+
dycw_utilities-0.109.17.dist-info/licenses/LICENSE,sha256=gppZp16M6nSVpBbUBrNL6JuYfvKwZiKgV7XoKKsHzqo,1066
|
92
|
+
dycw_utilities-0.109.17.dist-info/RECORD,,
|
utilities/__init__.py
CHANGED
utilities/numpy.py
CHANGED
@@ -14,6 +14,7 @@ from numpy import (
|
|
14
14
|
digitize,
|
15
15
|
dtype,
|
16
16
|
errstate,
|
17
|
+
exp,
|
17
18
|
flatnonzero,
|
18
19
|
float64,
|
19
20
|
floating,
|
@@ -133,6 +134,65 @@ class AsIntError(Exception): ...
|
|
133
134
|
##
|
134
135
|
|
135
136
|
|
137
|
+
def boxcar(
|
138
|
+
array: NDArray[floating[Any]],
|
139
|
+
/,
|
140
|
+
*,
|
141
|
+
loc_low: float = -1.0,
|
142
|
+
slope_low: float = 1.0,
|
143
|
+
loc_high: float = 1.0,
|
144
|
+
slope_high: float = 1.0,
|
145
|
+
rtol: float | None = None,
|
146
|
+
atol: float | None = None,
|
147
|
+
) -> NDArray[floating[Any]]:
|
148
|
+
"""Construct a boxcar function."""
|
149
|
+
if not is_at_most(loc_low, loc_high, rtol=rtol, atol=atol):
|
150
|
+
raise _BoxCarLocationsError(low=loc_low, high=loc_high)
|
151
|
+
if not is_positive(slope_low, rtol=rtol, atol=atol):
|
152
|
+
raise _BoxCarLowerBoundSlopeError(slope=slope_low)
|
153
|
+
if not is_positive(slope_high, rtol=rtol, atol=atol):
|
154
|
+
raise _BoxCarUpperBoundSlopeError(slope=slope_high)
|
155
|
+
return (
|
156
|
+
sigmoid(array, loc=loc_low, slope=slope_low)
|
157
|
+
+ sigmoid(array, loc=loc_high, slope=-slope_high)
|
158
|
+
) / 2
|
159
|
+
|
160
|
+
|
161
|
+
@dataclass(kw_only=True, slots=True)
|
162
|
+
class BoxCarError(Exception): ...
|
163
|
+
|
164
|
+
|
165
|
+
@dataclass(kw_only=True, slots=True)
|
166
|
+
class _BoxCarLocationsError(BoxCarError):
|
167
|
+
low: float
|
168
|
+
high: float
|
169
|
+
|
170
|
+
@override
|
171
|
+
def __str__(self) -> str:
|
172
|
+
return f"Location parameters must be consistent; got {self.low} and {self.high}"
|
173
|
+
|
174
|
+
|
175
|
+
@dataclass(kw_only=True, slots=True)
|
176
|
+
class _BoxCarLowerBoundSlopeError(BoxCarError):
|
177
|
+
slope: float
|
178
|
+
|
179
|
+
@override
|
180
|
+
def __str__(self) -> str:
|
181
|
+
return f"Lower-bound slope parameter must be positive; got {self.slope}"
|
182
|
+
|
183
|
+
|
184
|
+
@dataclass(kw_only=True, slots=True)
|
185
|
+
class _BoxCarUpperBoundSlopeError(BoxCarError):
|
186
|
+
slope: float
|
187
|
+
|
188
|
+
@override
|
189
|
+
def __str__(self) -> str:
|
190
|
+
return f"Upper-bound slope parameter must be positive; got {self.slope}"
|
191
|
+
|
192
|
+
|
193
|
+
##
|
194
|
+
|
195
|
+
|
136
196
|
def discretize(x: NDArrayF, bins: int | Iterable[float], /) -> NDArrayF:
|
137
197
|
"""Discretize an array of floats.
|
138
198
|
|
@@ -847,6 +907,31 @@ def shift_bool(
|
|
847
907
|
##
|
848
908
|
|
849
909
|
|
910
|
+
def sigmoid(
|
911
|
+
array: NDArray[floating[Any]],
|
912
|
+
/,
|
913
|
+
*,
|
914
|
+
loc: float = 0.0,
|
915
|
+
slope: float = 1.0,
|
916
|
+
rtol: float | None = None,
|
917
|
+
atol: float | None = None,
|
918
|
+
) -> NDArray[floating[Any]]:
|
919
|
+
"""Construct a sigmoid function."""
|
920
|
+
if is_zero(slope, rtol=rtol, atol=atol):
|
921
|
+
raise SigmoidError
|
922
|
+
return 1 / (1 + exp(-slope * (array - loc)))
|
923
|
+
|
924
|
+
|
925
|
+
@dataclass(kw_only=True, slots=True)
|
926
|
+
class SigmoidError(Exception):
|
927
|
+
@override
|
928
|
+
def __str__(self) -> str:
|
929
|
+
return "Slope must be non-zero"
|
930
|
+
|
931
|
+
|
932
|
+
##
|
933
|
+
|
934
|
+
|
850
935
|
def _is_close(
|
851
936
|
x: Any,
|
852
937
|
y: Any,
|
@@ -869,6 +954,7 @@ def _is_close(
|
|
869
954
|
__all__ = [
|
870
955
|
"DEFAULT_RNG",
|
871
956
|
"AsIntError",
|
957
|
+
"BoxCarError",
|
872
958
|
"FlatN0EmptyError",
|
873
959
|
"FlatN0Error",
|
874
960
|
"FlatN0MultipleError",
|
@@ -878,8 +964,10 @@ __all__ = [
|
|
878
964
|
"NDArrayI",
|
879
965
|
"NDArrayO",
|
880
966
|
"ShiftError",
|
967
|
+
"SigmoidError",
|
881
968
|
"array_indexer",
|
882
969
|
"as_int",
|
970
|
+
"boxcar",
|
883
971
|
"datetime64D",
|
884
972
|
"datetime64M",
|
885
973
|
"datetime64W",
|
@@ -948,4 +1036,5 @@ __all__ = [
|
|
948
1036
|
"maximum",
|
949
1037
|
"minimum",
|
950
1038
|
"shift_bool",
|
1039
|
+
"sigmoid",
|
951
1040
|
]
|
File without changes
|
File without changes
|