in reply to In PDL, how to raise a matrix $m to a power $v

See mpow. On the plus side, it allows strange but probably amazing additional things -- fractional powers, or (reading source) power being not scalar but another matrix. On the minus side, see this comment. For familiar integer powers, it does O(n) loop (line 544). And it's buggy: if power is 0, same matrix is returned (as if power was 1). To fix, replace line 539 with $ret = identity($m); and start loop (line 544) from 0. And use PDL::MatrixOps qw/identity/; somewhere. But formally, yes, such function does exist.

Replies are listed 'Best First'.
Re^2: In PDL, how to raise a matrix $m to a power $v
by etj (Priest) on May 02, 2022 at 18:31 UTC
    Good catch! I've fixed this in https://github.com/PDLPorters/pdl-linearalgebra/commit/a2d680992c1cd4a46a3009b8ae0b2f3e6ebf601e. In fact, to aid broadcasting, I used (using two PDL::LinearAlgebra utility functions recently added):
    my $di = $_[0]->dims_internal; my @dims = $m->dims; # ... $ret = identity($dims[$di]); $ret = $ret->r2C if $m->_is_complex;
    This has now been released as 0.30.

    Please do report problems like this at https://github.com/PDLPorters/pdl-linearalgebra/issues, we really do care! As an example, #10 (the wrapper functions didn't work on native complex, though the underlying LAPACK-bindings did) turned into a bit of a death-march because it revealed lots of copy-paste (~6800 lines ended up as ~3400), and very minimal tests. But I felt this module was important enough to justify the effort.