Skip to content

Commit

Permalink
Add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bwohlberg committed Feb 7, 2024
1 parent 1fcc048 commit 2b563f1
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions scico/test/linop/test_binop.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import operator as op

import pytest

import scico.numpy as snp
from scico import linop


class TestBinaryOp:
def setup_method(self, method):
self.input_shape = (5,)
self.input_dtype = snp.float32

@pytest.mark.parametrize("operator", [op.add, op.sub])
def test_case1(self, operator):
A = linop.Convolve(
snp.ones((2,)), input_shape=self.input_shape, input_dtype=self.input_dtype, mode="same"
)
B = linop.Identity(input_shape=self.input_shape, input_dtype=self.input_dtype)

assert type(A + B) == linop.LinearOperator
assert type(B + A) == linop.LinearOperator
assert type(2.0 * A + 3.0 * B) == linop.LinearOperator
assert type(2.0 * B + 3.0 * A) == linop.LinearOperator

@pytest.mark.parametrize("operator", [op.add, op.sub])
def test_case2(self, operator):
A = linop.SingleAxisFiniteDifference(
input_shape=self.input_shape, input_dtype=self.input_dtype, circular=True
)
B = linop.Identity(input_shape=self.input_shape, input_dtype=self.input_dtype)

assert type(A + B) == linop.LinearOperator
assert type(B + A) == linop.LinearOperator
assert type(2.0 * A + 3.0 * B) == linop.LinearOperator
assert type(2.0 * B + 3.0 * A) == linop.LinearOperator

@pytest.mark.parametrize("operator", [op.add, op.sub])
def test_case3(self, operator):
A = linop.ScaledIdentity(
scalar=0.5, input_shape=self.input_shape, input_dtype=self.input_dtype
)
B = linop.Identity(input_shape=self.input_shape, input_dtype=self.input_dtype)

assert type(A + B) == linop.ScaledIdentity
assert type(B + A) == linop.ScaledIdentity
assert type(2.0 * A + 3.0 * B) == linop.ScaledIdentity
assert type(2.0 * B + 3.0 * A) == linop.ScaledIdentity

0 comments on commit 2b563f1

Please sign in to comment.