Skip to content

Commit 68279d9

Browse files
committed
...
1 parent d758f2a commit 68279d9

2 files changed

Lines changed: 2 additions & 270 deletions

File tree

README.md

Lines changed: 2 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -61,34 +61,7 @@ When working with `Itr`, keep these points in mind:
6161

6262
`Itr` provides a comprehensive set of methods for various iterable operations. For a complete list of methods and their detailed descriptions, please refer to the [full documentation](autodoc.md).
6363

64-
*Note: The detailed list of methods in `autodoc.md` is automatically generated by [introspect.py], where `Itr` introspects itself.*
65-
66-
```py introspect.py
67-
from operator import add
68-
69-
from itr import Itr
70-
71-
# use Itr to introspect itself for methods and their docstrings
72-
methods = (
73-
Itr(dir(Itr))
74-
.filter(lambda m: m in ("__init__", "__iter__", "__next__") or not m.startswith("_"))
75-
.map(lambda m: (m, getattr(Itr, m).__doc__))
76-
.collect(dict)
77-
)
78-
79-
# use Itr to make some documentation
80-
method_template = """
81-
### `{method_name}`
82-
83-
{method_doc}
84-
"""
85-
86-
with open("doc/autodoc.md", "w") as fd:
87-
fd.write("# `Itr` class documentation\n")
88-
fd.write(Itr.__doc__ or "")
89-
fd.write("## Public methods\n")
90-
fd.write(Itr(methods.items()).map(lambda m: method_template.format(method_name=m[0], method_doc=m[1])).reduce(add))
91-
```
64+
*Note: The detailed list of methods in `autodoc.md` is automatically generated by [introspect.py](src/scripts/introspect.py), where `Itr` introspects itself.*
9265

9366
## Examples
9467

@@ -163,52 +136,4 @@ For reference, an equivalent using `itertools` directly:
163136

164137
### More examples
165138

166-
More examples can be found [here](./doc/examples.md).
167-
168-
169-
170-
171-
172-
Beyond basic transformations, `Itr` enables powerful composition of operations, making complex data processing more manageable. This example demonstrates numerical differentiation and integration using `Itr`.
173-
174-
```python
175-
from itr import Itr
176-
import numpy as np
177-
from operator import add
178-
179-
x = Itr(np.linspace(0, 1, 11))
180-
# Need a copy of 'x' as the original 'x' is consumed in the zip method.
181-
xy = x.copy().zip(x.map(lambda xi: xi * xi / 2))
182-
183-
# Numerical differentiation (central difference)
184-
def diff1central(xy_segment):
185-
# Unpack the 3-element rolling window: (x0, y0), (x1, y1_ignored), (x2, y2)
186-
(x0, y0), (x1, _y1), (x2, y2) = xy_segment
187-
return x1, (y2 - y0) / (x2 - x0)
188-
189-
print("Numerical Derivatives:")
190-
print(
191-
xy.copy() # Need a copy as xy will be reused below for integration
192-
.rolling(3)
193-
.map(diff1central) # Produces (x, dy/dx) pairs
194-
.collect()
195-
)
196-
197-
# Numerical integration (trapezoidal rule)
198-
# Integrates x**2 / 2, resulting in x**3 / 6. Over 0,1 this is 1/6.
199-
def trapz_accumulate(current_sum, xy_pair):
200-
# Unpack (x0, y0) and (x1, y1) from the pairwise iteration
201-
(x0, y0), (x1, y1) = xy_pair
202-
return current_sum + 0.5 * (y0 + y1) * (x1 - x0)
203-
204-
print("\nNumerical Integral (Trapezoidal Rule - Fold):")
205-
print(xy.pairwise().fold(0, trapz_accumulate))
206-
207-
# ...or an alternative integration implementation using starmap and flattening
208-
def trapz2(x0, y0, x1, y1): # type: ignore[no-untyped-def]
209-
"""Calculates trapezoidal area for two points."""
210-
return (y0 + y1) * (x1 - x0) / 2
211-
212-
print("\nNumerical Integral (Trapezoidal Rule - Starmap):")
213-
print(xy.copy().pairwise().flatten().flatten().batched(4).starmap(trapz2).reduce(add))
214-
```
139+
More examples can be found [here](./doc/examples.ipynb).

doc/examples.md

Lines changed: 0 additions & 193 deletions
This file was deleted.

0 commit comments

Comments
 (0)