The convex and affine function definition I am seeing is this: $f:R^n \to R$ is convex if $dom f$ is a convex set and if for all $x,y\in domf$, and $\theta$ with $0\leq\theta\leq 1$, we have $f(\theta x+(1-\theta)y)\leq\theta f(x)+(1-\theta)f(y)$
For an affine function we always have equality, $f(\theta x+(1-\theta)y)=\theta f(x)+(1-\theta)f(y)$
My confusion comes from, why convex function require its domain to be convex, and why affine function does not require anything about its domain(at least I cannot find anywhere mentioning)?
I was thinking about a function f(x)=2x with doamin $(-\infty,1]\cup[2.\infty)$
Then, when $x=1,y=2\in domf$ this equation does not hold properly: $f(\theta x+(1-\theta)y)=\theta f(x)+(1-\theta)f(y)$ because $\theta x+(1-\theta)y)$ is not in $domf$
Doesn't it mean, we also should specify some requiresments for domain of affine functions?