@@ -1798,26 +1798,32 @@ cdef class DenseMatrixBase(MatrixBase):
1798
1798
cdef DenseMatrixBase o = _sympify(rhs)
1799
1799
if self .rows != o.rows:
1800
1800
raise ShapeError(" `self` and `rhs` must have the same number of rows." )
1801
- cdef DenseMatrixBase result = zeros(self .rows, self .cols + o.cols)
1801
+ cdef DenseMatrixBase result = self .__class__ (self .rows, self .cols + o.cols)
1802
+ cdef Basic e_
1802
1803
for i in range (self .rows):
1803
1804
for j in range (self .cols):
1804
- result[i, j] = self [i, j]
1805
+ e_ = self ._get(i, j)
1806
+ deref(result.thisptr).set(i, j, e_.thisptr)
1805
1807
for i in range (o.rows):
1806
1808
for j in range (o.cols):
1807
- result[i, j + self .cols] = o[i, j]
1809
+ e_ = _sympify(o._get(i, j))
1810
+ deref(result.thisptr).set(i, j + self .cols, e_.thisptr)
1808
1811
return result
1809
1812
1810
1813
def col_join (self , bott ):
1811
1814
cdef DenseMatrixBase o = _sympify(bott)
1812
1815
if self .cols != o.cols:
1813
1816
raise ShapeError(" `self` and `rhs` must have the same number of columns." )
1814
- cdef DenseMatrixBase result = zeros(self .rows + o.rows, self .cols)
1817
+ cdef DenseMatrixBase result = self .__class__ (self .rows + o.rows, self .cols)
1818
+ cdef Basic e_
1815
1819
for i in range (self .rows):
1816
1820
for j in range (self .cols):
1817
- result[i, j] = self [i, j]
1821
+ e_ = self ._get(i, j)
1822
+ deref(result.thisptr).set(i, j, e_.thisptr)
1818
1823
for i in range (o.rows):
1819
1824
for j in range (o.cols):
1820
- result[i + self .rows, j] = o[i, j]
1825
+ e_ = _sympify(o._get(i, j))
1826
+ deref(result.thisptr).set(i + self .rows, j, e_.thisptr)
1821
1827
return result
1822
1828
1823
1829
@property
@@ -1937,16 +1943,16 @@ cdef class DenseMatrixBase(MatrixBase):
1937
1943
def T (self ):
1938
1944
return self .transpose()
1939
1945
1940
- def _applyfunc (self , f ):
1946
+ def applyfunc (self , f ):
1947
+ cdef DenseMatrixBase out = self .__class__ (self )
1941
1948
cdef int nr = self .nrows()
1942
1949
cdef int nc = self .ncols()
1950
+ cdef Basic e_;
1943
1951
for i in range (nr):
1944
1952
for j in range (nc):
1945
- self ._set(i, j, f(self ._get(i, j)))
1946
-
1947
- def applyfunc (self , f ):
1948
- cdef DenseMatrixBase out = self .__class__ (self )
1949
- out._applyfunc(f)
1953
+ e_ = _sympify(f(self ._get(i, j)))
1954
+ if e_ is not None :
1955
+ deref(out.thisptr).set(i, j, e_.thisptr)
1950
1956
return out
1951
1957
1952
1958
def msubs (self , *args ):
@@ -2160,6 +2166,12 @@ cdef class MutableDenseMatrix(DenseMatrixBase):
2160
2166
for k in range (0 , self .cols):
2161
2167
self [i, k], self [j, k] = self [j, k], self [i, k]
2162
2168
2169
+ def _applyfunc (self , f ):
2170
+ cdef int nr = self .nrows()
2171
+ cdef int nc = self .ncols()
2172
+ for i in range (nr):
2173
+ for j in range (nc):
2174
+ self ._set(i, j, f(self ._get(i, j)))
2163
2175
2164
2176
Matrix = DenseMatrix = MutableDenseMatrix
2165
2177
0 commit comments