Skip to content

Conversation

@ShikharJ
Copy link
Member

@ShikharJ ShikharJ commented Jun 3, 2017

Relevant: #147

@isuruf
Copy link
Member

isuruf commented Jun 3, 2017

It's better to fix applyfunc than to allow ImmutableMatrix to be mutable like this.

@ShikharJ ShikharJ force-pushed the _set branch 2 times, most recently from 2fef6d3 to cbb74fc Compare June 3, 2017 12:46
@ShikharJ ShikharJ changed the title Removed _set from ImmutableMatrix Removed the use of _set from _applyfunc Jun 3, 2017
self._set(i, j, f(self._get(i, j)))
e_ = _sympify(f(self._get(i, j)))
if e_ is not None:
deref(self.thisptr).set(i, j, e_.thisptr)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Above method would still allow an ImmutableMatrix to be mutated from python. You can copy the code from here and move it to applyfunc and move _applyfunc to MutableDenseMatrix.

raise ShapeError("`self` and `rhs` must have the same number of columns.")
cdef DenseMatrixBase result = zeros(self.rows + o.rows, self.cols)
cdef DenseMatrixBase result = self.__class__(self)
deref(symengine.static_cast_DenseMatrix(result.thisptr)).resize(self.rows + o.rows, self.cols)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the above 2 lines to cdef DenseMatrixBase result = self.__class__(self.rows, self.cols). This avoids the copy in the first line.

@ShikharJ ShikharJ force-pushed the _set branch 3 times, most recently from 246cfc1 to 2a56b82 Compare June 3, 2017 20:28
@ShikharJ
Copy link
Member Author

ShikharJ commented Jun 4, 2017

Ping @isuruf.

@ShikharJ ShikharJ changed the title Removed the use of _set from _applyfunc Improvements for ImmutableMatrix Jun 4, 2017
for k in range(0, self.cols):
self[i, k], self[j, k] = self[j, k], self[i, k]

def applyfunc(self, f):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the difference between this function and the one above?

We'd also need a _applyfunc in MutableDenseMatrix that modifies it in place.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one uses the python defined method _set. The implementation above directly uses C++ method.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, but what's the difference in the functionality?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None other than that, I'll change this to an in-place _applyfunc.

for i in range(self.rows):
for j in range(self.cols):
result[i, j] = self[i, j]
e_ = _sympify(self._get(i, j))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_sympify is unnecessary here.

@isuruf isuruf merged commit 4c73dc4 into symengine:master Jun 4, 2017
@isuruf
Copy link
Member

isuruf commented Jun 4, 2017

Thanks for the PR

@ShikharJ ShikharJ deleted the _set branch June 4, 2017 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants