Added flattenTriangular function and test

We don't make this check explicitly elsewhere in these helpers. If we are going to do this, we should make it check every row.