Skip to content

Commit 51ce008

Browse files
committed
Introduced MutableDenseMatrix and ImmutableDenseMatrix
1 parent 6c0febf commit 51ce008

File tree

2 files changed

+94
-26
lines changed

2 files changed

+94
-26
lines changed

symengine/lib/symengine_wrapper.pxd

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@ cdef class MatrixBase(object):
148148
cdef class DenseMatrix(MatrixBase):
149149
pass
150150

151+
cdef class MutableDenseMatrix(DenseMatrix):
152+
pass
153+
154+
cdef class ImmutableDenseMatrix(DenseMatrix):
155+
pass
156+
151157
cdef class Log(Function):
152158
pass
153159

symengine/lib/symengine_wrapper.pyx

Lines changed: 88 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1730,32 +1730,6 @@ cdef class DenseMatrix(MatrixBase):
17301730
else:
17311731
raise NotImplementedError
17321732

1733-
def row_join(self, rhs):
1734-
cdef DenseMatrix o = _sympify(rhs)
1735-
if self.rows != o.rows:
1736-
raise ShapeError("`self` and `rhs` must have the same number of rows.")
1737-
cdef DenseMatrix result = zeros(self.rows, self.cols + o.cols)
1738-
for i in range(self.rows):
1739-
for j in range(self.cols):
1740-
result[i, j] = self[i, j]
1741-
for i in range(o.rows):
1742-
for j in range(o.cols):
1743-
result[i, j + self.cols] = o[i, j]
1744-
return result
1745-
1746-
def col_join(self, bott):
1747-
cdef DenseMatrix o = _sympify(bott)
1748-
if self.cols != o.cols:
1749-
raise ShapeError("`self` and `rhs` must have the same number of columns.")
1750-
cdef DenseMatrix result = zeros(self.rows + o.rows, self.cols)
1751-
for i in range(self.rows):
1752-
for j in range(self.cols):
1753-
result[i, j] = self[i, j]
1754-
for i in range(o.rows):
1755-
for j in range(o.cols):
1756-
result[i + self.rows, j] = o[i, j]
1757-
return result
1758-
17591733
@property
17601734
def rows(self):
17611735
return self.nrows()
@@ -2080,6 +2054,94 @@ class DenseMatrixIter(object):
20802054

20812055
Matrix = DenseMatrix
20822056

2057+
cdef class MutableDenseMatrix(DenseMatrix):
2058+
2059+
def __cinit__(self, row=None, col=None, v=None):
2060+
super(MutableDenseMatrix, self).__cinit__(self, row, col, v)
2061+
2062+
def as_mutable(self):
2063+
return self.copy()
2064+
2065+
def row_join(self, rhs):
2066+
cdef DenseMatrix o = _sympify(rhs)
2067+
if self.rows != o.rows:
2068+
raise ShapeError("`self` and `rhs` must have the same number of rows.")
2069+
cdef DenseMatrix result = zeros(self.rows, self.cols + o.cols)
2070+
for i in range(self.rows):
2071+
for j in range(self.cols):
2072+
result[i, j] = self[i, j]
2073+
for i in range(o.rows):
2074+
for j in range(o.cols):
2075+
result[i, j + self.cols] = o[i, j]
2076+
return result
2077+
2078+
def col_join(self, bott):
2079+
cdef DenseMatrix o = _sympify(bott)
2080+
if self.cols != o.cols:
2081+
raise ShapeError("`self` and `rhs` must have the same number of columns.")
2082+
cdef DenseMatrix result = zeros(self.rows + o.rows, self.cols)
2083+
for i in range(self.rows):
2084+
for j in range(self.cols):
2085+
result[i, j] = self[i, j]
2086+
for i in range(o.rows):
2087+
for j in range(o.cols):
2088+
result[i + self.rows, j] = o[i, j]
2089+
return result
2090+
2091+
def col_del(self, i):
2092+
raise NotImplementedError
2093+
2094+
def col_op(self, j, f):
2095+
raise NotImplementedError
2096+
2097+
def col_swap(self, i, j):
2098+
for k in range(0, self.rows):
2099+
self[k, i], self[k, j] = self[k, j], self[k, i]
2100+
2101+
def copyin_list(self, key, value):
2102+
raise NotImplementedError
2103+
2104+
def copyin_matrix(self, key, value):
2105+
raise NotImplementedError
2106+
2107+
def fill(self, value):
2108+
raise NotImplementedError
2109+
2110+
def row_del(self, i):
2111+
raise NotImplementedError
2112+
2113+
def row_op(self, i, f):
2114+
raise NotImplementedError
2115+
2116+
def row_swap(self, i, j):
2117+
for k in range(0, self.cols):
2118+
self[i, k], self[j, k] = self[j, k], self[i, k]
2119+
2120+
def simplify(self, *args):
2121+
raise NotImplementedError
2122+
2123+
def zip_row_op(self, i, k, f):
2124+
raise NotImplementedError
2125+
2126+
2127+
cdef class ImmutableDenseMatrix(DenseMatrix):
2128+
2129+
def __cinit__(self, row=None, col=None, v=None):
2130+
super(ImmutableDenseMatrix, self).__cinit__(self, row, col, v)
2131+
2132+
def _entry(self, i, j):
2133+
return DenseMatrix.__getitem__(self, (i, j))
2134+
2135+
def __setitem__(self, key, value):
2136+
raise TypeError("Cannot set values of {}".format(self.__class__))
2137+
2138+
def set(self, i, j, e):
2139+
raise TypeError("Cannot set values of {}".format(self.__class__))
2140+
2141+
def _set(self, i, j, e):
2142+
raise TypeError("Cannot set values of {}".format(self.__class__))
2143+
2144+
20832145
cdef matrix_to_vec(DenseMatrix d, symengine.vec_basic& v):
20842146
cdef Basic e_
20852147
for i in range(d.nrows()):

0 commit comments

Comments
 (0)