Sprint Chase Technologies
  • Home
  • About
    • Why Choose Us
    • Contact Us
    • Team Members
    • Testimonials
  • Services
    • Web Development
    • Web Application Development
    • Mobile Application Development
    • Web Design
    • UI/UX Design
    • Social Media Marketing
    • Projects
  • Blog
    • PyTorch
    • Python
    • JavaScript
  • IT Institute
menu
close

Need Help? Talk to an Expert

+91 8000107255
Sprint Chase Technologies
  • Home
  • About
    • Why Choose Us
    • Contact Us
    • Team Members
    • Testimonials
  • Services
    • Web Development
    • Web Application Development
    • Mobile Application Development
    • Web Design
    • UI/UX Design
    • Social Media Marketing
    • Projects
  • Blog
    • PyTorch
    • Python
    • JavaScript
  • IT Institute

Need Help? Talk to an Expert

+91 8000107255

PyTorch torch.is_storage() Method

Home PyTorch torch.is_storage() Method
PyTorch torch.is_storage()
  • Written by krunallathiya21
  • July 17, 2025
  • 0 Com
PyTorch

The torch.is_storage() method determines whether a given object is a PyTorch storage object. If it is a valid storage, it will return True; otherwise, it will return False.

Storage objects are the underlying data containers that tensors use to store their actual data in memory.

Pytorch torch.is_storage()

TypedStorage (FloatStorage, IntStorage, etc.) is deprecated and will be removed in future PyTorch versions 

Instead of using a tensor.storage() method to create a TypedStorage class, always use the tensor.untyped_storage() method to create the UntypedStorage class because it will be the default method in future PyTorch versions.

Syntax

torch.is_storage(obj)

Parameters

Argument Description
obj It is an object to test. It can be any Python object.

Basic storage detection

import torch

# Create a tensor
tensor = torch.tensor([1.0, 2.0, 3.0])

# DEPRECATED: TypedStorage access
storage = tensor.storage()  

# RECOMMENDED: UntypedStorage access (future-proof)
untyped_storage = tensor.untyped_storage()

print(torch.is_storage(storage))
# Output: True (but deprecated)
# UserWarning: TypedStorage is deprecated. It will be removed in the future and UntypedStorage will be the only storage class. 
# This should only matter to you if you are using storages directly.  
# To access UntypedStorage directly, use tensor.untyped_storage() instead of tensor.storage()

print(torch.is_storage(untyped_storage))
# Output: True (recommended)

print(torch.is_storage(tensor))
# Output: False

print(torch.is_storage([1, 2, 3]))
# Output: False

Empty and Scalar Tensors

What if either a tensor is empty or a scalar tensor? Well, in both cases, the untyped_storage() method will return True.

import torch

# Empty tensor
empty_tensor = torch.empty(0)

# Scalar tensor
scalar_tensor = torch.tensor(5.0)

# UntypedStorage access
empty_untyped = empty_tensor.untyped_storage()
print(f"Empty tensor untyped storage: {torch.is_storage(empty_untyped)}")
# Output: True

scalar_untyped = scalar_tensor.untyped_storage()
print(f"Scalar tensor untyped storage: {torch.is_storage(scalar_untyped)}")
# Output: True
That’s all!
Post Views: 1
LEAVE A COMMENT Cancel reply
Please Enter Your Comments *

krunallathiya21

All Categories
  • JavaScript
  • Python
  • PyTorch
site logo

Address:  TwinStar, South Block – 1202, 150 Ft Ring Road, Nr. Nana Mauva Circle, Rajkot(360005), Gujarat, India

sprintchasetechnologies@gmail.com

(+91) 8000107255.

ABOUT US
  • About
  • Team Members
  • Testimonials
  • Contact

Copyright by @SprintChase  All Rights Reserved

  • PRIVACY
  • TERMS & CONDITIONS