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

Tensor lifetimes #6

Merged
merged 13 commits into from
Jan 5, 2025
Merged

Tensor lifetimes #6

merged 13 commits into from
Jan 5, 2025

Conversation

BhavyeMathur
Copy link
Owner

In previous versions, code like the following would compile without error:

fn undefined_behaviour() {
    let mut a;

    {
        let b = Tensor::zeros([3, 5]);
        a = b.view();
    }

    a.fill(50);
}

Even though a is a view into Tensor b which is destroyed once its scope ends, the library still allowed you to use a. With added lifetime generics for Tensor, code like this now generates a compiler error.

src/tensor/iterator/flat_iterator.rs Dismissed Show dismissed Hide dismissed
@BhavyeMathur BhavyeMathur merged commit 792f71d into master Jan 5, 2025
3 checks passed
@BhavyeMathur BhavyeMathur deleted the tensor-lifetimes branch January 12, 2025 15:34
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

Successfully merging this pull request may close these issues.

1 participant