I'd suggest PDL is the ultimate operator-overloader "source of truth". Mutating overloads is implemented in PDL::Ops, specifically (
https://github.com/PDLPorters/pdl/blob/ad2783ad4b00583f14af3a3c24a93bb9f1a4ff33/Basic/Ops/ops.pd#L191-L196):
$ret .= pp_line_numbers(__LINE__, <<EOF) if $mutator;
BEGIN {
# in1, in2, out, swap if true
\$OVERLOADS{'$op='} = sub { PDL::$name(\$_[0]->inplace, \$_[1]); \$_[0
+] };
}
EOF
Modifying the generated code for
+= to this:
#line 192 "ops.pd"
BEGIN {
# in1, in2, out, swap if true
$OVERLOADS{'+='} = sub {
use Carp; use Test::More; diag "RUN ", Test::More::explain \@_;
PDL::plus($_[0]->inplace, $_[1]); $_[0] };
}
and running it like this:
$ perl -MPDL -e '$p=pdl(1); $p+=2'
gives:
# RUN [
# bless( do{\(my $o = '94749946365136')}, 'PDL' ),
# 2,
# undef
# ]
so your XS function should work. Did you make an overload for
+=?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.