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

Call ts.Drop() ts.MustDrop() multiple times #10

Closed
sugarme opened this issue Oct 23, 2020 · 0 comments · Fixed by #11
Closed

Call ts.Drop() ts.MustDrop() multiple times #10

sugarme opened this issue Oct 23, 2020 · 0 comments · Fixed by #11
Assignees
Labels
enhancement New feature or request

Comments

@sugarme
Copy link
Owner

sugarme commented Oct 23, 2020

Make ts.Drop() can be called multiple times.

func (ts Tensor) Drop() (err error) {

	if !ts.MustDefined() {
		return nil
	}

	lib.AtFree(ts.ctensor)
	if err = TorchErr(); err != nil {
		return err
	}

	// NOTE. assign to a new undefined tensor, then check `ts.MustDefined`
	// before deleting at C land. Hence `Drop` method can be called
	// multiple times without worrying about double C memory delete panic.
	// Other pattern is `defer ts.MustDrop()` whenever a tensor is created.
	ts = NewTensor()

	return nil
}
@sugarme sugarme added the enhancement New feature or request label Oct 23, 2020
@sugarme sugarme self-assigned this Oct 23, 2020
sugarme added a commit that referenced this issue Oct 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant