Exemple #1
0
    def test_generate_matrix(self):
        dtype = self.dtype
        x_shape, s_shape = self.x_s_shapes
        sv = numpy.random.uniform(0.5, 1.5, s_shape).astype(dtype().real.dtype)
        x = testing.generate_matrix(x_shape, dtype=dtype, singular_values=sv)
        assert x.shape == x_shape

        s = numpy.linalg.svd(
            x.astype(numpy.complex128),
            full_matrices=False,
            compute_uv=False,
        )
        sv = matrix._broadcast_to(sv, s.shape)
        sv_sorted = numpy.sort(sv, axis=-1)[..., ::-1]

        rtol = 1e-3 if dtype == numpy.float16 else 1e-7
        numpy.testing.assert_allclose(s, sv_sorted, rtol=rtol)
Exemple #2
0
 def test_shape_mismatch(self):
     with self.assertRaises(ValueError):
         testing.generate_matrix((2, 2), singular_values=numpy.ones(3))
Exemple #3
0
 def test_negative_singular_values(self):
     with self.assertRaises(ValueError):
         testing.generate_matrix((2, 2), singular_values=[1, -1])
Exemple #4
0
 def test_invalid_dtype_singular_values(self):
     with self.assertRaises(TypeError):
         testing.generate_matrix((2, 2), singular_values=1 + 0j)
Exemple #5
0
 def test_invalid_dtype(self):
     with self.assertRaises(TypeError):
         testing.generate_matrix((2, 2),
                                 dtype=numpy.int32,
                                 singular_values=1)
Exemple #6
0
 def test_invalid_shape(self):
     with self.assertRaises(ValueError):
         testing.generate_matrix((2, ), singular_values=1)
Exemple #7
0
 def test_no_singular_values(self):
     with self.assertRaises(TypeError):
         testing.generate_matrix((2, 2))