Changeset 721

Show
Ignore:
Timestamp:
08/09/10 13:04:56 (1 year ago)
Author:
dmitrey
Message:

some FD changes

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • PythonPackages/FuncDesigner/FuncDesigner/ooFun.py

    r720 r721  
    2222    SparseMatrixConstructor = lambda *args, **kwargs: scipy.sparse.lil_matrix(*args, **kwargs) 
    2323    from scipy import sparse 
    24     from scipy.sparse import hstack as HstackSP 
     24    from scipy.sparse import hstack as HstackSP, isspmatrix_csc, isspmatrix_csr 
    2525    def Hstack(Tuple): 
    2626        ind = where([isscalar(elem) or prod(elem.shape)!=0 for elem in Tuple])[0].tolist() 
     
    728728                        else: 
    729729                            t1, t2 = self._considerSparse(t1, val) 
    730                         if t1.ndim > 1 or t2.ndim > 1: 
    731                             # warning! t1,t2 can be sparse matrices, so I don't use t = atleast_2d(t) directly 
    732                             if t2.ndim < 2:  
    733                                 assert t1.ndim > 1, 'error in FuncDesigner kernel, inform developers' 
    734                                 if t1.shape[1] != t2.shape[0]: 
    735                                     t2 = t2.reshape(1, -1) 
    736                         else: 
    737                             # hence these are ndarrays 
    738                             if self._getFuncCalcEngine(x).size > 1: 
    739                                 t1 = t1.reshape(-1, 1) 
    740                                 t2 = t2.reshape(1, -1) 
    741                             else: 
    742                                 t1 = t1.reshape(1, -1) 
    743                                 t2 = t2.reshape(-1, 1) 
     730#                        if t1.ndim > 1 or t2.ndim > 1: 
     731#                            # warning! t1,t2 can be sparse matrices, so I don't use t = atleast_2d(t) directly 
     732#                            if t2.ndim < 2:  
     733#                                #assert t1.ndim > 1, 'error in FuncDesigner kernel, inform developers' 
     734#                                if t1.shape[1] != t2.shape[0]: 
     735#                                    t2 = t2.reshape(1, -1) 
     736#                        else: 
     737#                            # hence these are ndarrays 
     738#                            if self._getFuncCalcEngine(x).size > 1: 
     739#                                t1 = t1.reshape(-1, 1) 
     740#                                t2 = t2.reshape(1, -1) 
     741#                            else: 
     742#                                t1 = t1.reshape(1, -1) 
     743#                                t2 = t2.reshape(-1, 1) 
    744744                         
    745                         if not (isinstance(t1,  ndarray) and isinstance(t2,  ndarray))
     745                        if not type(t1) == type(t2) ==  ndarray
    746746                            # CHECKME: is it trigger somewhere? 
    747747                            if not scipyInstalled: 
    748748                                self.pWarn(scipyAbsentMsg) 
    749                                 rr = atleast_1d(dot(t1, t2)
     749                                rr = dot(t1, t2
    750750                            else: 
    751                                 t1 = t1 if isinstance(t1, scipy.sparse.csc_matrix) else t1.tocsc() if isspmatrix(t1)  else scipy.sparse.csc_matrix(t1) 
    752                                 t2 = t2 if isinstance(t2, scipy.sparse.csr_matrix) else t2.tocsr() if isspmatrix(t2)  else scipy.sparse.csr_matrix(t2) 
     751                                t1 = t1 if isspmatrix_csc(t1) else t1.tocsc() if isspmatrix(t1)  else scipy.sparse.csc_matrix(t1) 
     752                                t2 = t2 if isspmatrix_csr(t2) else t2.tocsr() if isspmatrix(t2)  else scipy.sparse.csr_matrix(t2) 
    753753                                if t2.shape[0] != t1.shape[1]: 
    754754                                    if t2.shape[1] == t1.shape[1]: 
     
    760760                                    rr = rr.toarray()  
    761761                        else: 
    762                             rr = atleast_1d(dot(t1, t2)
     762                            rr = dot(t1, t2
    763763                    #assert rr.ndim>1 
    764764                         
     
    775775                        r[key] = rr 
    776776         
    777         dp = dict([(key, Copy(value)) for key, value in r.items()]) 
    778          
    779         self._d_val_prev = dp 
     777        self._d_val_prev = dict([(key, Copy(value)) for key, value in r.items()]) 
    780778        self._d_key_prev = dict([(elem, Copy(x[elem])) for elem in dep]) if involveStore else None 
    781779        return r