mirror of https://github.com/Yomguithereal/fog.git
Saving one lookup
This commit is contained in:
parent
775d02a6a4
commit
c1b5e732c1
2
Makefile
2
Makefile
|
@ -4,7 +4,7 @@ SOURCE = fog
|
|||
# Commands
|
||||
all: lint test
|
||||
test: unit
|
||||
publish: upload clean
|
||||
publish: lint test upload clean
|
||||
|
||||
clean:
|
||||
rm -rf *.egg-info .pytest_cache build dist
|
||||
|
|
|
@ -6,6 +6,10 @@
|
|||
#
|
||||
import math
|
||||
|
||||
# TODO: test one of the two counters is empty
|
||||
# TODO: test both are empty
|
||||
# TODO: test 1 dimension (identical + different)
|
||||
|
||||
|
||||
def sparse_cosine_similarity(A, B, key=lambda x: x):
|
||||
"""
|
||||
|
@ -35,8 +39,10 @@ def sparse_cosine_similarity(A, B, key=lambda x: x):
|
|||
weight = key(v)
|
||||
xx += weight ** 2
|
||||
|
||||
if k in B:
|
||||
xy += weight * key(B[k])
|
||||
v2 = B.get(k)
|
||||
|
||||
if v2 is not None:
|
||||
xy += weight * key(v2)
|
||||
|
||||
for v in B.values():
|
||||
weight = key(v)
|
||||
|
|
Loading…
Reference in New Issue