Exemplo n.º 1
0
 def _normalize_inplace(self):
     """Normalizes trace to -1, in-place.
     
     Should only call during __init__, since it mutates the object.
     WARNING: Only normalizes real component.
     """
     scale_trace(self._data)
Exemplo n.º 2
0
 def _normalize_inplace(self):
     """Normalizes trace to -1, in-place.
     
     Should only call during __init__, since it mutates the object.
     WARNING: Only normalizes real component.
     """
     scale_trace(self._data)
Exemplo n.º 3
0
    def test_scale_trace(self):
        """scale_trace should scale trace to correct values"""
        #should scale to -1 by default
        #WARNING: won't work with integer matrices
        m = array([[-2., 0],[0,-2]])
        scale_trace(m)
        self.assertFloatEqual(m, [[-0.5, 0],[0,-0.5]])
        #should work even with zero rows
        m = array([
                [1.0,2,3,4],
                [2,4,4,0],
                [1,1,0,1],
                [0,0,0,0]
        ])
        m_orig = m.copy()
        scale_trace(m)
        self.assertFloatEqual(m, m_orig / -5)
        #but should fail if trace is zero
        m = array([[0,1,1],[1,0,1],[1,1,0]])

        #SUPPORT2425
        ori_err = numpy.geterr()
        numpy.seterr(divide='raise')
        try:
        #with numpy_err(divide='raise'):
            self.assertRaises((ZeroDivisionError, FloatingPointError), \
                scale_trace, m)
        finally:
            numpy.seterr(**ori_err)