SciRuby/nmatrix — pull request #106 by agarie (2013-07-19 02:42:54+00:00)
Title: Added element-wise exponentiation to dense NMatrix

This commit adds element-wise exponentiation to dense NMatrices through
the `**` operator. For example:

n = NMatrix.new(:dense, 2, [1, 2, 3, 4], :float64)
n = n ** 2
# n will be [1, 4, 9, 16]

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`. The
solution 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`)