CSx = CSC mul_s_d_csx = mul_s_d_csc elif svar.type.format == 'csr': CSx = CSR mul_s_d_csx = mul_s_d_csr else: raise NotImplemented() c_data = mul_s_d_csx(csm_data(svar), csm_indices(svar), csm_indptr(svar), dvar) return [CSx(c_data, csm_indices(svar), csm_indptr(svar), csm_shape(svar))] return False register_specialize(local_mul_s_d) class MulSDCSC(gof.Op): def __eq__(self, other): return (type(self) == type(other)) def __hash__(self): return hash(type(self)) def make_node(self, a_data, a_indices, a_indptr, b): assert b.type.ndim == 2 return gof.Apply(self, [a_data, a_indices, a_indptr, b], [tensor.tensor(b.dtype, (False,))]) #def perform(self, node, (a_data, a_indices, a_indptr, b), (out,)):
# This is tested in tests/test_opt.py:test_local_csm_properties_csm @gof.local_optimizer([csm_properties]) def local_csm_properties_csm(node): """if we find csm_properties(CSM(*args)), then we can replace that with the *args directly""" if node.op == csm_properties: csm, = node.inputs if csm.owner and (csm.owner.op == CSC or csm.owner.op == CSR): # csm.owner.inputs could be broadcastable. In that case, we have # to adjust the broadcasting flag here. ret_var = [theano.tensor.patternbroadcast(i, o.broadcastable) for i, o in izip(csm.owner.inputs, node.outputs)] return ret_var return False sparse.register_specialize(local_csm_properties_csm) # This is tested in tests/test_basic.py:test_remove0 @gof.local_optimizer([None]) def local_inplace_remove0(node): """ Optimization to insert inplace versions of Remove0. """ if isinstance(node.op, sparse.Remove0) and not node.op.inplace: new_op = node.op.__class__(inplace=True) new_node = new_op(*node.inputs) return [new_node] return False theano.compile.optdb.register('local_inplace_remove0', gof.TopoOptimizer(local_inplace_remove0,
CSx = CSR mul_s_d_csx = mul_s_d_csr else: raise NotImplemented() c_data = mul_s_d_csx(csm_data(svar), csm_indices(svar), csm_indptr(svar), dvar) return [ CSx(c_data, csm_indices(svar), csm_indptr(svar), csm_shape(svar)) ] return False register_specialize(local_mul_s_d) class MulSDCSC(gof.Op): def __eq__(self, other): return (type(self) == type(other)) def __hash__(self): return hash(type(self)) def make_node(self, a_data, a_indices, a_indptr, b): assert b.type.ndim == 2 return gof.Apply(self, [a_data, a_indices, a_indptr, b], [tensor.tensor(b.dtype, (False, ))]) def c_code_cache_version(self):