ludwig-ai--ludwig
593b94c120
pytest / Unit Tests (push) Has been cancelled
pytest / Integration (integration_tests_a) (push) Has been cancelled
pytest / Integration (integration_tests_b) (push) Has been cancelled
pytest / Integration (integration_tests_c) (push) Has been cancelled
pytest / Integration (integration_tests_d) (push) Has been cancelled
pytest / Integration (integration_tests_e) (push) Has been cancelled
pytest / Integration (integration_tests_f) (push) Has been cancelled
pytest / Integration (integration_tests_g) (push) Has been cancelled
pytest / Integration (integration_tests_h) (push) Has been cancelled
pytest / Integration (integration_tests_i) (push) Has been cancelled
pytest / Integration (integration_tests_j) (push) Has been cancelled
pytest / Distributed (distributed_a) (push) Has been cancelled
pytest / Distributed (distributed_b) (push) Has been cancelled
pytest / Distributed (distributed_c) (push) Has been cancelled
pytest / Distributed (distributed_d) (push) Has been cancelled
pytest / Distributed (distributed_e) (push) Has been cancelled
pytest / Distributed (distributed_f) (push) Has been cancelled
pytest / Minimal Install (push) Has been cancelled
pytest / Event File (push) Has been cancelled
pytest (slow) / py-slow (push) Has been cancelled
Publish JSON Schema / publish-schema (push) Has been cancelled
20 行
1.1 KiB
Python
20 行
1.1 KiB
Python
import pytest
|
|
import torch
|
|
|
|
from ludwig.utils import output_feature_utils
|
|
|
|
|
|
def test_output_feature_utils():
|
|
tensor_dict = {}
|
|
output_feature_utils.set_output_feature_tensor(tensor_dict, "feature_1", "1", torch.Tensor([1]))
|
|
output_feature_utils.set_output_feature_tensor(tensor_dict, "feature_1", "10", torch.Tensor([10]))
|
|
output_feature_utils.set_output_feature_tensor(tensor_dict, "feature_2", "2", torch.Tensor([2]))
|
|
output_feature_utils.set_output_feature_tensor(tensor_dict, "feature_2", "20", torch.Tensor([20]))
|
|
|
|
assert list(tensor_dict.keys()) == ["feature_1::1", "feature_1::10", "feature_2::2", "feature_2::20"]
|
|
assert output_feature_utils.get_output_feature_tensor(tensor_dict, "feature_1", "1") == torch.Tensor([1])
|
|
assert list(output_feature_utils.get_single_output_feature_tensors(tensor_dict, "feature_1").keys()) == ["1", "10"]
|
|
assert list(output_feature_utils.get_single_output_feature_tensors(tensor_dict, "feature_3").keys()) == []
|
|
with pytest.raises(Exception):
|
|
output_feature_utils.get_output_feature_tensor(tensor_dict, "feature_1", "2")
|