[docs]defmandelbrot_warp(c:torch.Tensor)->torch.Tensor:""" Warp implementation of the Mandelbrot set. Warp converts external arrays to its own format zero-copy, therefore we do not need to worry about it. See Also -------- https://nvidia.github.io/warp/modules/interoperability.html """if"cuda"instr(c.device):device="cuda"else:device="cpu"xp=array_namespace(c)out=wp.empty(shape=c.shape,dtype=wp.int32,device=device)c=xp.stack([c.real,c.imag],axis=-1)field=wp.array(c,dtype=wp.vec2difc.dtype==torch.float64elsewp.vec2f,device=device)wp.launch(kernel=_mandelbrot_kernel,dim=c.shape,inputs=[field],outputs=[out],device=device,)returnwp.to_torch(out,requires_grad=False)