Task
Given a matrix of numbers \$M\$ with \$r\$ rows and \$c\$ columns, and the magnification factor \$n\$, build the matrix with \$rn\$ rows and \$cn\$ columns where the original elements are spaced \$n\$ units apart and the gaps are filled by piecewise linear interpolation:
$$ \begin{bmatrix} a_{11} & a_{12} & \cdots \\ a_{21} & a_{22} & \cdots \\ \vdots & \vdots & \ddots \\ \end{bmatrix} \Rightarrow \begin{bmatrix} a_{11} & \frac{(n-1)a_{11} + a_{12}}{n} & \cdots & a_{12} & \cdots \\ \frac{(n-1)a_{11} + a_{21}}{n} & \frac{(n-1) \frac{(n-1)a_{11} + a_{21}}{n} + \frac{(n-1)a_{12} + a_{22}}{n}}{n} & \cdots & \frac{(n-1)a_{12} + a_{22}}{n} & \cdots \\ \vdots & \vdots & \ddots & \vdots \\ a_{21} & \frac{(n-1)a_{21} + a_{22}}{n} & \cdots & a_{22} & \cdots \\ \vdots & \vdots & & \vdots & \ddots \\ \end{bmatrix} $$
Because the operation is toroidal, the "gaps" between the \$r\$-th row and the 1st row (resp. the \$c\$-th column and the 1st column) must also be filled, which is placed below the original elements of the \$r\$-th row (resp. on the right side of the \$c\$-th column).
You can take \$M\$ and \$n\$ (and optionally \$r\$ and \$c\$) as input and output the resulting matrix in any suitable format. \$n\$ is guaranteed to be a positive integer. The input matrix and the result may have non-integers.
Standard code-golf rules apply. The shortest code in bytes wins.
Test cases
# one-element matrix
M = [[1]], n = 3
[[1, 1, 1],
[1, 1, 1],
[1, 1, 1]]
# one-element matrix, large n
M = [[1]], n = 100
(100-by-100 matrix of ones)
# one-row matrix
M = [[0, 6, 3, 6]], n = 3
[[0, 2, 4, 6, 5, 4, 3, 4, 5, 6, 4, 2],
[0, 2, 4, 6, 5, 4, 3, 4, 5, 6, 4, 2],
[0, 2, 4, 6, 5, 4, 3, 4, 5, 6, 4, 2]]
# one-column matrix
M = [[0], [6], [3], [6]], n = 3
(transpose of the above)
# n = 1
M = [[1, 9, 8, 3],
[5, 4, 2, 7],
[3, 8, 5, 1]], n = 1
(same as M)
# 2-by-2 matrix; here the result is rounded to 2 decimal places for convenience.
# An answer doesn't need to round them, though one may choose to do so.
M = [[0, 9],
[3, 6]], n = 3
[[0, 3, 6, 9, 6, 3],
[1, 3.33, 5.67, 8, 5.67, 3.33],
[2, 3.67, 5.33, 7, 5.33, 3.67],
[3, 4, 5, 6, 5, 4],
[2, 3.67, 5.33, 7, 5.33, 3.67],
[1, 3.33, 5.67, 8, 5.67, 3.33]]
# a larger test case
M = [[0, 25, 0],
[25, 0, 0],
[0, 0, 25]], n = 5
[[0, 5, 10, 15, 20, 25, 20, 15, 10, 5, 0, 0, 0, 0, 0],
[5, 8, 11, 14, 17, 20, 16, 12, 8, 4, 0, 1, 2, 3, 4],
[10, 11, 12, 13, 14, 15, 12, 9, 6, 3, 0, 2, 4, 6, 8],
[15, 14, 13, 12, 11, 10, 8, 6, 4, 2, 0, 3, 6, 9, 12],
[20, 17, 14, 11, 8, 5, 4, 3, 2, 1, 0, 4, 8, 12, 16],
[25, 20, 15, 10, 5, 0, 0, 0, 0, 0, 0, 5, 10, 15, 20],
[20, 16, 12, 8, 4, 0, 1, 2, 3, 4, 5, 8, 11, 14, 17],
[15, 12, 9, 6, 3, 0, 2, 4, 6, 8, 10, 11, 12, 13, 14],
[10, 8, 6, 4, 2, 0, 3, 6, 9, 12, 15, 14, 13, 12, 11],
[5, 4, 3, 2, 1, 0, 4, 8, 12, 16, 20, 17, 14, 11, 8],
[0, 0, 0, 0, 0, 0, 5, 10, 15, 20, 25, 20, 15, 10, 5],
[0, 1, 2, 3, 4, 5, 8, 11, 14, 17, 20, 16, 12, 8, 4],
[0, 2, 4, 6, 8, 10, 11, 12, 13, 14, 15, 12, 9, 6, 3],
[0, 3, 6, 9, 12, 15, 14, 13, 12, 11, 10, 8, 6, 4, 2],
[0, 4, 8, 12, 16, 20, 17, 14, 11, 8, 5, 4, 3, 2, 1]]