Solution (source code)

= Solution

For an integrable initial profile $f(y)$, use its <Fourier transform> with the convention
$$
\widehat f(k)=\int_{\mathbb R}f(y)e^{-iky}\,dy.
$$
The transformed <diffusion equation> is $\partial_t\widehat T=-\kappa k^2\widehat T$, so
$$
\boxed{T(t,y)=\frac1{2\pi}\int_{\mathbb R}\widehat f(k)e^{-\kappa k^2t}e^{iky}\,dk.}
$$
Equivalently the <heat-kernel convolution> is
$$
T(t,y)=\frac1{\sqrt{4\pi\kappa t}}\int_{\mathbb R}
\exp\!\left[-\frac{(y-\eta)^2}{4\kappa t}\right]f(\eta)\,d\eta.
$$
This also accommodates bounded piecewise-continuous initial profiles; it recovers $f$ at continuity points as $t\downarrow0$. For periodic initial data use a <Fourier series> and multiply each mode by $e^{-\kappa k_r^2t}$; the constant mean mode remains unchanged. “Any function” needs the usual existence/integrability or growth conditions: an arbitrarily fast-growing initial function need not give a finite heat-kernel integral.