提交 72144cf9 authored 作者: turian@grenat.iro.umontreal.ca's avatar turian@grenat.iro.umontreal.ca

Merge

...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
# The list of objects to document. Objects can be named using # The list of objects to document. Objects can be named using
# dotted names, module filenames, or package directory names. # dotted names, module filenames, or package directory names.
# Alases for this option include "objects" and "values". # Alases for this option include "objects" and "values".
modules: *.py, gof/*.py, scipy, numpy modules: *.py, gof/*.py, joseph/*.py, tlearn/*.py, scipy, numpy
# The type of output that should be generated. Should be one # The type of output that should be generated. Should be one
# of: html, text, latex, dvi, ps, pdf. # of: html, text, latex, dvi, ps, pdf.
...@@ -135,7 +135,7 @@ dotpath: /usr/bin/dot ...@@ -135,7 +135,7 @@ dotpath: /usr/bin/dot
# The name of one or more pstat files (generated by the profile # The name of one or more pstat files (generated by the profile
# or hotshot module). These are used to generate call graphs. # or hotshot module). These are used to generate call graphs.
#pstat: sparse.pstat pstat: autotest.pstat
# Specify the font used to generate Graphviz graphs. # Specify the font used to generate Graphviz graphs.
# (e.g., helvetica or times). # (e.g., helvetica or times).
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
# The list of objects to document. Objects can be named using # The list of objects to document. Objects can be named using
# dotted names, module filenames, or package directory names. # dotted names, module filenames, or package directory names.
# Alases for this option include "objects" and "values". # Alases for this option include "objects" and "values".
modules: *.py, gof/*.py modules: *.py, gof/*.py, joseph/*.py, tlearn/*.py
# The type of output that should be generated. Should be one # The type of output that should be generated. Should be one
# of: html, text, latex, dvi, ps, pdf. # of: html, text, latex, dvi, ps, pdf.
...@@ -135,7 +135,7 @@ dotpath: /usr/bin/dot ...@@ -135,7 +135,7 @@ dotpath: /usr/bin/dot
# The name of one or more pstat files (generated by the profile # The name of one or more pstat files (generated by the profile
# or hotshot module). These are used to generate call graphs. # or hotshot module). These are used to generate call graphs.
#pstat: sparse.pstat pstat: autotest.pstat
# Specify the font used to generate Graphviz graphs. # Specify the font used to generate Graphviz graphs.
# (e.g., helvetica or times). # (e.g., helvetica or times).
......
#!/bin/sh #!/bin/sh
# python -m profile -o autotest.pstat autotest.py
epydoc --config epydoc-fast epydoc --config epydoc-fast
#!/bin/sh #!/bin/sh
python -m profile -o autotest.pstat autotest.py
epydoc --config epydoc epydoc --config epydoc
...@@ -17,7 +17,7 @@ __all__ = ['Op', ...@@ -17,7 +17,7 @@ __all__ = ['Op',
def constructor(op_cls): def constructor(op_cls):
"""Make an Op look like a Result-valued function.""" """Make an Op look like a L{Result}-valued function."""
def f(*args, **kwargs): def f(*args, **kwargs):
op = op_cls(*args, **kwargs) op = op_cls(*args, **kwargs)
if len(op.outputs) > 1: if len(op.outputs) > 1:
...@@ -28,12 +28,12 @@ def constructor(op_cls): ...@@ -28,12 +28,12 @@ def constructor(op_cls):
class Op(object): class Op(object):
""" """
Op represents a computation on the storage in its 'inputs' slot, L{Op} represents a computation on the storage in its 'inputs' slot,
the results of which are stored in the Result instances in the the results of which are stored in the L{Result} instances in the
'outputs' slot. The owner of each Result in the outputs list must 'outputs' slot. The owner of each L{Result} in the outputs list must
be set to this Op and thus any Result instance is in the outputs be set to this L{Op} and thus any L{Result} instance is in the outputs
list of at most one Op, its owner. It is the responsibility of the list of at most one L{Op}, its owner. It is the responsibility of the
Op to ensure that it owns its outputs and it is encouraged (though L{Op} to ensure that it owns its outputs and it is encouraged (though
not required) that it creates them. not required) that it creates them.
""" """
......
...@@ -9,7 +9,12 @@ import tensor ...@@ -9,7 +9,12 @@ import tensor
# Wrapper type # Wrapper type
def assparse(sp, **kwargs): def assparse(sp, **kwargs):
"""Return SparseR version of sp""" """
Wrapper around SparseR constructor.
@param sp: A sparse matrix. assparse reads dtype and format properties
out of this sparse matrix.
@return: SparseR version of sp.
"""
if isinstance(sp, SparseR): if isinstance(sp, SparseR):
return sp return sp
else: else:
...@@ -37,6 +42,13 @@ class SparseR(gof.result.ResultBase): ...@@ -37,6 +42,13 @@ class SparseR(gof.result.ResultBase):
dtype_set = set(['int', 'int32', 'int64', 'float32', 'float64']) dtype_set = set(['int', 'int32', 'int64', 'float32', 'float64'])
def __init__(self, dtype, format, **kwargs): def __init__(self, dtype, format, **kwargs):
"""
Fundamental way to do create a sparse node.
@param dtype: Type of numbers in the matrix.
@param format: The sparse storage strategy.
@return An empty SparseR instance.
"""
gof.ResultBase.__init__(self, **kwargs) gof.ResultBase.__init__(self, **kwargs)
if dtype in SparseR.dtype_set: if dtype in SparseR.dtype_set:
self._dtype = dtype self._dtype = dtype
...@@ -165,8 +177,10 @@ if 0: ...@@ -165,8 +177,10 @@ if 0:
def gen_outputs(self): return [SparseR()] def gen_outputs(self): return [SparseR()]
def impl(x,y): def impl(x,y):
if hasattr(x, 'getnnz'): if hasattr(x, 'getnnz'):
# if x is sparse, then do this.
return x.dot(y) return x.dot(y)
else: else:
# if x is dense (and y is sparse), we do this
return y.transpose().dot(x.transpose()).transpose() return y.transpose().dot(x.transpose()).transpose()
def grad(self, x, y, gz): def grad(self, x, y, gz):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论