torch.get_default_dtype
function get_default_dtype(): stringReturns the default data type used for newly created tensors.
When creating tensors without specifying a dtype, this default is used.
You can change the default with set_default_dtype().
torch.js always defaults to float32 for compatibility and performance. Changing the default is not supported.
Returns
string– The default dtype (always 'float32' in torch.js)Examples
// Get the default dtype
const dtype = torch.get_default_dtype();
// Returns: 'float32'
// Create a tensor with default dtype
const x = torch.tensor([1, 2, 3]);
console.log(x.dtype); // 'float32'
// Create a tensor with explicit dtype to override default
const y = torch.tensor([1, 2, 3], { dtype: 'int32' });
console.log(y.dtype); // 'int32'See Also
- PyTorch torch.get_default_dtype()
- tensor - Create tensors with explicit dtype
- Tensor.to - Convert tensor to different dtype