TorchDSP / torchsig

TorchSig is an open-source signal processing machine learning toolkit based on the PyTorch data handling pipeline.
MIT License
174 stars 40 forks source link

`is_signal` Type Checking Failure #254

Closed IsaiahHarvi closed 2 weeks ago

IsaiahHarvi commented 2 weeks ago

is_signal Type Checking Failure

Description: The is_signal method fails due to incorrect type checking. Specifically, d["metadata"] is expected to be a list but is instead a dictionary, causing the check to fail when is_signal is invoked.

Steps to Reproduce: The following code snippet has this the issue, revealing that d["metadata"] is a dictionary, not a list, as expected by is_signal which is modified for debugging below.

d = Signal(
    data=create_signal_data(i + 1j * q),
    metadata=create_modulated_rf_metadata(
        sample_rate=1024,
        num_samples=4096,
        complex=True,
        snr=100,
        samples_per_symbol=32  # samp_rate/symbol_rate
    )
)

if not isinstance(d, dict):
    print("Error: `d` is not a dictionary.")

if "data" not in d.keys() or "metadata" not in d.keys():
    print("Error: `data` or `metadata` key missing in `d`.")

print(d["metadata"], type(d["metadata"]))
if not isinstance(d["metadata"], list):
    print("Error: `metadata` is not a list as expected.")

print(is_signal_data(d["data"]) and all(
    [is_signal_metadata(m) for m in d["metadata"]]
))

Expected Behavior: The is_signal method should pass this check without failure, except that create_modulated_rf_metadata returns the incorrect type.

Proposed Solution: Wrap the dictionary in a list within create_modulated_rf_metadata to meet the expected structure. This will align the data type with the is_signal method’s requirements, resolving the type mismatch. Or, just expect a dictionary.