(b)
| 507 | if log or return_matrix: |
| 508 | |
| 509 | def f(b): |
| 510 | bsel = b != 0 |
| 511 | |
| 512 | G, cost, u, v, result_code = emd_c(a, b, M, numItermax, numThreads) |
| 513 | |
| 514 | if center_dual: |
| 515 | u, v = center_ot_dual(u, v, a, b) |
| 516 | |
| 517 | if np.any(~asel) or np.any(~bsel): |
| 518 | u, v = estimate_dual_null_weights(u, v, a, b, M) |
| 519 | |
| 520 | result_code_string = check_result(result_code) |
| 521 | log = {} |
| 522 | if not nx.is_floating_point(type_as): |
| 523 | warnings.warn( |
| 524 | "Input histogram consists of integer. The transport plan will be " |
| 525 | "casted accordingly, possibly resulting in a loss of precision. " |
| 526 | "If this behaviour is unwanted, please make sure your input " |
| 527 | "histogram consists of floating point elements.", |
| 528 | stacklevel=2, |
| 529 | ) |
| 530 | G = nx.from_numpy(G, type_as=type_as) |
| 531 | if return_matrix: |
| 532 | log["G"] = G |
| 533 | log["u"] = nx.from_numpy(u, type_as=type_as) |
| 534 | log["v"] = nx.from_numpy(v, type_as=type_as) |
| 535 | log["warning"] = result_code_string |
| 536 | log["result_code"] = result_code |
| 537 | cost = nx.set_gradients( |
| 538 | nx.from_numpy(cost, type_as=type_as), |
| 539 | (a0, b0, M0), |
| 540 | (log["u"] - nx.mean(log["u"]), log["v"] - nx.mean(log["v"]), G), |
| 541 | ) |
| 542 | return [cost, log] |
| 543 | else: |
| 544 | |
| 545 | def f(b): |
no test coverage detected