Skip to content
This repository was archived by the owner on Nov 17, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/api/python/ndarray/sparse.md
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,8 @@ We summarize the interface for each class in the following sections.
elemwise_add
elemwise_sub
elemwise_mul
broadcast_mul
broadcast_div
negative
dot
add_n
Expand Down
90 changes: 90 additions & 0 deletions perl-package/AI-MXNet/lib/AI/MXNet/NDArray/Sparse.pm
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,100 @@ use overload '""' => sub {
my $shape_info = join('x', @{ $self->shape });
sprintf("\n<%s, %s @%s>", $self->_class_name, $shape_info, $self->context);
},
'+' => \&add,
'-' => \&subtract,
'*' => \&multiply,
'/' => \&divide,
'+=' => \&not_implemented,
'-=' => \&not_implemented,
'*=' => \&not_implemented,
'/=' => \&not_implemented;

method add(AI::MXNet::NDArray|Num $other, $reverse=)
{
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I really appreciate your fast response @sergeykolychev thanks for unblocking us. While I'm not a perl user but some documentations for the new function will be great. Maybe worth adding next time

Copy link
Copy Markdown
Contributor

@sergeykolychev sergeykolychev Mar 30, 2018

Choose a reason for hiding this comment

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

Yeah, I'll add the docs next time with more substantial changes in April. Tried to unblock quickly. Though I don't see anybody using the functions directly and not via the overloaded operators.

if(blessed $other and join(',', @{ $self->shape }) eq join(',', @{ $other->shape }))
{
return AI::MXNet::NDArray::_ufunc_helper(
$self,
$other,
qw/elemwise_add _plus_scalar/
);
}
else
{
return AI::MXNet::NDArray::_ufunc_helper(
$self,
$other,
qw/broadcast_add _plus_scalar/
);
}
}


method subtract(AI::MXNet::NDArray|Num $other, $reverse=)
{
if(blessed $other and join(',', @{ $self->shape }) eq join(',', @{ $other->shape }))
{
return AI::MXNet::NDArray::_ufunc_helper(
$self,
$other,
qw/elemwise_sub _minus_scalar _rminus_scalar/,
$reverse
);
}
else
{
return AI::MXNet::NDArray::_ufunc_helper(
$self,
$other,
qw/broadcast_sub _minus_scalar _rminus_scalar/,
$reverse
);
}
}

method multiply(AI::MXNet::NDArray|Num $other, $reverse=)
{
if(blessed $other and join(',', @{ $self->shape }) eq join(',', @{ $other->shape }))
{
return AI::MXNet::NDArray::_ufunc_helper(
$self,
$other,
qw/elemwise_mul _mul_scalar/,
);
}
else
{
return AI::MXNet::NDArray::_ufunc_helper(
$self,
$other,
qw/broadcast_mul _mul_scalar/,
);
}
}

method divide(AI::MXNet::NDArray|Num $other, $reverse=)
{
if(blessed $other and join(',', @{ $self->shape }) eq join(',', @{ $other->shape }))
{
return AI::MXNet::NDArray::_ufunc_helper(
$self,
$other,
qw/elemwise_div _div_scalar _rdiv_scalar/,
$reverse
);
}
else
{
return AI::MXNet::NDArray::_ufunc_helper(
$self,
$other,
qw/broadcast_div _div_scalar _rdiv_scalar/,
$reverse
);
}
}

{
no warnings 'redefine';
*_sync_copyfrom = *_at = *_slice = *reshape = *size = \&not_implemented;
Expand Down
Loading