Skip to content

Commit

Permalink
Merge pull request #1346 from palonso/unaryoperator-bugfix
Browse files Browse the repository at this point in the history
Unaryoperator bugfix
  • Loading branch information
dbogdanov authored Jun 29, 2023
2 parents e11821f + 3e622e9 commit 0a94448
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/algorithms/standard/unaryoperator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ inline Real square_func(Real x) {
for (int i=0; i<int(input.size()); ++i) { \
output[i] = f(input[i]); \
} \
return; \
break; \
}

void UnaryOperator::compute() {
Expand Down
22 changes: 18 additions & 4 deletions test/src/unittests/standard/test_unaryoperator.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def testLog10(self):
def testLog10LowX(self):
self.assertAlmostEqualVector(
UnaryOperator(type="log10")(self.testInputLowX),
[-30., -30., -30., -30.])
[-30., -30., -30., -30.])

def testLog(self):
self.assertAlmostEqualVector(
Expand All @@ -55,15 +55,15 @@ def testLog(self):

def testLogLowX(self):
self.assertAlmostEqualVector(
UnaryOperator(type="log")(self.testInputLowX),[-69.07755, -69.07755, -69.07755, -69.07755])
UnaryOperator(type="log")(self.testInputLowX),[-69.07755, -69.07755, -69.07755, -69.07755])

def testLn(self):
self.assertAlmostEqualVector(UnaryOperator(type="ln")(self.testInput),
[0, 0.693147181, 1.098612289, 1.386294361, 1.223775432, -69.07755279, 11.513265407])

def testLnLowX(self):
def testLnLowX(self):
self.assertAlmostEqualVector(UnaryOperator(type="ln")(self.testInputLowX),
[-69.07755, -69.07755, -69.07755, -69.07755])
[-69.07755, -69.07755, -69.07755, -69.07755])

def testLin2Db(self):
self.assertAlmostEqualVector(
Expand Down Expand Up @@ -107,6 +107,20 @@ def testSquare(self):
def testInvalidParam(self):
self.assertConfigureFails(UnaryOperator(), {'type':'exp'})

def testOperatorScaleShift(self):
functions = ["identity", "abs", "log10", "log", "ln", "lin2db", "db2lin", "sin", "cos", "sqrt", "square"]

shift = 1
scale = 2
test_data = [1]

for type in functions:
with self.subTest(i=type):

expected = UnaryOperator(type=type)(test_data) * scale + shift
found = UnaryOperator(type=type, shift=shift, scale=scale)(test_data)

self.assertAlmostEqualVector(expected, found)

suite = allTests(TestUnaryOperator)

Expand Down

0 comments on commit 0a94448

Please sign in to comment.