提交 60b10b99 authored 作者: james@X40's avatar james@X40

adding a global dot function to __init__.py

上级 f0c64a36
...@@ -123,3 +123,23 @@ def __src_version__(): ...@@ -123,3 +123,23 @@ def __src_version__():
return __src_version__.rval return __src_version__.rval
### This is defined here because it is designed to work across symbolic datatypes
# (Sparse and Tensor)
def dot(l, r):
"""Return a symbolic matrix/dot product between l and r """
rval = NotImplemented
if rval == NotImplemented and hasattr(l, '__dot__'):
try:
rval = l.__dot__(r)
except Exception, e0:
rval = NotImplemented
if rval == NotImplemented and hasattr(r, '__rdot__'):
try:
rval = r.__rdot__(l)
except Exception, e1:
rval = NotImplemented
if rval == NotImplemented:
raise NotImplementedError("Dot failed for the following reaons:", (e0, e1))
return rval
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论