'Apply the Gram-Schmidt orthogonalization procedure
to vectors supplied in `vecs`.
Arguments
vecs : vectors to be made orthogonal
normalize : bool. Whether the returned vectors
should be renormalized to be unit vectors.'

@classmethod
def orthogonalize(cls, *vecs, **kwargs):

    normalize = kwargs.get('normalize', False)
    def project(a, b):
        return (b * (a.dot(b) / b.dot(b)))
    def perp_to_subspace(vec, basis):
        'projects    vec    onto    the    subspace    given\n                                                by    the    orthogonal    basis    `basis`'
        components = [project(vec, b) for b in basis]
        if (len(basis) == 0):
            return vec
        return (vec - reduce((lambda a, b: (a + b)), components))
    ret = []
    while ((len(vecs) > 0) and vecs[0].is_zero):
        del vecs[0]
    for vec in vecs:
        perp = perp_to_subspace(vec, ret)
        if (not perp.is_zero):
            ret.append(perp)
    if normalize:
        ret = [(vec / vec.norm()) for vec in ret]
    return ret
