Python tensorflow.python.ops.array_ops.diag_part() Examples
The following are 11
code examples of tensorflow.python.ops.array_ops.diag_part().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
tensorflow.python.ops.array_ops
, or try the search function
.
Example #1
Source File: array_grad.py From lambda-packs with MIT License | 5 votes |
def _DiagGrad(_, grad): return array_ops.diag_part(grad)
Example #2
Source File: init_ops.py From lambda-packs with MIT License | 5 votes |
def __call__(self, shape, dtype=None, partition_info=None): if dtype is None: dtype = self.dtype # Check the shape if len(shape) < 2: raise ValueError("The tensor to initialize must be " "at least two-dimensional") # Flatten the input shape with the last dimension remaining # its original shape so it works for conv2d num_rows = 1 for dim in shape[:-1]: num_rows *= dim num_cols = shape[-1] flat_shape = (num_rows, num_cols) # Generate a random matrix a = random_ops.random_normal(flat_shape, dtype=dtype, seed=self.seed) # Compute the qr factorization q, r = linalg_ops.qr(a, full_matrices=False) # Make Q uniform square_len = math_ops.minimum(num_rows, num_cols) d = array_ops.diag_part(r[:square_len, :square_len]) ph = d / math_ops.abs(d) q *= ph # Pad zeros to Q (if rows smaller than cols) if num_rows < num_cols: padding = array_ops.zeros([num_rows, num_cols - num_rows], dtype=dtype) q = array_ops.concat([q, padding], 1) return self.gain * array_ops.reshape(q, shape)
Example #3
Source File: operator_pd_cholesky.py From lambda-packs with MIT License | 5 votes |
def _batch_log_det(self): """Log determinant of every batch member.""" # Note that array_ops.diag_part does not seem more efficient for non-batch, # and would give a bad result for a batch matrix, so aways use # matrix_diag_part. diag = array_ops.matrix_diag_part(self._chol) det = 2.0 * math_ops.reduce_sum(math_ops.log(math_ops.abs(diag)), reduction_indices=[-1]) det.set_shape(self.get_shape()[:-2]) return det
Example #4
Source File: array_grad.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def _DiagGrad(_, grad): return array_ops.diag_part(grad)
Example #5
Source File: operator_pd_cholesky.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def _batch_log_det(self): """Log determinant of every batch member.""" # Note that array_ops.diag_part does not seem more efficient for non-batch, # and would give a bad result for a batch matrix, so aways use # matrix_diag_part. diag = array_ops.matrix_diag_part(self._chol) det = 2.0 * math_ops.reduce_sum(math_ops.log(math_ops.abs(diag)), reduction_indices=[-1]) det.set_shape(self.get_shape()[:-2]) return det
Example #6
Source File: array_grad.py From deep_image_model with Apache License 2.0 | 5 votes |
def _DiagGrad(_, grad): return array_ops.diag_part(grad)
Example #7
Source File: operator_pd_cholesky.py From deep_image_model with Apache License 2.0 | 5 votes |
def _batch_log_det(self): """Log determinant of every batch member.""" # Note that array_ops.diag_part does not seem more efficient for non-batch, # and would give a bad result for a batch matrix, so aways use # matrix_diag_part. diag = array_ops.matrix_diag_part(self._chol) det = 2.0 * math_ops.reduce_sum(math_ops.log(diag), reduction_indices=[-1]) det.set_shape(self.get_shape()[:-2]) return det
Example #8
Source File: array_grad.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 5 votes |
def _DiagGrad(_, grad): return array_ops.diag_part(grad)
Example #9
Source File: init_ops.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 5 votes |
def __call__(self, shape, dtype=None, partition_info=None): if dtype is None: dtype = self.dtype # Check the shape if len(shape) < 2: raise ValueError("The tensor to initialize must be " "at least two-dimensional") # Flatten the input shape with the last dimension remaining # its original shape so it works for conv2d num_rows = 1 for dim in shape[:-1]: num_rows *= dim num_cols = shape[-1] flat_shape = (num_cols, num_rows) if num_rows < num_cols else (num_rows, num_cols) # Generate a random matrix a = random_ops.random_normal(flat_shape, dtype=dtype, seed=self.seed) # Compute the qr factorization q, r = linalg_ops.qr(a, full_matrices=False) # Make Q uniform d = array_ops.diag_part(r) ph = d / math_ops.abs(d) q *= ph if num_rows < num_cols: q = array_ops.matrix_transpose(q) return self.gain * array_ops.reshape(q, shape)
Example #10
Source File: array_grad.py From keras-lambda with MIT License | 5 votes |
def _DiagGrad(_, grad): return array_ops.diag_part(grad)
Example #11
Source File: operator_pd_cholesky.py From keras-lambda with MIT License | 5 votes |
def _batch_log_det(self): """Log determinant of every batch member.""" # Note that array_ops.diag_part does not seem more efficient for non-batch, # and would give a bad result for a batch matrix, so aways use # matrix_diag_part. diag = array_ops.matrix_diag_part(self._chol) det = 2.0 * math_ops.reduce_sum(math_ops.log(math_ops.abs(diag)), reduction_indices=[-1]) det.set_shape(self.get_shape()[:-2]) return det