torch.is_complex_dtype
function is_complex_dtype(dtype: DType): booleanChecks if the given dtype is a complex number type.
Returns true for complex data types (complex64) and false for real types. Complex numbers are stored as interleaved real/imaginary pairs. Useful for:
- Signal processing: FFT and spectral analysis operations
- Physics simulations: Wave equations, quantum mechanics
- Linear algebra: Eigenvalue decomposition with complex eigenvalues
- Control theory: Complex transfer functions and poles/zeros
- Storage: complex64 tensors use Float32Array with 2x elements (interleaved real/imag)
- Components: Use tensor.real and tensor.imag to access components
Parameters
dtypeDType- The data type to check
Returns
boolean– True if dtype is complex64, false for real typesExamples
torch.is_complex_dtype('complex64'); // true
torch.is_complex_dtype('float32'); // false
torch.is_complex_dtype('int32'); // false// Check for complex before using complex-specific operations
function fft_output(x: Tensor): Tensor {
if (torch.is_complex_dtype(x.dtype)) {
return torch.fft.fft(x); // Complex input
} else {
return torch.fft.rfft(x); // Real input
}
}See Also
- PyTorch torch.is_complex()
- is_floating_point_dtype - Check if dtype is floating-point
- get_real_dtype - Get the component dtype (float32 for complex64)
- promote_types - Determine output dtype for mixed-precision operations