class SymmetricMatrix {

    public static double quadraticForm(final Matrix S, final DataBlock x) {
        double[] pm = S.data_;
        double[] px = x.getData();

        int x0 = x.getStartPosition(), x1 = x.getEndPosition(), xinc = x.getIncrement();
        int cinc = S.nrows_;
        double s = 0;
        for (int ic = 0, id = 0, ix = x0; ix != x1; ix += xinc, id += 1 + cinc, ic += cinc) {
            double xi = px[ix];
            double z = pm[id] * xi;
            for (int ir = ic, jx = x0; jx < ix; ++ir, jx += xinc) {
                z += 2 * pm[ir] * px[jx];
            }
            s += z * xi;
        }
        return s;
    }

    private  SymmetricMatrix();

}