Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend GenericDict support to integer keys. #885

Open
mlej8 opened this issue Aug 16, 2024 · 0 comments
Open

Extend GenericDict support to integer keys. #885

mlej8 opened this issue Aug 16, 2024 · 0 comments

Comments

@mlej8
Copy link

mlej8 commented Aug 16, 2024

hi, I noticed converting HashMap with i64 as keys to tch::IValue::GenericDict results in an object of type Dict[Any,Any] on the python side:

pub fn create_int_tensor_dict_ivalue(hm: &HashMap<i64, tch::Tensor>) -> tch::IValue {
    tch::IValue::GenericDict(
        hm.iter()
            .map(|(k, v)| {
                (
                    tch::IValue::Int(*k),
                    tch::IValue::Tensor(tch::Tensor::shallow_clone(v)),
                )
            })
            .collect::<Vec<(tch::IValue, tch::IValue)>>(),
    )
}

However, hashmaps with strings as keys are typed as Dict[str, Tensor], could we add support for int as keys ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant