Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ot/da.py
Original file line number Diff line number Diff line change
Expand Up @@ -2287,6 +2287,8 @@ class label
Returns self.
"""

self._get_backend(Xs, ys, Xt, yt)

# check the necessary inputs parameters are here
if check_params(Xs=Xs, Xt=Xt):
super(UnbalancedSinkhornTransport, self).fit(Xs, ys, Xt, yt)
Expand Down
28 changes: 28 additions & 0 deletions test/test_da.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,34 @@ def test_unbalanced_sinkhorn_transport_class(nx):
assert len(otda.log_.keys()) != 0


@pytest.skip_backend("jax")
@pytest.skip_backend("tf")
def test_unbalanced_sinkhorn_transport_nx_initialized(nx):
"""non-regression test for issue #650

fit must always initialize the backend attribute nx, even when called
with missing parameters, so that transform fails on a clear error
instead of 'NoneType' object has no attribute 'array_equal'
"""

ns = 50
Xs, ys = make_data_classif("3gauss", ns)
Xt, yt = make_data_classif("3gauss2", ns)

Xs, ys, Xt, yt = nx.from_numpy(Xs, ys, Xt, yt)

# incomplete fit (Xt missing) still initializes the backend
otda = ot.da.UnbalancedSinkhornTransport()
otda.fit(Xs=Xs)
assert otda.nx is not None

# complete fit followed by a separate transform call
otda = ot.da.UnbalancedSinkhornTransport()
otda.fit(Xs=Xs, Xt=Xt)
transp_Xs = otda.transform(Xs)
assert_equal(transp_Xs.shape, Xs.shape)


@pytest.skip_backend("jax")
@pytest.skip_backend("tf")
def test_emd_transport_class(nx):
Expand Down
Loading