Skip to content

Commit 3850bc2

Browse files
update llms.txt
1 parent cee6fd1 commit 3850bc2

File tree

3 files changed

+9
-539
lines changed

3 files changed

+9
-539
lines changed

nbs/llms-ctx-full.txt

Lines changed: 3 additions & 267 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<project title="fastcore">
2-
fastcore adds to Python features inspired by other languages, like multiple dispatch from Julia, mixins from Ruby, and currying, binding, and more from Haskell. It also adds some “missing features” and clean up some rough edges in the Python standard library, such as simplifying parallel processing, and bringing ideas from NumPy over to Python’s list type.
2+
fastcore adds to Python features inspired by other languages, like mixins from Ruby, and currying, binding, and more from Haskell. It also adds some “missing features” and clean up some rough edges in the Python standard library, such as simplifying parallel processing, and bringing ideas from NumPy over to Python’s list type.
33

44
Here are some tips on using fastcore:
55

@@ -12,7 +12,6 @@ Here are some tips on using fastcore:
1212
- **Expressive testing**: Prefer fastcore's testing functions like `test_eq`, `test_ne`, `test_close` for more readable and informative test assertions.
1313
- **Advanced file operations**: Use the extended `Path` class, which adds methods like `ls()`, `read_json()`, and others to `pathlib.Path`.
1414
- **Flexible data structures**: Convert between dictionaries and attribute-access objects using `dict2obj` and `obj2dict` for more intuitive data handling.
15-
- **Data pipeline construction**: Employ `Transform` and `Pipeline` classes to create modular, composable data processing workflows.
1615
- **Functional programming paradigms**: Utilize tools like `compose`, `maps`, and `filter_ex` to write more functional-style Python code.
1716
- **Documentation**: Use `docments` where possible to document parameters of functions and methods.
1817
- **Time-aware caching**: Apply the `timed_cache` decorator to add time-based expiration to the standard `lru_cache` functionality.
@@ -364,77 +363,8 @@ in `list` in the first place, such as making this do what you’d expect
364363

365364
(#4) [1,2,3,4]
366365

367-
### Transforms
368-
369-
A [`Transform`](https://fastcore.fast.ai/transform.html#transform) is
370-
the main building block of the fastai data pipelines. In the most
371-
general terms a transform can be any function you want to apply to your
372-
data, however the
373-
[`Transform`](https://fastcore.fast.ai/transform.html#transform) class
374-
provides several mechanisms that make the process of building them easy
375-
and flexible (see the docs for information about each of these):
376-
377-
- Type dispatch
378-
- Dispatch over tuples
379-
- Reversability
380-
- Type propagation
381-
- Preprocessing
382-
- Filtering based on the dataset type
383-
- Ordering
384-
- Appending new behavior with decorators
385-
386-
[`Transform`](https://fastcore.fast.ai/transform.html#transform) looks
387-
for three special methods, <code>encodes</code>, <code>decodes</code>,
388-
and <code>setups</code>, which provide the implementation for
389-
[`__call__`](https://www.python-course.eu/python3_magic_methods.php),
390-
`decode`, and `setup` respectively. For instance:
391-
392-
``` python
393-
class A(Transform):
394-
def encodes(self, x): return x+1
395-
396-
A()(1)
397-
```
398-
399-
2
400-
401-
For simple transforms like this, you can also use
402-
[`Transform`](https://fastcore.fast.ai/transform.html#transform) as a
403-
decorator:
404-
405-
``` python
406-
@Transform
407-
def f(x): return x+1
408-
409-
f(1)
410-
```
411-
412-
2
413-
414-
Transforms can be composed into a
415-
[`Pipeline`](https://fastcore.fast.ai/transform.html#pipeline):
416-
417-
``` python
418-
@Transform
419-
def g(x): return x/2
420-
421-
pipe = Pipeline([f,g])
422-
pipe(3)
423-
```
424-
425-
2.0
426-
427-
The power of
428-
[`Transform`](https://fastcore.fast.ai/transform.html#transform) and
429-
[`Pipeline`](https://fastcore.fast.ai/transform.html#pipeline) is best
430-
understood by seeing how they’re used to create a complete data
431-
processing pipeline. This is explained in [chapter
432-
11](https://github.com/fastai/fastbook/blob/master/11_midlevel_data.ipynb)
433-
of the [fastai
434-
book](https://www.amazon.com/Deep-Learning-Coders-fastai-PyTorch/dp/1492045527),
435-
which is [available for free](https://github.com/fastai/fastbook) in
436-
Jupyter Notebook format.</doc>
437-
<doc title="Blog Post" desc="A tour of some of the features of fastcore."># fastcore: An Underrated Python Library
366+
</doc>
367+
<doc title="Blog Post" desc="A tour of some of the features of fastcore."># fastcore: An Underrated Python Library
438368

439369
A unique python library that extends the python programming language and provides utilities that enhance productivity.
440370

@@ -627,76 +557,6 @@ assert sc.some_attr == 'hello'
627557

628558
* * *
629559

630-
## Type Dispatch __
631-
632-
Type dispatch, orMultiple dispatch, allows you to change the way a function behaves based upon the input types it receives. This is a prominent feature in some programming languages like Julia. For example, this is a conceptual example of how multiple dispatch works in Julia, returning different values depending on the input types of x and y:
633-
634-
```
635-
collide_with(x::Asteroid, y::Asteroid) = ...
636-
# deal with asteroid hitting asteroid
637-
638-
collide_with(x::Asteroid, y::Spaceship) = ...
639-
# deal with asteroid hitting spaceship
640-
641-
collide_with(x::Spaceship, y::Asteroid) = ...
642-
# deal with spaceship hitting asteroid
643-
644-
collide_with(x::Spaceship, y::Spaceship) = ...
645-
# deal with spaceship hitting spaceship
646-
647-
```
648-
649-
Type dispatch can be especially useful in data science, where you might allow different input types (i.e. Numpy arrays and Pandas dataframes) to a function that processes data. Type dispatch allows you to have a common API for functions that do similar tasks.
650-
651-
Unfortunately, Python does not support this out-of-the box. Fortunately, there is the @typedispatch decorator to the rescue. This decorator relies upon type hints in order to route inputs the correct version of the function:
652-
653-
```
654-
@typedispatch
655-
def f(x:str, y:str): return f'{x}{y}'
656-
657-
@typedispatch
658-
def f(x:np.ndarray): return x.sum()
659-
660-
@typedispatch
661-
def f(x:int, y:int): return x+y
662-
663-
```
664-
665-
Below is a demonstration of type dispatch at work for the function `f`:
666-
667-
```
668-
f('Hello ', 'World!')
669-
670-
```
671-
672-
```
673-
'Hello World!'
674-
```
675-
676-
```
677-
f(2,3)
678-
679-
```
680-
681-
```
682-
5
683-
```
684-
685-
```
686-
f(np.array([5,5,5,5]))
687-
688-
```
689-
690-
```
691-
20
692-
```
693-
694-
There are limitations of this feature, as well as other ways of using this functionality that you can read about here. In the process of learning about typed dispatch, I also found a python library called multipledispatch made by Mathhew Rocklin (the creator of Dask).
695-
696-
After using this feature, I am now motivated to learn languages like Julia to discover what other paradigms I might be missing.
697-
698-
* * *
699-
700560
## A better version of functools.partial __
701561

702562
`functools.partial` is a great utility that creates functions from other functions that lets you set default values. Lets take this function for example that filters a list to only contain values >= `val`:
@@ -1050,10 +910,6 @@ Thefunctional programming section is my favorite part of this library.
1050910
* mapped: A more robust `map`
1051911
* using_attr: compose a function that operates on an attribute
1052912

1053-
## Transforms __
1054-
1055-
Transforms is a collection of utilities for creating data transformations and associated pipelines. These transformation utilities build upon many of the building blocks discussed in this blog post.
1056-
1057913
## Further Reading __
1058914

1059915
**It should be noted that you should read themain page of the docs first, followed by the section on tests to fully understand the documentation.**
@@ -1493,60 +1349,6 @@ This blog post was written entirely in a Jupyter Notebook, which GitHub automati
14931349
- `def str2bool(s)`
14941350
Case-insensitive convert string `s` too a bool (`y`,`yes`,`t`,`true`,`on`,`1`->`True`)
14951351

1496-
## fastcore.dispatch
1497-
1498-
> Basic single and dual parameter dispatch
1499-
1500-
- `def lenient_issubclass(cls, types)`
1501-
If possible return whether `cls` is a subclass of `types`, otherwise return False.
1502-
1503-
- `def sorted_topologically(iterable)`
1504-
Return a new list containing all items from the iterable sorted topologically
1505-
1506-
- `class TypeDispatch`
1507-
Dictionary-like object; `__getitem__` matches keys of types using `issubclass`
1508-
1509-
- `def __init__(self, funcs, bases)`
1510-
- `def add(self, f)`
1511-
Add type `t` and function `f`
1512-
1513-
- `def first(self)`
1514-
Get first function in ordered dict of type:func.
1515-
1516-
- `def returns(self, x)`
1517-
Get the return type of annotation of `x`.
1518-
1519-
- `def __repr__(self)`
1520-
- `def __call__(self, *args, **kwargs)`
1521-
- `def __get__(self, inst, owner)`
1522-
- `def __getitem__(self, k)`
1523-
Find first matching type that is a super-class of `k`
1524-
1525-
1526-
- `class DispatchReg`
1527-
A global registry for `TypeDispatch` objects keyed by function name
1528-
1529-
- `def __init__(self)`
1530-
- `def __call__(self, f)`
1531-
1532-
- `def retain_meta(x, res, as_copy)`
1533-
Call `res.set_meta(x)`, if it exists
1534-
1535-
- `def default_set_meta(self, x, as_copy)`
1536-
Copy over `_meta` from `x` to `res`, if it's missing
1537-
1538-
- `@typedispatch def cast(x, typ)`
1539-
cast `x` to type `typ` (may also change `x` inplace)
1540-
1541-
- `def retain_type(new, old, typ, as_copy)`
1542-
Cast `new` to type of `old` or `typ` if it's a superclass
1543-
1544-
- `def retain_types(new, old, typs)`
1545-
Cast each item of `new` to type of matching item in `old` if it's a superclass
1546-
1547-
- `def explode_types(o)`
1548-
Return the type of `o`, potentially in nested dictionaries for thing that are listy
1549-
15501352
## fastcore.docments
15511353

15521354
> Document parameters using comments.
@@ -2056,72 +1858,6 @@ This blog post was written entirely in a Jupyter Notebook, which GitHub automati
20561858
- `def __enter__(self)`
20571859
- `def __exit__(self, type, value, traceback)`
20581860

2059-
## fastcore.transform
2060-
2061-
> Definition of `Transform` and `Pipeline`
2062-
2063-
- `class Transform`
2064-
Delegates (`__call__`,`decode`,`setup`) to (<code>encodes</code>,<code>decodes</code>,<code>setups</code>) if `split_idx` matches
2065-
2066-
- `def __init__(self, enc, dec, split_idx, order)`
2067-
- `@property def name(self)`
2068-
- `def __call__(self, x, **kwargs)`
2069-
- `def decode(self, x, **kwargs)`
2070-
- `def __repr__(self)`
2071-
- `def setup(self, items, train_setup)`
2072-
2073-
- `class InplaceTransform`
2074-
A `Transform` that modifies in-place and just returns whatever it's passed
2075-
2076-
2077-
- `class DisplayedTransform`
2078-
A transform with a `__repr__` that shows its attrs
2079-
2080-
- `@property def name(self)`
2081-
2082-
- `class ItemTransform`
2083-
A transform that always take tuples as items
2084-
2085-
- `def __call__(self, x, **kwargs)`
2086-
- `def decode(self, x, **kwargs)`
2087-
2088-
- `def get_func(t, name, *args, **kwargs)`
2089-
Get the `t.name` (potentially partial-ized with `args` and `kwargs`) or `noop` if not defined
2090-
2091-
- `class Func`
2092-
Basic wrapper around a `name` with `args` and `kwargs` to call on a given type
2093-
2094-
- `def __init__(self, name, *args, **kwargs)`
2095-
- `def __repr__(self)`
2096-
- `def __call__(self, t)`
2097-
2098-
- `def compose_tfms(x, tfms, is_enc, reverse, **kwargs)`
2099-
Apply all `func_nm` attribute of `tfms` on `x`, maybe in `reverse` order
2100-
2101-
- `def mk_transform(f)`
2102-
Convert function `f` to `Transform` if it isn't already one
2103-
2104-
- `def gather_attrs(o, k, nm)`
2105-
Used in __getattr__ to collect all attrs `k` from `self.{nm}`
2106-
2107-
- `def gather_attr_names(o, nm)`
2108-
Used in __dir__ to collect all attrs `k` from `self.{nm}`
2109-
2110-
- `class Pipeline`
2111-
A pipeline of composed (for encode/decode) transforms, setup with types
2112-
2113-
- `def __init__(self, funcs, split_idx)`
2114-
- `def setup(self, items, train_setup)`
2115-
- `def add(self, ts, items, train_setup)`
2116-
- `def __call__(self, o)`
2117-
- `def __repr__(self)`
2118-
- `def __getitem__(self, i)`
2119-
- `def __setstate__(self, data)`
2120-
- `def __getattr__(self, k)`
2121-
- `def __dir__(self)`
2122-
- `def decode(self, o, full)`
2123-
- `def show(self, o, ctx, **kwargs)`
2124-
21251861
## fastcore.xdg
21261862

21271863
> XDG Base Directory Specification helpers.

0 commit comments

Comments
 (0)