Example #1
0
  def test_ref_type_shape_args_raises(self):
    with self.assertRaisesRegex(TypeError, "num_rows.cannot.be.reference"):
      linalg_lib.LinearOperatorZeros(num_rows=variables_module.Variable(2))

    with self.assertRaisesRegex(TypeError, "num_columns.cannot.be.reference"):
      linalg_lib.LinearOperatorZeros(
          num_rows=2, num_columns=variables_module.Variable(3))

    with self.assertRaisesRegex(TypeError, "batch_shape.cannot.be.reference"):
      linalg_lib.LinearOperatorZeros(
          num_rows=2, batch_shape=variables_module.Variable([2]))
Example #2
0
    def test_negative_num_rows_raises_dynamic(self):
        with self.cached_session():
            n = array_ops.placeholder(dtypes.int32)
            operator = linalg_lib.LinearOperatorZeros(
                num_rows=n, assert_proper_shapes=True)
            with self.assertRaisesOpError("must be non-negative"):
                operator.to_dense().eval(feed_dict={n: -2})

            operator = linalg_lib.LinearOperatorZeros(
                num_rows=2, num_columns=n, assert_proper_shapes=True)
            with self.assertRaisesOpError("must be non-negative"):
                operator.to_dense().eval(feed_dict={n: -2})
 def test_negative_num_rows_raises_dynamic(self):
     with self.cached_session():
         n = array_ops.placeholder_with_default(-2, shape=None)
         with self.assertRaisesError("must be non-negative"):
             operator = linalg_lib.LinearOperatorZeros(
                 num_rows=n, assert_proper_shapes=True)
             self.evaluate(operator.to_dense())
 def test_non_scalar_num_rows_raises_dynamic(self):
     with self.cached_session():
         num_rows = array_ops.placeholder_with_default([2], shape=None)
         with self.assertRaisesError("must be a 0-D Tensor"):
             operator = linalg_lib.LinearOperatorZeros(
                 num_rows, assert_proper_shapes=True)
             self.evaluate(operator.to_dense())
Example #5
0
 def test_non_1d_batch_shape_raises_dynamic(self):
     with self.cached_session():
         batch_shape = array_ops.placeholder(dtypes.int32)
         operator = linalg_lib.LinearOperatorZeros(
             num_rows=2, batch_shape=batch_shape, assert_proper_shapes=True)
         with self.assertRaisesOpError("must be a 1-D"):
             operator.to_dense().eval(feed_dict={batch_shape: 2})
Example #6
0
 def test_non_scalar_num_rows_raises_dynamic(self):
     with self.cached_session():
         num_rows = array_ops.placeholder(dtypes.int32)
         operator = linalg_lib.LinearOperatorZeros(
             num_rows, assert_proper_shapes=True)
         with self.assertRaisesOpError("must be a 0-D Tensor"):
             operator.to_dense().eval(feed_dict={num_rows: [2]})
Example #7
0
 def test_non_1d_batch_shape_raises_dynamic(self):
   with self.cached_session():
     batch_shape = array_ops.placeholder_with_default(2, shape=None)
     with self.assertRaisesError("must be a 1-D"):
       operator = linalg_lib.LinearOperatorZeros(
           num_rows=2, batch_shape=batch_shape, assert_proper_shapes=True)
       self.evaluate(operator.to_dense())
    def test_wrong_matrix_dimensions_raises_dynamic(self):
        num_rows = array_ops.placeholder_with_default(2, shape=None)
        x = array_ops.placeholder_with_default(rng.rand(3, 3), shape=None)

        with self.cached_session():
            with self.assertRaisesError("Dimensions.*not.compatible"):
                operator = linalg_lib.LinearOperatorZeros(
                    num_rows, assert_proper_shapes=True, dtype=dtypes.float64)
                self.evaluate(operator.matmul(x))
    def test_zeros_matmul(self):
        operator1 = linalg_lib.LinearOperatorIdentity(num_rows=2)
        operator2 = linalg_lib.LinearOperatorZeros(num_rows=2)
        self.assertTrue(
            isinstance(operator1.matmul(operator2),
                       linalg_lib.LinearOperatorZeros))

        self.assertTrue(
            isinstance(operator2.matmul(operator1),
                       linalg_lib.LinearOperatorZeros))
Example #10
0
    def test_wrong_matrix_dimensions_raises_dynamic(self):
        num_rows = array_ops.placeholder(dtypes.int32)
        x = array_ops.placeholder(dtypes.float32)

        with self.cached_session():
            operator = linalg_lib.LinearOperatorZeros(
                num_rows, assert_proper_shapes=True)
            y = operator.matmul(x)
            with self.assertRaisesOpError("Incompatible.*dimensions"):
                y.eval(feed_dict={num_rows: 2, x: rng.rand(3, 3)})
  def _operator_and_matrix(self, build_info, dtype, use_placeholder):
    del use_placeholder
    shape = list(build_info.shape)
    assert shape[-1] == shape[-2]

    batch_shape = shape[:-2]
    num_rows = shape[-1]

    operator = linalg_lib.LinearOperatorZeros(
        num_rows, batch_shape=batch_shape, dtype=dtype)
    matrix = array_ops.zeros(shape=shape, dtype=dtype)

    return operator, matrix
  def _operator_and_matrix(self, build_info, dtype, use_placeholder):
    del use_placeholder
    shape = list(build_info.shape)

    batch_shape = shape[:-2]
    num_rows = shape[-2]
    num_columns = shape[-1]

    operator = linalg_lib.LinearOperatorZeros(
        num_rows, num_columns, is_square=False, is_self_adjoint=False,
        batch_shape=batch_shape, dtype=dtype)
    matrix = array_ops.zeros(shape=shape, dtype=dtype)

    return operator, matrix
 def test_wrong_matrix_dimensions_raises_static(self):
     operator = linalg_lib.LinearOperatorZeros(num_rows=2)
     x = rng.randn(3, 3).astype(np.float32)
     with self.assertRaisesRegex(ValueError, "Dimensions.*not compatible"):
         operator.matmul(x)
 def test_non_scalar_num_rows_raises_static(self):
     with self.assertRaisesRegex(ValueError, "must be a 0-D Tensor"):
         linalg_lib.LinearOperatorZeros(num_rows=[2])
     with self.assertRaisesRegex(ValueError, "must be a 0-D Tensor"):
         linalg_lib.LinearOperatorZeros(num_rows=2, num_columns=[2])
 def test_assert_non_singular(self):
     with self.assertRaisesOpError("non-invertible"):
         operator = linalg_lib.LinearOperatorZeros(num_rows=2)
         operator.assert_non_singular()
 def test_is_x_flags(self):
     # The is_x flags are by default all True.
     operator = linalg_lib.LinearOperatorZeros(num_rows=2)
     self.assertFalse(operator.is_positive_definite)
     self.assertFalse(operator.is_non_singular)
     self.assertTrue(operator.is_self_adjoint)
 def test_negative_num_rows_raises_static(self):
     with self.assertRaisesRegex(ValueError, "must be non-negative"):
         linalg_lib.LinearOperatorZeros(num_rows=-2)
     with self.assertRaisesRegex(ValueError, "must be non-negative"):
         linalg_lib.LinearOperatorZeros(num_rows=2, num_columns=-2)
 def test_assert_positive_definite(self):
     operator = linalg_lib.LinearOperatorZeros(num_rows=2)
     with self.assertRaisesOpError("non-positive definite"):
         operator.assert_positive_definite()
 def test_non_1d_batch_shape_raises_static(self):
     with self.assertRaisesRegex(ValueError, "must be a 1-D"):
         linalg_lib.LinearOperatorZeros(num_rows=2, batch_shape=2)
 def test_assert_self_adjoint(self):
     with self.cached_session():
         operator = linalg_lib.LinearOperatorZeros(num_rows=2)
         self.evaluate(operator.assert_self_adjoint())  # Should not fail
 def test_non_integer_batch_shape_raises_static(self):
     with self.assertRaisesRegex(TypeError, "must be integer"):
         linalg_lib.LinearOperatorZeros(num_rows=2, batch_shape=[2.])
 def test_non_integer_num_rows_raises_static(self):
     with self.assertRaisesRegex(TypeError, "must be integer"):
         linalg_lib.LinearOperatorZeros(num_rows=2.)
     with self.assertRaisesRegex(TypeError, "must be integer"):
         linalg_lib.LinearOperatorZeros(num_rows=2, num_columns=2.)
 def test_negative_batch_shape_raises_static(self):
     with self.assertRaisesRegex(ValueError, "must be non-negative"):
         linalg_lib.LinearOperatorZeros(num_rows=2, batch_shape=[-2])