Skip to content

Commit

Permalink
Fixing up extra array dimension when incoming opytimizer.
Browse files Browse the repository at this point in the history
  • Loading branch information
gugarosa committed Jun 26, 2020
1 parent 045504f commit 8dd43ee
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 23 deletions.
15 changes: 13 additions & 2 deletions opytimark/utils/decorator.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import numpy as np

import opytimark.utils.exception as e


Expand All @@ -23,20 +25,29 @@ def _check_dimension(*args):
# Retrieving the object and the input from arguments
obj, x = args[0], args[1]

# Tries to squeeze the last dimension of `x` as it might be an array of (dim, 1)
try:
# Squeezes the array
x = np.squeeze(x, axis=1)

# If squeeze could not be performed, it means that there is no extra dimension
except:
pass

# If the function's number of dimensions is equal to `-1` (n-dimensional)
if obj.dims == -1:
# Checks if the input array is bigger than zero
if x.shape[0] == 0:
# If not, raises an error
raise e.SizeError(f'{obj.name} input should be n-dimensional')

return f(*args)
return f(obj, x)

# If the input dimensions is different from function's allowed dimensions
if x.shape[0] != obj.dims:
# Raises an error
raise e.SizeError(f'{obj.name} input should be {obj.dims}-dimensional')

return f(*args)
return f(obj, x)

return _check_dimension
21 changes: 0 additions & 21 deletions tests/opytimark/utils/test_logging.py

This file was deleted.

0 comments on commit 8dd43ee

Please sign in to comment.