Files
HowToSD-ComfyUI-Pt-Wrapper/modules/pytorch_wrapper/pt_to_float32.py
T

41 lines
982 B
Python

from typing import Any, Dict
import torch
class PtToFloat32:
"""
Pt To Float32:
Converts the input tensor's data type to float32.
category: PyTorch wrapper - Data type conversion
"""
@classmethod
def INPUT_TYPES(cls) -> Dict[str, Any]:
"""
Defines the required input types.
Returns:
Dict[str, Any]: A dictionary of required input types.
"""
return {
"required": {
"tens_a": ("TENSOR", {})
}
}
RETURN_TYPES: tuple = ("TENSOR",)
FUNCTION: str = "f"
CATEGORY: str = "Data Analysis"
def f(self, tens_a: torch.Tensor) -> tuple:
"""
Converts the input tensor's data type to float32.
Args:
tens_a (torch.Tensor): A PyTorch tensor of numerical type.
Returns:
tuple: A tuple containing the resultant tensor after the operation.
"""
return (tens_a.to(torch.float32),)