Files
mlx/docs/build/doctrees/python/tree_utils.doctree

36 lines
8.9 KiB
Plaintext
Raw Normal View History

2024-01-17 17:15:29 -08:00
<EFBFBD><05><>#<00>sphinx.addnodes<65><73>document<6E><74><EFBFBD>)<29><>}<7D>(<28> rawsource<63><65><00><>children<65>]<5D>(<28>docutils.nodes<65><73>target<65><74><EFBFBD>)<29><>}<7D>(h<05>
.. _utils:<3A>h]<5D><>
attributes<EFBFBD>}<7D>(<28>ids<64>]<5D><>classes<65>]<5D><>names<65>]<5D><>dupnames<65>]<5D><>backrefs<66>]<5D><>refid<69><64>utils<6C>u<EFBFBD>tagname<6D>h
<EFBFBD>line<6E>K<01>parent<6E>h<03> _document<6E>h<03>source<63><65>:/Users/awnihannun/repos/mlx/docs/src/python/tree_utils.rst<73>ubh <09>section<6F><6E><EFBFBD>)<29><>}<7D>(hhh]<5D>(h <09>title<6C><65><EFBFBD>)<29><>}<7D>(h<05>
Tree Utils<6C>h]<5D>h <09>Text<78><74><EFBFBD><EFBFBD>
Tree Utils<6C><73><EFBFBD><EFBFBD><EFBFBD>}<7D>(h h+h!hh"NhNubah}<7D>(h]<5D>h]<5D>h]<5D>h]<5D>h]<5D>uhh)h h&h!hh"h#hKubh <09> paragraph<70><68><EFBFBD>)<29><>}<7D>(hX2In MLX we consider a python tree to be an arbitrarily nested collection of
dictionaries, lists and tuples without cycles. Functions in this module that
return python trees will be using the default python ``dict``, ``list`` and
``tuple`` but they can usually process objects that inherit from any of these.<2E>h]<5D>(h0<68><30>In MLX we consider a python tree to be an arbitrarily nested collection of
dictionaries, lists and tuples without cycles. Functions in this module that
return python trees will be using the default python <20><><EFBFBD><EFBFBD><EFBFBD>}<7D>(h h=h!hh"NhNubh <09>literal<61><6C><EFBFBD>)<29><>}<7D>(h<05>``dict``<60>h]<5D>h0<68>dict<63><74><EFBFBD><EFBFBD><EFBFBD>}<7D>(h hGh!hh"NhNubah}<7D>(h]<5D>h]<5D>h]<5D>h]<5D>h]<5D>uhhEh h=ubh0<68>, <20><><EFBFBD><EFBFBD><EFBFBD>}<7D>(h h=h!hh"NhNubhF)<29><>}<7D>(h<05>``list``<60>h]<5D>h0<68>list<73><74><EFBFBD><EFBFBD><EFBFBD>}<7D>(h hYh!hh"NhNubah}<7D>(h]<5D>h]<5D>h]<5D>h]<5D>h]<5D>uhhEh h=ubh0<68> and
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>}<7D>(h h=h!hh"NhNubhF)<29><>}<7D>(h<05> ``tuple``<60>h]<5D>h0<68>tuple<6C><65><EFBFBD><EFBFBD><EFBFBD>}<7D>(h hkh!hh"NhNubah}<7D>(h]<5D>h]<5D>h]<5D>h]<5D>h]<5D>uhhEh h=ubh0<68>E but they can usually process objects that inherit from any of these.<2E><><EFBFBD><EFBFBD><EFBFBD>}<7D>(h h=h!hh"NhNubeh}<7D>(h]<5D>h]<5D>h]<5D>h]<5D>h]<5D>uhh;h"h#hKh h&h!hubh <09>note<74><65><EFBFBD>)<29><>}<7D>(h<05>@Dictionaries should have keys that are valid python identifiers.<2E>h]<5D>h<)<29><>}<7D>(hh<>h]<5D>h0<68>@Dictionaries should have keys that are valid python identifiers.<2E><><EFBFBD><EFBFBD><EFBFBD>}<7D>(h h<>h!hh"NhNubah}<7D>(h]<5D>h]<5D>h]<5D>h]<5D>h]<5D>uhh;h"h#hK h h<>ubah}<7D>(h]<5D>h]<5D>h]<5D>h]<5D>h]<5D>uhh<>h h&h!hh"h#hNubh<00>tabular_col_spec<65><63><EFBFBD>)<29><>}<7D>(hhh]<5D>h}<7D>(h]<5D>h]<5D>h]<5D>h]<5D>h]<5D><>spec<65><63>\X{1}{2}\X{1}{2}<7D>uhh<>h h&h!hh"<22>K/Users/awnihannun/repos/mlx/docs/src/python/tree_utils.rst:21:<autosummary><3E>hNub<75>sphinx.ext.autosummary<72><79>autosummary_table<6C><65><EFBFBD>)<29><>}<7D>(hX4
tree_flatten(tree[, prefix, is_leaf])
Flattens a python tree to a list of key, value tuples.
tree_unflatten(tree)
Recreate a python tree from its flat representation.
tree_map(fn, tree, *rest[, is_leaf])
Applies fn to the leaves of the python tree tree and returns a new collection with the results.<2E>h]<5D>h <09>table<6C><65><EFBFBD>)<29><>}<7D>(hhh]<5D>h <09>tgroup<75><70><EFBFBD>)<29><>}<7D>(hhh]<5D>(h <09>colspec<65><63><EFBFBD>)<29><>}<7D>(hhh]<5D>h}<7D>(h]<5D>h]<5D>h]<5D>h]<5D>h]<5D><>colwidth<74>K
uhh<>h h<>ubh<62>)<29><>}<7D>(hhh]<5D>h}<7D>(h]<5D>h]<5D>h]<5D>h]<5D>h]<5D><>colwidth<74>KZuhh<>h h<>ubh <09>tbody<64><79><EFBFBD>)<29><>}<7D>(hhh]<5D>(h <09>row<6F><77><EFBFBD>)<29><>}<7D>(hhh]<5D>(h <09>entry<72><79><EFBFBD>)<29><>}<7D>(hhh]<5D>h<)<29><>}<7D>(h<05>Q:py:obj:`tree_flatten <mlx.utils.tree_flatten>`\ \(tree\[\, prefix\, is\_leaf\]\)<29>h]<5D>(h<00> pending_xref<65><66><EFBFBD>)<29><>}<7D>(h<05>/:py:obj:`tree_flatten <mlx.utils.tree_flatten>`<60>h]<5D>hF)<29><>}<7D>(hh<>h]<5D>h0<68> tree_flatten<65><6E><EFBFBD><EFBFBD><EFBFBD>}<7D>(h h<>h!hh"NhNubah}<7D>(h]<5D>h]<5D>(<28>xref<65><66>py<70><79>py-obj<62>eh]<5D>h]<5D>h]<5D>uhhEh h<>ubah}<7D>(h]<5D>h]<5D>h]<5D>h]<5D>h]<5D><>refdoc<6F><63>python/tree_utils<6C><73> refdomain<69>h<EFBFBD><68>reftype<70><65>obj<62><6A> refexplicit<69><74><EFBFBD>refwarn<72><6E><EFBFBD> py:module<6C><65> mlx.utils<6C><73>py:class<73>N<EFBFBD> reftarget<65><74>mlx.utils.tree_flatten<65>uhh<>h"<22>K/Users/awnihannun/repos/mlx/docs/src/python/tree_utils.rst:21:<autosummary><3E>hKh h<>ubh0<68>(tree[, prefix, is_leaf])<29><><EFBFBD><EFBFBD><EFBFBD>}<7D>(h h<>h!hh"NhNubeh}<7D>(h]<5D>h]<5D>h]<5D>h]<5D>h]<5D>uhh;h"j hKh h<>ubah}<7D>(h]<5D>h]<5D>h]<5D>h]<5D>h]<5D>uhh<>h h<>ubh<62>)<29><>}<7D>(hhh]<5D>h<)<29><>}<7D>(h<05>6Flattens a python tree to a list of key, value tuples.<2E>h]<5D>h0<68>6Flattens a python tree to a list of key, value tuples.<2E><><EFBFBD><EFBFBD><EFBFBD>}<7D>(h j h!hh"NhNubah}<7D>(h]<5D>h]<5D>h]<5D>h]<5D>h]<5D>uhh;h"<22>K/Users/awnihannun/repos/mlx/docs/src/python/tree_utils.rst:21:<autosummary><3E>hKh jubah}<7D>(h]<5D>h]<5D>h]<5D>h]<5D>h]<5D>uhh<>h h<>ubeh}<7D>(h]<5D>h]<5D>h]<5D>h]<5D>h]<5D>uhh<>h h<>ubh<62>)<29><>}<7D>(hhh]<5D>(h<>)<29><>}<7D>(hhh]<5D>h<)<29><>}<7D>(h<05>=:py:obj:`tree_unflatten <mlx.utils.tree_unflatten>`\ \(tree\)<29>h]<5D>(h<>)<29><>}<7D>(h<05>3:py:obj:`tree_unflatten <mlx.utils.tree_unflatten>`<60>h]<5D>hF)<29><>}<7D>(hjGh]<5D>h0<68>tree_unflatten<65><6E><EFBFBD><EFBFBD><EFBFBD>}<7D>(h jIh!hh"NhNubah}<7D>(h]<5D>h]<5D>(h<><68>py<70><79>py-obj<62>eh]<5D>h]<5D>h]<5D>uhhEh jEubah}<7D>(h]<5D>h]<5D>h]<5D>h]<5D>h]<5D><>refdoc<6F>j<00> refdomain<69>jS<00>reftype<70><65>obj<62><6A> refexplicit<69><74><EFBFBD>refwarn<72><6E>jjj Nj
<00>mlx.utils.tree_unflatten<65>uhh<>h"<22>K/Users/awnihannun/repos/mlx/docs/src/python/tree_utils.rst:21:<autosummary><3E>hKh jAubh0<68>(tree)<29><><EFBFBD><EFBFBD><EFBFBD>}<7D>(h jAh!hh"NhNubeh}<7D>(h]<5D>h]<5D>h]<5D>h]<5D>h]<5D>uhh;h"jehKh j>ubah}<7D>(h]<5D>h]<5D>h]<5D>h]<5D>h]<5D>uhh<>h j;ubh<62>)<29><>}<7D>(hhh]<5D>h<)<29><>}<7D>(h<05>4Recreate a python tree from its flat representation.<2E>h]<5D>h0<68>4Recreate a python tree from its flat representation.<2E><><EFBFBD><EFBFBD><EFBFBD>}<7D>(h jyh!hh"NhNubah}<7D>(h]<5D>h]<5D>h]<5D>h]<5D>h]<5D>uhh;h"<22>K/Users/awnihannun/repos/mlx/docs/src/python/tree_utils.rst:21:<autosummary><3E>hKh jvubah}<7D>(h]<5D>h]<5D>h]<5D>h]<5D>h]<5D>uhh<>h j;ubeh}<7D>(h]<5D>h]<5D>h]<5D>h]<5D>h]<5D>uhh<>h h<>ubh<62>)<29><>}<7D>(hhh]<5D>(h<>)<29><>}<7D>(hhh]<5D>h<)<29><>}<7D>(h<05>N:py:obj:`tree_map <mlx.utils.tree_map>`\ \(fn\, tree\, \*rest\[\, is\_leaf\]\)<29>h]<5D>(h<>)<29><>}<7D>(h<05>':py:obj:`tree_map <mlx.utils.tree_map>`<60>h]<5D>hF)<29><>}<7D>(hj<>h]<5D>h0<68>tree_map<61><70><EFBFBD><EFBFBD><EFBFBD>}<7D>(h j<>h!hh"NhNubah}<7D>(h]<5D>h]<5D>(h<><68>py<70><79>py-obj<62>eh]<5D>h]<5D>h]<5D>uhhEh j<>ubah}<7D>(h]<5D>h]<5D>h]<5D>h]<5D>h]<5D><>refdoc<6F>j<00> refdomain<69>j<EFBFBD><00>reftype<70><65>obj<62><6A> refexplicit<69><74><EFBFBD>refwarn<72><6E>jjj Nj
<00>mlx.utils.tree_map<61>uhh<>h"<22>K/Users/awnihannun/repos/mlx/docs/src/python/tree_utils.rst:21:<autosummary><3E>hKh j<>ubh0<68>(fn, tree, *rest[, is_leaf])<29><><EFBFBD><EFBFBD><EFBFBD>}<7D>(h j<>h!hh"NhNubeh}<7D>(h]<5D>h]<5D>h]<5D>h]<5D>h]<5D>uhh;h"j<>hKh j<>ubah}<7D>(h]<5D>h]<5D>h]<5D>h]<5D>h]<5D>uhh<>h j<>ubh<62>)<29><>}<7D>(hhh]<5D>h<)<29><>}<7D>(h<05>gApplies ``fn`` to the leaves of the python tree ``tree`` and returns a new collection with the results.<2E>h]<5D>(h0<68>Applies <20><><EFBFBD><EFBFBD><EFBFBD>}<7D>(h j<>h!hh"NhNubhF)<29><>}<7D>(h<05>``fn``<60>h]<5D>h0<68>fn<66><6E><EFBFBD><EFBFBD><EFBFBD>}<7D>(h j<>h!hh"NhNubah}<7D>(h]<5D>h]<5D>h]<5D>h]<5D>h]<5D>uhhEh j<>ubh0<68>" to the leaves of the python tree <20><><EFBFBD><EFBFBD><EFBFBD>}<7D>(h j<>h!hh"NhNubhF)<29><>}<7D>(h<05>``tree``<60>h]<5D>h0<68>tree<65><65><EFBFBD><EFBFBD><EFBFBD>}<7D>(h j<>h!hh"NhNubah}<7D>(h]<5D>h]<5D>h]<5D>h]<5D>h]<5D>uhhEh j<>ubh0<68>/ and returns a new collection with the results.<2E><><EFBFBD><EFBFBD><EFBFBD>}<7D>(h j<>h!hh"NhNubeh}<7D>(h]<5D>h]<5D>h]<5D>h]<5D>h]<5D>uhh;h"h<>hKh j<>ubah}<7D>(h]<5D>h]<5D>h]<5D>h]<5D>h]<5D>uhh<>h j<>ubeh}<7D>(h]<5D>h]<5D>h]<5D>h]<5D>h]<5D>uhh<>h h<>ubeh}<7D>(h]<5D>h]<5D>h]<5D>h]<5D>h]<5D>uhh<>h h<>ubeh}<7D>(h]<5D>h]<5D>h]<5D>h]<5D>h]<5D><>cols<6C>Kuhh<>h h<>ubah}<7D>(h]<5D>h]<5D><>autosummary longtable<6C>ah]<5D>h]<5D>h]<5D>uhh<>h h<>ubah}<7D>(h]<5D>h]<5D>h]<5D>h]<5D>h]<5D><> xml:space<63><65>preserve<76>uhh<>h h&h!hh"h<>hNubh<62><68>autosummary_toc<6F><63><EFBFBD>)<29><>}<7D>(hhh]<5D>h<00>toctree<65><65><EFBFBD>)<29><>}<7D>(hhh]<5D>h}<7D>(h]<5D>h]<5D>h]<5D>h]<5D>h]<5D><> includefiles<65>]<5D>(<28>*python/_autosummary/mlx.utils.tree_flatten<65><6E>,python/_autosummary/mlx.utils.tree_unflatten<65><6E>&python/_autosummary/mlx.utils.tree_map<61>e<EFBFBD>entries<65>]<5D>(Nj><00><>Nj?<00><>Nj@<00><>e<EFBFBD>maxdepth<74>J<EFBFBD><4A><EFBFBD><EFBFBD><EFBFBD>glob<6F>N<EFBFBD>caption<6F>N<EFBFBD>
rawentries<EFBFBD>]<5D>uhj1h j.ubah}<7D>(h]<5D>h]<5D>h]<5D>h]<5D>h]<5D>j*j+uhj,h h&h!hh"h<>hNubeh}<7D>(h]<5D>(<28>
tree-utils<6C>heh]<5D>h]<5D>(<28>
tree utils<6C><73>utils<6C>eh]<5D>h]<5D>uhh$h hh!hh"h#hK<04>expect_referenced_by_name<6D>}<7D>jWh s<>expect_referenced_by_id<69>}<7D>hh subeh}<7D>(h]<5D>h]<5D>h]<5D>h]<5D>h]<5D><>source<63>h#uhh<01>current_source<63>N<EFBFBD> current_line<6E>N<EFBFBD>settings<67><73>docutils.frontend<6E><64>Values<65><73><EFBFBD>)<29><>}<7D>(h)N<> generator<6F>N<EFBFBD> datestamp<6D>N<EFBFBD> source_link<6E>N<EFBFBD>
source_url<EFBFBD>N<EFBFBD> toc_backlinks<6B>footnote_backlinks<6B>K<01> sectnum_xform<72>K<01>strip_comments<74>N<EFBFBD>strip_elements_with_classes<65>N<EFBFBD> strip_classes<65>N<EFBFBD> report_level<65>K<02>
halt_level<EFBFBD>K<05>exit_status_level<65>K<05>debug<75>N<EFBFBD>warning_stream<61>N<EFBFBD> traceback<63><6B><EFBFBD>input_encoding<6E><67> utf-8-sig<69><67>input_encoding_error_handler<65><72>strict<63><74>output_encoding<6E><67>utf-8<><38>output_encoding_error_handler<65>j<EFBFBD><00>error_encoding<6E><67>utf-8<><38>error_encoding_error_handler<65><72>backslashreplace<63><65> language_code<64><65>en<65><6E>record_dependencies<65>N<EFBFBD>config<69>N<EFBFBD> id_prefix<69>h<06>auto_id_prefix<69><78>id<69><64> dump_settings<67>N<EFBFBD>dump_internals<6C>N<EFBFBD>dump_transforms<6D>N<EFBFBD>dump_pseudo_xml<6D>N<EFBFBD>expose_internals<6C>N<EFBFBD>strict_visitor<6F>N<EFBFBD>_disable_config<69>N<EFBFBD>_source<63>h#<23> _destination<6F>N<EFBFBD> _config_files<65>]<5D><>file_insertion_enabled<65><64><EFBFBD> raw_enabled<65>K<01>line_length_limit<69>M'<27>pep_references<65>N<EFBFBD> pep_base_url<72><6C>https://peps.python.org/<2F><>pep_file_url_template<74><65>pep-%04d<34><64>rfc_references<65>N<EFBFBD> rfc_base_url<72><6C>&https://datatracker.ietf.org/doc/html/<2F><> tab_width<74>K<08>trim_footnote_reference_space<63><65><EFBFBD>syntax_highlight<68><74>long<6E><67> smart_quotes<65><73><EFBFBD>smartquotes_locales<65>]<5D><>character_level_inline_markup<75><70><EFBFBD>doctitle_xform<72><6D><EFBFBD> docinfo_xform<72>K<01>sectsubtitle_xform<72><6D><EFBFBD> image_loading<6E><67>link<6E><6B>embed_stylesheet<65><74><EFBFBD>cloak_email_addresses<65><73><EFBFBD>section_self_link<6E><6B><EFBFBD>env<6E>Nub<75>reporter<65>N<EFBFBD>indirect_targets<74>]<5D><>substitution_defs<66>}<7D><>substitution_names<65>}<7D><>refnames<65>}<7D><>refids<64>}<7D>h]<5D>h as<61>nameids<64>}<7D>(jWhjVjSu<> nametypes<65>}<7D>(jW<00>jV<00>uh}<7D>(hh&jSh&u<> footnote_refs<66>}<7D><> citation_refs<66>}<7D><> autofootnotes<65>]<5D><>autofootnote_refs<66>]<5D><>symbol_footnotes<65>]<5D><>symbol_footnote_refs<66>]<5D><> footnotes<65>]<5D><> citations<6E>]<5D><>autofootnote_start<72>K<01>symbol_footnote_start<72>K<00>
id_counter<EFBFBD><EFBFBD> collections<6E><73>Counter<65><72><EFBFBD>}<7D><><EFBFBD>R<EFBFBD><52>parse_messages<65>]<5D><>transform_messages<65>]<5D>h <09>system_message<67><65><EFBFBD>)<29><>}<7D>(hhh]<5D>h<)<29><>}<7D>(hhh]<5D>h0<68>+Hyperlink target "utils" is not referenced.<2E><><EFBFBD><EFBFBD><EFBFBD>}<7D>h j<>sbah}<7D>(h]<5D>h]<5D>h]<5D>h]<5D>h]<5D>uhh;h j<>ubah}<7D>(h]<5D>h]<5D>h]<5D>h]<5D>h]<5D><>level<65>K<01>type<70><65>INFO<46><4F>source<63>h#<23>line<6E>Kuhj<>uba<62> transformer<65>N<EFBFBD> include_log<6F>]<5D><>
decoration<EFBFBD>Nh!hub.