<s> import core . modules <EOL> import core . modules . module_registry <EOL> from core . modules . vistrails_module import Module , ModuleError <EOL> import scipy <EOL> import numpy <EOL> from scipy import sparse <EOL> from Array import * <EOL> class MatrixModule ( object ) : <EOL> my_namespace = '<STR_LIT>' <EOL> class MatrixOp ( object ) : <EOL> my_namespace = '<STR_LIT>' <EOL> class Matrix ( MatrixModule , Module ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> Module . __init__ ( self ) <EOL> self . matrix = None <EOL> def get_shape ( self ) : <EOL> return self . matrix . shape <EOL> def get_conjugate ( self ) : <EOL> return self . matrix . conjugate ( ) <EOL> def get_column ( self , colId ) : <EOL> return self . matrix . getcol ( colId ) <EOL> def get_row ( self , rowId ) : <EOL> return self . matrix . getrow ( rowId ) <EOL> def set_diagonal ( self , vals ) : <EOL> self . matrix . setdiag ( vals ) <EOL> def toarray ( self ) : <EOL> return self . matrix . toarray ( ) <EOL> def transpose ( self ) : <EOL> return self . matrix . transpose ( ) <EOL> def get_num_elements ( self ) : <EOL> return self . matrix . getnnz ( ) <EOL> def get_max_elements ( self ) : <EOL> return self . matrix . nzmax <EOL> def get_reals ( self ) : <EOL> return self . matrix . _real ( ) <EOL> def get_imaginaries ( self ) : <EOL> return self . matrix . _imag ( ) <EOL> def get_matrix ( self ) : <EOL> return self . matrix <EOL> def set_matrix ( self , mat ) : <EOL> self . matrix = mat <EOL> class MatrixMultiply ( MatrixOp , Module ) : <EOL> """<STR_LIT>""" <EOL> def compute ( self ) : <EOL> a = self . get_input ( "<STR_LIT>" ) <EOL> b = self . get_input ( "<STR_LIT>" ) <EOL> out = Matrix ( ) <EOL> out . set_matrix ( a . get_matrix ( ) * b . get_matrix ( ) ) <EOL> self . set_output ( "<STR_LIT>" , out ) <EOL> @ classmethod <EOL> def register ( cls , reg , basic ) : <EOL> reg . add_module ( cls , namespace = cls . my_namespace ) <EOL> reg . add_input_port ( cls , "<STR_LIT>" , ( Matrix , '<STR_LIT>' ) ) <EOL> reg . add_input_port ( cls , "<STR_LIT>" , ( Matrix , '<STR_LIT>' ) ) <EOL> reg . add_output_port ( cls , "<STR_LIT>" , ( Matrix , '<STR_LIT>' ) ) <EOL> class MatrixConjugate ( MatrixOp , Module ) : <EOL> """<STR_LIT>""" <EOL> def compute ( self ) : <EOL> a = self . get_input ( "<STR_LIT>" ) <EOL> b = a . get_conjugate ( ) . copy ( ) <EOL> out = Matrix ( ) <EOL> out . set_matrix ( b ) <EOL> self . set_output ( "<STR_LIT>" , out ) <EOL> @ classmethod <EOL> def register ( cls , reg , basic ) : <EOL> reg . add_module ( cls , namespace = cls . my_namespace ) <EOL> reg . add_input_port ( cls , "<STR_LIT>" , ( Matrix , '<STR_LIT>' ) ) <EOL> reg . add_output_port ( cls , "<STR_LIT>" , ( Matrix , '<STR_LIT>' ) ) <EOL> class MatrixToArray ( MatrixOp , Module ) : <EOL> """<STR_LIT>""" <EOL> def compute ( self ) : <EOL> m = self . get_input ( "<STR_LIT>" ) <EOL> a = m . toarray ( ) <EOL> out = NDArray ( ) <EOL> out . set_array ( a ) <EOL> self . set_output ( "<STR_LIT>" , out ) <EOL> @ classmethod <EOL> def register ( cls , reg , basic ) : <EOL> reg . add_module ( cls , namespace = cls . my_namespace ) <EOL> reg . add_input_port ( cls , "<STR_LIT>" , ( Matrix , '<STR_LIT>' ) ) <EOL> reg . add_output_port ( cls , "<STR_LIT>" , ( NDArray , '<STR_LIT>' ) ) </s>
