Unittest function has code errors


w1_unittest.test_translate(translate, trained_translator) has code errors that do not seem related to my code.

Is anybody experiencing the same problem?

ValueError                                Traceback (most recent call last)
Cell In[30], line 1
----> 1 w1_unittest.test_translate(translate, trained_translator)

File /tf/w1_unittest.py:599, in test_translate(learner_func, model)
    595     cases.append(t)
    597     return cases
--> 599 cases = g()
    600 print_feedback(cases)

File /tf/w1_unittest.py:557, in test_translate.<locals>.g()
    554 cases.append(t)
    556 t = test_case()
--> 557 if not np.allclose(tokens, tokens2):
    558     t.failed = True
    559     t.msg = "translate didn't return the same tokens when using temperature of 0.0"

File <__array_function__ internals>:200, in allclose(*args, **kwargs)

File /usr/local/lib/python3.8/dist-packages/numpy/core/numeric.py:2270, in allclose(a, b, rtol, atol, equal_nan)
   2199 @array_function_dispatch(_allclose_dispatcher)
   2200 def allclose(a, b, rtol=1.e-5, atol=1.e-8, equal_nan=False):
   2201     """
   2202     Returns True if two arrays are element-wise equal within a tolerance.
   2269     """
-> 2270     res = all(isclose(a, b, rtol=rtol, atol=atol, equal_nan=equal_nan))
   2271     return bool(res)

File <__array_function__ internals>:200, in isclose(*args, **kwargs)

File /usr/local/lib/python3.8/dist-packages/numpy/core/numeric.py:2380, in isclose(a, b, rtol, atol, equal_nan)
   2378 yfin = isfinite(y)
   2379 if all(xfin) and all(yfin):
-> 2380     return within_tol(x, y, atol, rtol)
   2381 else:
   2382     finite = xfin & yfin

File /usr/local/lib/python3.8/dist-packages/numpy/core/numeric.py:2361, in isclose.<locals>.within_tol(x, y, atol, rtol)
   2359 def within_tol(x, y, atol, rtol):
   2360     with errstate(invalid='ignore'), _no_nep50_warning():
-> 2361         return less_equal(abs(x-y), atol + rtol * abs(y))

ValueError: operands could not be broadcast together with shapes (1,6) (1,7)

When a unit test throws an error, it means it has detected an error in your code.

1 Like

Your code is probably called from line “599”, where it calls g(). I suspect that’s a function pointer to one of your functions.

Exactly. That type of dimension mismatch error most likely means that your code is not general. E.g. it makes hard-coded assumptions about the dimensions of the input objects, but there are multiple test cases with different dimensions.

@TMosh , @paulinpaloalto , thanks for the help. I will check my code with those hints in mind.

@TMosh , @paulinpaloalto , may I bother one more time?

Never mind. I found and corrected my error.

1 Like

Hi, Francisco.

That’s great news! Nice work!


I have stucked in this problems, can you help me ??

@ledai0912 , who are you asking and where are you stuck? (do not show your code, please)