precompute diags