<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Wed, 31 Oct 2018 at 00:20, David Mertz <<a href="mailto:mertz@gnosis.cx">mertz@gnosis.cx</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr">Counter doesn't QUITE do the same thing as this `mdict`.  But it's pretty close.<div><br></div><div>I think if .__add__() became a synonym for .update() that wouldn't break anything that currently works.  But I'm probably wrong, and missing a case in my quick thought:</div><div><br></div></div></div></blockquote></div><div class="gmail_quote">My quick thoughts too is that it achieve coincidently Counter features as a subset of its features. I never noticed it, and both approaches seem consistent in their results (pfiou, close one since I did not thought of checking it)<br></div><div class="gmail_quote"><br></div><div class="gmail_quote">And .... if you add the trait to Counter .... you have the following results : <br>>>> from collections import Counter<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div><div></div></div></div></div></blockquote><div>>>> from archery.quiver import LinearAlgebrae<br>>>> class ACounter(LinearAlgebrae, Counter): pass</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div><div>>>> c = ACounter(a=[2], b='a')</div><div>>>> c.update(c)</div><div>>>> c</div></div></div></div></blockquote><div><br></div><div> ACounter({'a': [2, 2], 'b': 'aa'}) <br></div><div> (same)</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div><div>>>> c2 = ACounter(a=1, b=2)</div><div>>>> c2 + c2</div></div></div></div></blockquote><div>ACounter({'b': 4, 'a': 2})</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div><div>>>> c2.update(c2)</div><div>>>> c2</div></div></div></div></blockquote><div> ACounter({'b': 4, 'a': 2})</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div><div>>>> c2 + c2</div></div></div></div></blockquote><div>ACounter({'a': 4, 'b': 8})</div></div><div class="gmail_quote">>>> c2 + .5 * c2<br> ACounter({'a': 1.5, 'b': 3.0})<br><br><br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div><div class="gmail_quote"><div dir="ltr">On Tue, Oct 30, 2018 at 6:54 PM Alexander Belopolsky <<a href="mailto:alexander.belopolsky@gmail.com" target="_blank">alexander.belopolsky@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr">> In [12]: a= mdict(a=[2], b='a')<br>> In [13]: a+a<div><br></div><div>Aren't you reinventing the Counter type?</div><div><br></div></div></div></div></blockquote></div></div></div></div></blockquote><div>nop. It is an unintended subset of the possibilities.<br></div><div>I do have though<br></div><div>>>> c2 / 2<br>Out[17]: ACounter({'a': 0.5, 'b': 1.0})<br></div><div>>>> c / 2</div><div>TypeError: can't multiply sequence by non-int of type 'float'</div><div><br></div><div>And talking about Counter, by inheriting from the mixins of Vector (dot, abs, cos) we give it out of the box the cosine simlarities.</div></div><div class="gmail_quote"><br></div><div class="gmail_quote">Which given its wide use in textual indexation is pretty reassuring. It would also enable to normalize Counter (with value that supports truediv) easily by writing <br></div><div class="gmail_quote"><br></div><div class="gmail_quote">>>> class VCounter(LinearAlgebrae,Vector, Counter): pass<br>>>> c2 = VCounter(a=1, b=2)<br>>>> c2/abs(c2)<br>Out[20]: VCounter({'a': 0.4472135954999579, 'b': 0.8944271909999159})<br></div><div class="gmail_quote">And since it is mixins it touches nothing of the MutableMapping class it relies on. It just gives behaviours associated with operators.<br></div><div class="gmail_quote">(ofc c2.cos(c) willl normally raise a TypeError since it would have no sense)</div><div class="gmail_quote"><br></div><div class="gmail_quote">It really is a proof of concept of adding linear/vectorial algebrae to ANY kind of mutable mapping be it : dict, Counter, OrderedDict, defaultDict ...</div><div class="gmail_quote">It only relies on what mutableMapping (from abc) offers and does its life with it.<br></div><div class="gmail_quote"><br></div></div></div></div></div></div></div></div>