For A = \begin{bmatrix} 1 & 0\\ 1 & 0\end{bmatrix}, P = \begin{bmatrix} 1 & 0\\ 1 & 0\end{bmatrix}, and N = \begin{bmatrix} 0 & 1\\ 0 & 1\end{bmatrix} we have {\cal L}(A,P) = 0 and {\cal L}(A,N) = \begin{bmatrix} 1 & -1\\ 1 & -1\end{bmatrix}_F^2 = 4. Thus the overall loss {\cal L}(A,N,P) = [0 - 4 + \alpha]_+ = 0 for \alpha = 3 . But the assert statement in the test code wants a value of 2. !!

Even in the formula you have written the L2 norm has to be taken before adding \alpha. So the answer should be ||\begin{bmatrix}0 \\ 0 \end{bmatrix}||_2^2 - ||\begin{bmatrix}2 \\ 2 \end{bmatrix}||_2^2 + 3 = 5

Also I don’t get how you construct the rank 1, length 2 vectors \begin{bmatrix} 0 \\ 0 \end{bmatrix} and \begin{bmatrix} 2 \\ 2 \end{bmatrix} from the 2x2 dimensional matrices f(A)-f(P) and f(A)-f(N).