class_docstr: Optimizer that implements the Conditional Gradient optimization.
  
  This optimizer helps handle constraints well.
  
  Currently only supports frobenius norm constraint or nuclear norm
  constraint.
  See https://arxiv.org/pdf/1803.06453.pdf
  
  ```
  variable -= (1-learning_rate) * (variable + lambda_ * gradient
      / (frobenius_norm(gradient) + epsilon))
  ```
  
  Note that `lambda_` here refers to the constraint "lambda" in
  the paper. `epsilon` is constant with tiny value as compared to
  the value of frobenius norm of gradient. The purpose of `epsilon`
  here is to avoid the case that the value of frobenius norm of
  gradient is 0.
  
  In this implementation, `epsilon` defaults to $10^{-7}$.
  
  For nucler norm constraint, the formula is as following:
  
  ```
  variable -= (1-learning_rate) * (variable
      + lambda_ * top_singular_vector(gradient))
  ```
class_docstr_tok: ["Optimizer","that","implements","the","Conditional","Gradient","optimization",".","This","optimizer","helps","handle","constraints","well",".","Currently","only","supports","frobenius","norm","constraint","or","nuclear","norm","constraint",".","See","https",":","\/\/arxiv.org\/pdf\/1803.06453.pdf","``","`","variable","-=","(","1-learning_rate",")","*","(","variable","+","lambda_","*","gradient","\/","(","frobenius_norm","(","gradient",")","+","epsilon",")",")","``","`","Note","that","`","lambda_","`","here","refers","to","the","constraint","``","lambda","''","in","the","paper",".","`","epsilon","`","is","constant","with","tiny","value","as","compared","to","the","value","of","frobenius","norm","of","gradient",".","The","purpose","of","`","epsilon","`","here","is","to","avoid","the","case","that","the","value","of","frobenius","norm","of","gradient","is","0",".","In","this","implementation",",","`","epsilon","`","defaults","to","$","10^","{","-7","}","$",".","For","nucler","norm","constraint",",","the","formula","is","as","following",":","``","`","variable","-=","(","1-learning_rate",")","*","(","variable","+","lambda_","*","top_singular_vector","(","gradient",")",")","``","`"]
code: def _top_singular_vector(m):
      # handle the case where m is a tensor of rank 0 or rank 1.
      # Example:
      #   scalar (rank 0) a, shape []=> [[a]], shape [1,1]
      #   vector (rank 1) [a,b], shape [2] => [[a,b]], shape [1,2]
      original_rank = tf.rank(m)
      shape = tf.shape(m)
      first_pad = tf.cast(tf.less(original_rank, 2), dtype=tf.int32)
      second_pad = tf.cast(tf.equal(original_rank, 0), dtype=tf.int32)
      new_shape = tf.concat(
          [
              tf.ones(shape=first_pad, dtype=tf.int32),
              tf.ones(shape=second_pad, dtype=tf.int32),
              shape,
          ],
          axis=0,
      )
      n = tf.reshape(m, new_shape)
      st, ut, vt = tf.linalg.svd(n, full_matrices=False)
      n_size = tf.shape(n)
      ut = tf.reshape(ut[:, 0], [n_size[0], 1])
      vt = tf.reshape(vt[:, 0], [n_size[1], 1])
      st = tf.matmul(ut, tf.transpose(vt))
      # when we return the top singular vector, we have to remove the
      # dimension we have added on
      st_shape = tf.shape(st)
      begin = tf.cast(tf.less(original_rank, 2), dtype=tf.int32)
      end = 2 - tf.cast(tf.equal(original_rank, 0), dtype=tf.int32)
      new_shape = st_shape[begin:end]
      return tf.reshape(st, new_shape)
  
file_path: addons/tensorflow_addons/optimizers/conditional_gradient.py
imports: import tensorflow
  from tensorflow_addons.optimizers import KerasLegacyOptimizer
  from tensorflow_addons.utils.types import FloatTensorLike
  from typeguard import typechecked
  from typing import Union, Callable
label_desc: Use image node_id 6 for calling the ConditionalGradient obj's underlying member method code with example usage: obj._top_singular_vector(m) and returns: tf