### ----------------------------------------------------
### -- Math::SparseMatrix::Native
### -- Licenses: Artistic-2.0
### -- Authors: Anton Antonov
### -- File: t/04-element-wise-addition.rakutest
### ----------------------------------------------------
use v6.d;

#use lib <. lib>;
use Math::SparseMatrix::Native;
use Math::SparseMatrix::Native::Utilities;
use Test;

my $nrow = 5;
my $ncol = 8;
my $density = 0.25;
my $nnz = ($nrow * $ncol * $density).Int;
my $seed = Whatever;

my $matrix1 = Math::SparseMatrix::Native::CSRStruct.new.random(:$nrow, :$ncol, :$nnz, seed => 3232);
my $matrix2 = Math::SparseMatrix::Native::CSRStruct.new.random(:$nrow, :$ncol, :$nnz, seed => 882);

plan *;

## 1
isa-ok $matrix1, Math::SparseMatrix::Native::CSRStruct;

## 2
isa-ok $matrix2, Math::SparseMatrix::Native::CSRStruct;

## 3
isa-ok $matrix1.add(4.3), Math::SparseMatrix::Native::CSRStruct;

## 4
isa-ok $matrix1.add($matrix2), Math::SparseMatrix::Native::CSRStruct;

## 5
is-deeply
        $matrix1.add($matrix2).Array,
        elementwise-operation($matrix1.Array, $matrix2.Array, &infix:<+>),
        "Same dense matrix";

## 6
subtest {
    my $matrix1iv = $matrix1.clone;
    $matrix1iv.implicit_value = 1.5.Num;
    my $matrix2iv = $matrix2.clone;
    $matrix2iv.implicit_value = 2.2.Num;
    is-deeply
            $matrix1iv.add($matrix2iv).Array,
            elementwise-operation($matrix1iv.Array, $matrix2iv.Array, &infix:<+>),
            "Same dense matrix";
}, "Addition with implicit values";

## 7
subtest {
    my $m = $matrix1.add(3.4);
    my $a = $matrix1.Array.deepmap({ 3.4 + $_ });
    is-deeply $m.Array, $a, 'Same dense matrix';
}, 'Additiona with a scalar';

done-testing;


