Added element-wise exponentiation to dense NMatrix #106
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit adds element-wise exponentiation to dense NMatrices through
the
**
operator. For example:I think I changed all the relevant places, but I'm pretty sure there
are some cases in which my implementation will blow up. For one, I'm not
taking care of the resulting NMatrix's dtype, leaving it the same as the
left side NMatrix.
The problem with this is that, even if my NMatrix is :int64, I can have
a floating-point exponent, e.g.
NMatrix.new(2, 3) ** 3.14
. Thesolution probably involves doing some checks before delegating the
calculation to ew_op_switch() (see dense.cpp#772).
Can anybody see more problems with this implementation? I want to fix
the issues with element-wise operations in list matrices (#42) and
implement the operations still needed, i.e. modulo and exponentiation.
For this, I need more experience dealing with these parts of NMatrix. :)
I'm sure there's a way to cleanup the codebase a bit regarding this as
well.
There are some changes that are related to spacing (removing tabs for
true spaces). They shouldn't hamper this PR's legibility and are a Good
Thing for the project, so let's leave them here. Also, some places of
the codebase need a bit more of care & love regarding comment
positioning and spacing, but that's a discussion for another day...
(yes, it's compiling and passing the new spec with
rake compile && rake spec
)