@@ -2506,31 +2506,38 @@ cdef class DenseMatrixBase(MatrixBase):
2506
2506
if self .rows != o.rows:
2507
2507
raise ShapeError(" `self` and `rhs` must have the same number of rows." )
2508
2508
cdef DenseMatrixBase result = self .__class__ (self .rows, self .cols + o.cols)
2509
- cdef Basic e_
2510
- for i in range (self .rows):
2511
- for j in range (self .cols):
2512
- e_ = self ._get(i, j)
2513
- deref(result.thisptr).set(i, j, e_.thisptr)
2514
- for i in range (o.rows):
2515
- for j in range (o.cols):
2516
- e_ = sympify(o._get(i, j))
2517
- deref(result.thisptr).set(i, j + self .cols, e_.thisptr)
2509
+ symengine.row_join(deref(symengine.static_cast_DenseMatrix(self .thisptr)),
2510
+ deref(symengine.static_cast_DenseMatrix(o.thisptr)),
2511
+ deref(symengine.static_cast_DenseMatrix(result.thisptr)))
2518
2512
return result
2519
2513
2520
2514
def col_join (self , bott ):
2521
2515
cdef DenseMatrixBase o = sympify(bott)
2522
2516
if self .cols != o.cols:
2523
2517
raise ShapeError(" `self` and `rhs` must have the same number of columns." )
2524
2518
cdef DenseMatrixBase result = self .__class__ (self .rows + o.rows, self .cols)
2525
- cdef Basic e_
2526
- for i in range (self .rows):
2527
- for j in range (self .cols):
2528
- e_ = self ._get(i, j)
2529
- deref(result.thisptr).set(i, j, e_.thisptr)
2530
- for i in range (o.rows):
2531
- for j in range (o.cols):
2532
- e_ = sympify(o._get(i, j))
2533
- deref(result.thisptr).set(i + self .rows, j, e_.thisptr)
2519
+ symengine.col_join(deref(symengine.static_cast_DenseMatrix(self .thisptr)),
2520
+ deref(symengine.static_cast_DenseMatrix(o.thisptr)),
2521
+ deref(symengine.static_cast_DenseMatrix(result.thisptr)))
2522
+ return result
2523
+
2524
+ def dot (self , b ):
2525
+ cdef DenseMatrixBase o = sympify(b)
2526
+ cdef DenseMatrixBase result = self .__class__ (self .rows, self .cols)
2527
+ symengine.dot(deref(symengine.static_cast_DenseMatrix(self .thisptr)),
2528
+ deref(symengine.static_cast_DenseMatrix(o.thisptr)),
2529
+ deref(symengine.static_cast_DenseMatrix(result.thisptr)))
2530
+ return result
2531
+
2532
+ def cross (self , b ):
2533
+ cdef DenseMatrixBase o = sympify(b)
2534
+ if self .cols * self .rows != 3 or o.cols * o.rows != 3 :
2535
+ raise ShapeError(" Dimensions incorrect for cross product: %s x %s " %
2536
+ ((self .rows, self .cols), (b.rows, b.cols)))
2537
+ cdef DenseMatrixBase result = self .__class__ (self .rows, self .cols)
2538
+ symengine.cross(deref(symengine.static_cast_DenseMatrix(self .thisptr)),
2539
+ deref(symengine.static_cast_DenseMatrix(o.thisptr)),
2540
+ deref(symengine.static_cast_DenseMatrix(result.thisptr)))
2534
2541
return result
2535
2542
2536
2543
@property
@@ -2864,17 +2871,33 @@ class DenseMatrixBaseIter(object):
2864
2871
cdef class MutableDenseMatrix(DenseMatrixBase):
2865
2872
2866
2873
def col_swap (self , i , j ):
2867
- for k in range ( 0 , self .rows):
2868
- self [k, i], self [k, j] = self [k, j], self [k, i]
2874
+ symengine.column_exchange_dense(deref(symengine.static_cast_DenseMatrix( self .thisptr)),
2875
+ i, j)
2869
2876
2870
2877
def fill (self , value ):
2871
2878
for i in range (self .rows):
2872
2879
for j in range (self .cols):
2873
2880
self [i, j] = value
2874
2881
2875
2882
def row_swap (self , i , j ):
2876
- for k in range (0 , self .cols):
2877
- self [i, k], self [j, k] = self [j, k], self [i, k]
2883
+ symengine.row_exchange_dense(deref(symengine.static_cast_DenseMatrix(self .thisptr)),
2884
+ i, j)
2885
+
2886
+ def row_del (self , i ):
2887
+ if i < - self .rows or i >= self .rows:
2888
+ raise IndexError (" Index out of range: 'i = %s ', valid -%s <= i"
2889
+ " < %s " % (i, self .rows, self .rows))
2890
+ if i < 0 :
2891
+ i += self .rows
2892
+ symengine.row_del(deref(symengine.static_cast_DenseMatrix(self .thisptr)), i)
2893
+
2894
+ def col_del (self , i ):
2895
+ if i < - self .cols or i >= self .cols:
2896
+ raise IndexError (" Index out of range: 'i=%s ', valid -%s <= i < %s "
2897
+ % (i, self .cols, self .cols))
2898
+ if i < 0 :
2899
+ i += self .cols
2900
+ symengine.col_del(deref(symengine.static_cast_DenseMatrix(self .thisptr)), i)
2878
2901
2879
2902
def _applyfunc (self , f ):
2880
2903
cdef int nr = self .nrows()
0 commit comments