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
|
# Commands
|
||||||
all: lint test
|
all: lint test
|
||||||
test: unit
|
test: unit
|
||||||
publish: upload clean
|
publish: lint test upload clean
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf *.egg-info .pytest_cache build dist
|
rm -rf *.egg-info .pytest_cache build dist
|
||||||
|
|
|
@ -6,6 +6,10 @@
|
||||||
#
|
#
|
||||||
import math
|
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):
|
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)
|
weight = key(v)
|
||||||
xx += weight ** 2
|
xx += weight ** 2
|
||||||
|
|
||||||
if k in B:
|
v2 = B.get(k)
|
||||||
xy += weight * key(B[k])
|
|
||||||
|
if v2 is not None:
|
||||||
|
xy += weight * key(v2)
|
||||||
|
|
||||||
for v in B.values():
|
for v in B.values():
|
||||||
weight = key(v)
|
weight = key(v)
|
||||||
|
|
Loading…
Reference in New Issue