star.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:hylaa 作者: stanleybak 项目源码 文件源码
def vector_to_star_basis(self, standard_vec):
        '''
        convert a vector in the standard basis to a point in the star's basis.

        This solves basis_matrix * rv = input, which is essentially computing the
        inverse of basis_matrix, which can become ill-conditioned.
        '''

        Timers.tic("vector_to_star_basis()")

        rv = np.linalg.solve(self.basis_matrix.T, standard_vec)

        #rv = lstsq(self.basis_matrix.T, np.array(standard_vec, dtype=float))[0]

        # double-check that we've found the solution within some tolerance
        if not np.allclose(np.dot(self.basis_matrix.T, rv), standard_vec):
            raise RuntimeError("basis matrix was ill-conditioned, vector_to_star_basis() failed")

        Timers.toc("vector_to_star_basis()")

        assert isinstance(rv, np.ndarray)

        return rv
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号