.. image:: https://travis-ci.org/jul/archery.svg?branch=master
:target: https://travis-ci.org/jul/archery
.. image:: https://badge.fury.io/py/archery.svg
:target: https://badge.fury.io/py/archery
.. image:: https://codecov.io/gh/jul/archery/branch/master/graph/badge.svg
:target: https://codecov.io/gh/jul/archery
.. image:: https://readthedocs.org/projects/archery/badge/?version=latest
:target: https://archery.readthedocs.io/en/latest/?badge=latest
:alt: Documentation Status
.. image:: https://img.shields.io/badge/py2.7|3.3|3.4|3.5|3.6|3.7-ok-brightgreen.svg
* Source : https://github.com/jul/archery
* Tickets : https://github.com/jul/archery/issues?state=open
* Latest documentation : http://archery.readthedocs.org/en/latest/index.html
What is archery?
================
It is set of Mixins to use on MutableMapping giving the following features :
- Linear Algebrae;
- Vector like metrics;
- Searchable behaviour;
for convenience 3 concrete classes are provided :
- `mdict`_ (dict that follow the rules of linear algebrae based on dict);
- `vdict`_ (dict that have cos, abs, dot product);
- `sdict`_ (dict that are easily searchable);
Basic Usage
===========
Using the ready to use class derived from dict
mdict
*****
**dict that supports consistently all the linear algebrae properties**
Basically : dict that are vectors on arbitrary basis (recursively).
To learn more about its use and implementation:
- `Video presentation in FOSDEM 2017 <https://www.youtube.com/watch?v=Rd6rY5zNcGM>`_
- `or look at the presentation <http://jul.github.io/cv/pres.html#printable>`_
ex::
>>> from archery import mdict
>>> point = mdict(x=1, y=1, z=1)
>>> point2 = mdict(x=1, y=-1)
>>> print( (2 * point + point2)/4)
>>> # OUT : {'y': 0.25, 'x': 0.75, 'z': 0.5}
>>> print(point - point2)
>>> # OUT : {'y': 2, 'x': 0, 'z': 1}
>>> b=mdict(x=2, z=-1)
>>> a=mdict(x=1, y=2.0)
>>> a+b
>>> # OUT: {'y': 2.0, 'x': 3, 'z': -1}
>>> b-a
>>> # OUT: {'y': -2.0, 'x': 1, 'z': -1}
>>> -(a-b)
>>> # OUT: {'y': -2.0, 'x': 1, 'z': -1}
>>> a+1
>>> # OUT: {'y': 3.0, 'x': 2}
>>> -1-a
>>> # OUT: {'y': -3.0, 'x': -2}
>>> a*b
>>> # OUT: {'x': 2}
>>> a/b
>>> # OUT: {'x': 0}
>>> 1.0*a/b
>>> # OUT: {'x': 0.5}
vdict
*****
dict that defines *abs()*, *dot()*, *cos()* in the euclidean meaning
ex::
>>> from archery import vdict as Point
>>>
>>> u = Point(x=1, y=1)
>>> v = Point(x=1, y=0)
>>> u.cos(v)
>>> 0.7071067811865475
>>> u.dot(v)
>>> # OUT: 1
>>> u.cos(2*v)
>>> # OUT: 0.7071067811865475
>>> u.dot(2*v)
>>> #OUT: 2
>>> abs(u)
>>> #OUT: 1.4142135623730951
>>> u3 = Point(x=1, y=1, z=2)
>>> u4 = Point(x=1, y=3, z=4)
>>> u3 + u4
>>> #OUT: dict(x=2, y=4, z=6)
>>> assert u4 + u4 == 2*u4
>>> from archery import vdict
>>> from math import acos, pi
>>> point = vdict(x=1, y=1, z=1)
>>> point2 = vdict(x=1, y=-1)
>>> point2 = mdict(x=1, y=-1)
>>> print( (2 * point + point2)/4)
>>> # OUT : {'y': 0.25, 'x': 0.75, 'z': 0.5}
>>> print(acos(vdict(x=1,y=0).cos(vdict(x=1, y=1)))*360/2/pi)
>>> # OUT : 45.0
>>> print(abs(vdict(x=1, y=1)))
>>> # OUT : 1.41421356237
>>> print(vdict(x=1,y=0,z=3).dot(vdict(x=1, y=1, z=-1)))
>>> #OUT -2
sdict
*****
dict made for searching value/keys/*Path* with special interests.
Basically, it returns an iterator in the form of a tuple being all the keys and the value.
It is a neat trick, if you combine it with *make_from_path*, it helps select exactly what you want in a dict::
>>> from archery import sdict, make_from_path
>>> tree = sdict(
... a = 1,
... b = dict(
... c = 3.0,
... d = dict(e=True)
... ),
... point = dict( x=1, y=1, z=0),
... )
>>> list(tree.leaf_search(lambda x: type(x) is float ))
>>> #Out: [3.0]
>>> res = list(tree.search(lambda x: ("point") in x ))
>>> ## equivalent to list(tree.search(lambda x: Path(x).contains("point")))
>>> print(res)
>>> #Out: [('point', 'y', 1), ('point', 'x', 1), ('point', 'z', 0)]
>>> make_from_path(dict(), res)
>>> # {('point', 'y', 1): {('point', 'x', 1): ('point', 'z', 0)}}
Advanced usage
==============
This library is a proof of the consistent use of Mixins on `MutableMapping <https://docs.python.org/3.7/library/collections.abc.html?highlight=mutablemapping#collections.abc.MutableMapping>`_ gives the property seen in the basic usage.
The Mixins do not require any specifics regarding the implementation and **should** work if I did my job properly with
any kinds of *MutableMapping*.
Here is an example of a cosine similarities out of the box on the *Collections.Counter* ::
>>> from collections import Counter
>>> from archery import VectorDict
>>> class CWCos(VectorDict, Counter):
... pass
>>>
>>> CWCos(["mot", "wut", "wut", "bla"]).cos(CWCos(["mot","wut", "bla"]))
>>> # OUT: 0.942809041582
You can also inherit LinearAlgebrae
Resource
********
Ticketing: https://github.com/jul/archery/issues?state=open
Source: https://github.com/jul/archery
Latest documentation: http://archery.readthedocs.org/en/latest/index.html
Raw data
{
"_id": null,
"home_page": "http://archery.readthedocs.org/",
"name": "archery",
"maintainer": "",
"docs_url": "https://pythonhosted.org/archery/",
"requires_python": "",
"maintainer_email": "",
"keywords": "",
"author": "julien tayon",
"author_email": "julien@tayon.net",
"download_url": "https://files.pythonhosted.org/packages/32/df/6002230e936350f29ba911b40ac8e43661fc6cec53f9cf131b44b49203bf/archery-1.3.0.tar.gz",
"platform": null,
"description": ".. image:: https://travis-ci.org/jul/archery.svg?branch=master\r\n :target: https://travis-ci.org/jul/archery\r\n\r\n.. image:: https://badge.fury.io/py/archery.svg\r\n :target: https://badge.fury.io/py/archery\r\n\r\n.. image:: https://codecov.io/gh/jul/archery/branch/master/graph/badge.svg\r\n :target: https://codecov.io/gh/jul/archery\r\n\r\n.. image:: https://readthedocs.org/projects/archery/badge/?version=latest\r\n :target: https://archery.readthedocs.io/en/latest/?badge=latest\r\n :alt: Documentation Status\r\n\r\n\r\n.. image:: https://img.shields.io/badge/py2.7|3.3|3.4|3.5|3.6|3.7-ok-brightgreen.svg\r\n\r\n\r\n\r\n* Source : https://github.com/jul/archery\r\n* Tickets : https://github.com/jul/archery/issues?state=open\r\n* Latest documentation : http://archery.readthedocs.org/en/latest/index.html\r\n\r\nWhat is archery?\r\n================\r\n\r\nIt is set of Mixins to use on MutableMapping giving the following features :\r\n\r\n- Linear Algebrae;\r\n- Vector like metrics;\r\n- Searchable behaviour;\r\n\r\nfor convenience 3 concrete classes are provided :\r\n\r\n- `mdict`_ (dict that follow the rules of linear algebrae based on dict);\r\n- `vdict`_ (dict that have cos, abs, dot product);\r\n- `sdict`_ (dict that are easily searchable);\r\n\r\n\r\nBasic Usage\r\n===========\r\n\r\nUsing the ready to use class derived from dict\r\n\r\nmdict\r\n*****\r\n\r\n**dict that supports consistently all the linear algebrae properties**\r\n\r\nBasically : dict that are vectors on arbitrary basis (recursively).\r\n\r\nTo learn more about its use and implementation:\r\n\r\n- `Video presentation in FOSDEM 2017 <https://www.youtube.com/watch?v=Rd6rY5zNcGM>`_\r\n- `or look at the presentation <http://jul.github.io/cv/pres.html#printable>`_\r\n\r\nex::\r\n\r\n >>> from archery import mdict\r\n >>> point = mdict(x=1, y=1, z=1)\r\n >>> point2 = mdict(x=1, y=-1)\r\n >>> print( (2 * point + point2)/4)\r\n >>> # OUT : {'y': 0.25, 'x': 0.75, 'z': 0.5}\r\n >>> print(point - point2)\r\n >>> # OUT : {'y': 2, 'x': 0, 'z': 1}\r\n >>> b=mdict(x=2, z=-1)\r\n >>> a=mdict(x=1, y=2.0)\r\n >>> a+b\r\n >>> # OUT: {'y': 2.0, 'x': 3, 'z': -1}\r\n >>> b-a\r\n >>> # OUT: {'y': -2.0, 'x': 1, 'z': -1}\r\n >>> -(a-b)\r\n >>> # OUT: {'y': -2.0, 'x': 1, 'z': -1}\r\n >>> a+1\r\n >>> # OUT: {'y': 3.0, 'x': 2}\r\n >>> -1-a\r\n >>> # OUT: {'y': -3.0, 'x': -2}\r\n >>> a*b\r\n >>> # OUT: {'x': 2}\r\n >>> a/b\r\n >>> # OUT: {'x': 0}\r\n >>> 1.0*a/b\r\n >>> # OUT: {'x': 0.5}\r\n\r\nvdict\r\n*****\r\n\r\n\r\ndict that defines *abs()*, *dot()*, *cos()* in the euclidean meaning\r\n\r\nex::\r\n\r\n >>> from archery import vdict as Point\r\n >>>\r\n >>> u = Point(x=1, y=1)\r\n >>> v = Point(x=1, y=0)\r\n >>> u.cos(v)\r\n >>> 0.7071067811865475\r\n >>> u.dot(v)\r\n >>> # OUT: 1\r\n >>> u.cos(2*v)\r\n >>> # OUT: 0.7071067811865475\r\n >>> u.dot(2*v)\r\n >>> #OUT: 2\r\n >>> abs(u)\r\n >>> #OUT: 1.4142135623730951\r\n >>> u3 = Point(x=1, y=1, z=2)\r\n >>> u4 = Point(x=1, y=3, z=4)\r\n >>> u3 + u4\r\n >>> #OUT: dict(x=2, y=4, z=6)\r\n >>> assert u4 + u4 == 2*u4\r\n >>> from archery import vdict\r\n >>> from math import acos, pi\r\n >>> point = vdict(x=1, y=1, z=1)\r\n >>> point2 = vdict(x=1, y=-1)\r\n >>> point2 = mdict(x=1, y=-1)\r\n >>> print( (2 * point + point2)/4)\r\n >>> # OUT : {'y': 0.25, 'x': 0.75, 'z': 0.5}\r\n >>> print(acos(vdict(x=1,y=0).cos(vdict(x=1, y=1)))*360/2/pi)\r\n >>> # OUT : 45.0\r\n >>> print(abs(vdict(x=1, y=1)))\r\n >>> # OUT : 1.41421356237\r\n >>> print(vdict(x=1,y=0,z=3).dot(vdict(x=1, y=1, z=-1)))\r\n >>> #OUT -2\r\n\r\n\r\nsdict\r\n*****\r\n\r\ndict made for searching value/keys/*Path* with special interests.\r\n\r\nBasically, it returns an iterator in the form of a tuple being all the keys and the value.\r\nIt is a neat trick, if you combine it with *make_from_path*, it helps select exactly what you want in a dict::\r\n\r\n\r\n >>> from archery import sdict, make_from_path\r\n >>> tree = sdict(\r\n ... a = 1,\r\n ... b = dict(\r\n ... c = 3.0,\r\n ... d = dict(e=True)\r\n ... ),\r\n ... point = dict( x=1, y=1, z=0),\r\n ... )\r\n >>> list(tree.leaf_search(lambda x: type(x) is float ))\r\n >>> #Out: [3.0]\r\n >>> res = list(tree.search(lambda x: (\"point\") in x ))\r\n >>> ## equivalent to list(tree.search(lambda x: Path(x).contains(\"point\")))\r\n >>> print(res)\r\n >>> #Out: [('point', 'y', 1), ('point', 'x', 1), ('point', 'z', 0)]\r\n >>> make_from_path(dict(), res)\r\n >>> # {('point', 'y', 1): {('point', 'x', 1): ('point', 'z', 0)}}\r\n\r\n\r\nAdvanced usage\r\n==============\r\n\r\nThis library is a proof of the consistent use of Mixins on `MutableMapping <https://docs.python.org/3.7/library/collections.abc.html?highlight=mutablemapping#collections.abc.MutableMapping>`_ gives the property seen in the basic usage.\r\n\r\n\r\nThe Mixins do not require any specifics regarding the implementation and **should** work if I did my job properly with\r\nany kinds of *MutableMapping*.\r\n\r\nHere is an example of a cosine similarities out of the box on the *Collections.Counter* ::\r\n\r\n >>> from collections import Counter\r\n >>> from archery import VectorDict\r\n >>> class CWCos(VectorDict, Counter):\r\n ... pass\r\n >>>\r\n >>> CWCos([\"mot\", \"wut\", \"wut\", \"bla\"]).cos(CWCos([\"mot\",\"wut\", \"bla\"]))\r\n >>> # OUT: 0.942809041582\r\n\r\nYou can also inherit LinearAlgebrae\r\n\r\n\r\nResource\r\n********\r\n\r\nTicketing: https://github.com/jul/archery/issues?state=open\r\nSource: https://github.com/jul/archery\r\nLatest documentation: http://archery.readthedocs.org/en/latest/index.html\r\n",
"bugtrack_url": null,
"license": "Python Software Foundation License",
"summary": "Traits (Mixins) to give +,/,-,* to MutableMapping",
"version": "1.3.0",
"project_urls": {
"Homepage": "http://archery.readthedocs.org/"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "32df6002230e936350f29ba911b40ac8e43661fc6cec53f9cf131b44b49203bf",
"md5": "6f78c76d924d233144f9c3df15400692",
"sha256": "30923281a2e6f76d34d0aa10540f6468fd996366b9a1b393c4029d90f01b3728"
},
"downloads": -1,
"filename": "archery-1.3.0.tar.gz",
"has_sig": false,
"md5_digest": "6f78c76d924d233144f9c3df15400692",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 19307,
"upload_time": "2023-08-06T19:32:41",
"upload_time_iso_8601": "2023-08-06T19:32:41.102419Z",
"url": "https://files.pythonhosted.org/packages/32/df/6002230e936350f29ba911b40ac8e43661fc6cec53f9cf131b44b49203bf/archery-1.3.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-08-06 19:32:41",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "archery"
}