def _operator_and_mat_and_feed_dict(self, shape, dtype, use_placeholder): sess = ops.get_default_session() shape = list(shape) # Either 1 or 2 matrices, depending. num_operators = rng.randint(low=1, high=3) matrices = [ linear_operator_test_util.random_positive_definite_matrix(shape, dtype, force_well_conditioned=True) for _ in range(num_operators) ] if use_placeholder: matrices_ph = [array_ops.placeholder(dtype=dtype) for _ in range(num_operators)] # Evaluate here because (i) you cannot feed a tensor, and (ii) # values are random and we want the same value used for both mat and # feed_dict. matrices = sess.run(matrices) operator = linalg.LinearOperatorComposition([linalg.LinearOperatorMatrix(m_ph) for m_ph in matrices_ph]) feed_dict = {m_ph: m for (m_ph, m) in zip(matrices_ph, matrices)} else: operator = linalg.LinearOperatorComposition([linalg.LinearOperatorMatrix(m) for m in matrices]) feed_dict = None # Convert back to Tensor. Needed if use_placeholder, since then we have # already evaluated each matrix to a numpy array. apply_order_list = list(reversed(matrices)) mat = ops.convert_to_tensor(apply_order_list[0]) for other_mat in apply_order_list[1:]: mat = math_ops.matmul(other_mat, mat) return operator, mat, feed_dict
def _operator_and_mat_and_feed_dict(self, shape, dtype, use_placeholder): shape = list(shape) matrix = linear_operator_test_util.random_positive_definite_matrix( shape, dtype, force_well_conditioned=True) if use_placeholder: matrix_ph = array_ops.placeholder(dtype=dtype) # Evaluate here because (i) you cannot feed a tensor, and (ii) # values are random and we want the same value used for both mat and # feed_dict. matrix = matrix.eval() # is_square is auto-set because of self_adjoint/pd. operator = linalg.LinearOperatorFullMatrix( matrix_ph, is_self_adjoint=True, is_positive_definite=True) feed_dict = {matrix_ph: matrix} else: operator = linalg.LinearOperatorFullMatrix( matrix, is_self_adjoint=True, is_positive_definite=True) feed_dict = None # Convert back to Tensor. Needed if use_placeholder, since then we have # already evaluated matrix to a numpy array. mat = ops.convert_to_tensor(matrix) return operator, mat, feed_dict
def _operator_and_mat_and_feed_dict(self, shape, dtype, use_placeholder): sess = tf.get_default_session() shape = list(shape) # Either 1 or 2 matrices, depending. num_operators = rng.randint(low=1, high=3) matrices = [ linear_operator_test_util.random_positive_definite_matrix( shape, dtype, force_well_conditioned=True) for _ in range(num_operators) ] if use_placeholder: matrices_ph = [tf.placeholder(dtype=dtype) for _ in range(num_operators)] # Evaluate here because (i) you cannot feed a tensor, and (ii) # values are random and we want the same value used for both mat and # feed_dict. matrices = sess.run(matrices) operator = linalg.LinearOperatorComposition( [linalg.LinearOperatorMatrix(m_ph) for m_ph in matrices_ph]) feed_dict = {m_ph: m for (m_ph, m) in zip(matrices_ph, matrices)} else: operator = linalg.LinearOperatorComposition( [linalg.LinearOperatorMatrix(m) for m in matrices]) feed_dict = None # Convert back to Tensor. Needed if use_placeholder, since then we have # already evaluated each matrix to a numpy array. apply_order_list = list(reversed(matrices)) mat = tf.convert_to_tensor(apply_order_list[0]) for other_mat in apply_order_list[1:]: mat = tf.matmul(other_mat, mat) return operator, mat, feed_dict
def _operator_and_mat_and_feed_dict(self, shape, dtype, use_placeholder): shape = list(shape) matrix = linear_operator_test_util.random_positive_definite_matrix( shape, dtype) if use_placeholder: matrix_ph = tf.placeholder(dtype=dtype) # Evaluate here because (i) you cannot feed a tensor, and (ii) # values are random and we want the same value used for both mat and # feed_dict. matrix = matrix.eval() operator = linalg.LinearOperatorMatrix(matrix) feed_dict = {matrix_ph: matrix} else: operator = linalg.LinearOperatorMatrix(matrix) feed_dict = None # Convert back to Tensor. Needed if use_placeholder, since then we have # already evaluated matrix to a numpy array. mat = tf.convert_to_tensor(matrix) return operator, mat, feed_dict
def _operator_and_mat_and_feed_dict(self, shape, dtype, use_placeholder): shape = list(shape) matrix = linear_operator_test_util.random_positive_definite_matrix( shape, dtype) if use_placeholder: matrix_ph = tf.placeholder(dtype=dtype) # Evaluate here because (i) you cannot feed a tensor, and (ii) # values are random and we want the same value used for both mat and # feed_dict. matrix = matrix.eval() operator = linalg.LinearOperatorMatrix(matrix) feed_dict = {matrix_ph: matrix} else: operator = linalg.LinearOperatorMatrix(matrix) feed_dict = None # Convert back to Tensor. Needed if use_placeholder, since then we have # already evaluated matrix to a numpy array. mat = tf.convert_to_tensor(matrix) return operator, mat, feed_dict