docstr: The gradient of the dissimilarity constraint function w.r.t. A.
  
  For example, let distance by L1 norm:
  f = f(\sum_{ij \in D} \sqrt{(x_i-x_j)A(x_i-x_j)'})
  df/dA_{kl} = f'* d(\sum_{ij \in D} \sqrt{(x_i-x_j)^k*(x_i-x_j)^l})/dA_{kl}
  
  Note that d_ij*A*d_ij' = tr(d_ij*A*d_ij') = tr(d_ij'*d_ij*A)
  so, d(d_ij*A*d_ij')/dA = d_ij'*d_ij
      df/dA = f'(\sum_{ij \in D} \sqrt{tr(d_ij'*d_ij*A)})
              * 0.5*(\sum_{ij \in D} (1/sqrt{tr(d_ij'*d_ij*A)})*(d_ij'*d_ij))
docstr_tok: ["The","gradient","of","the","dissimilarity","constraint","function","w.r.t",".","A",".","For","example",",","let","distance","by","L1","norm",":","f","=","f","(","\\sum_","{","ij","\\in","D","}","\\sqrt","{","(","x_i-x_j",")","A","(","x_i-x_j",")","'","}",")","df\/dA_","{","kl","}","=","f","'","*","d","(","\\sum_","{","ij","\\in","D","}","\\sqrt","{","(","x_i-x_j",")","^k","*","(","x_i-x_j",")","^l","}",")","\/dA_","{","kl","}","Note","that","d_ij","*","A","*","d_ij","'","=","tr","(","d_ij","*","A","*","d_ij","'",")","=","tr","(","d_ij","'","*","d_ij","*","A",")","so",",","d","(","d_ij","*","A","*","d_ij","'",")","\/dA","=","d_ij","'","*","d_ij","df\/dA","=","f","'","(","\\sum_","{","ij","\\in","D","}","\\sqrt","{","tr","(","d_ij","'","*","d_ij","*","A",")","}",")","*","0.5","*","(","\\sum_","{","ij","\\in","D","}","(","1\/sqrt","{","tr","(","d_ij","'","*","d_ij","*","A",")","}",")","*","(","d_ij","'","*","d_ij",")",")"]
code: def _fD1(self, neg_pairs, A):
      r"""The gradient of the dissimilarity constraint function w.r.t. A.
  
      For example, let distance by L1 norm:
      f = f(\sum_{ij \in D} \sqrt{(x_i-x_j)A(x_i-x_j)'})
      df/dA_{kl} = f'* d(\sum_{ij \in D} \sqrt{(x_i-x_j)^k*(x_i-x_j)^l})/dA_{kl}
  
      Note that d_ij*A*d_ij' = tr(d_ij*A*d_ij') = tr(d_ij'*d_ij*A)
      so, d(d_ij*A*d_ij')/dA = d_ij'*d_ij
          df/dA = f'(\sum_{ij \in D} \sqrt{tr(d_ij'*d_ij*A)})
                  * 0.5*(\sum_{ij \in D} (1/sqrt{tr(d_ij'*d_ij*A)})*(d_ij'*d_ij))
      """
      diff = neg_pairs[:, 0, :] - neg_pairs[:, 1, :]
      # outer products of all rows in `diff`
      M = np.einsum("ij,ik->ijk", diff, diff)
      # faster version of: dist = np.sqrt(np.sum(M * A[None,:,:], axis=(1,2)))
      dist = np.sqrt(np.einsum("ijk,jk", M, A))
      # faster version of: sum_deri = np.sum(M /
      # (2 * (dist[:,None,None] + 1e-6)), axis=0)
      sum_deri = np.einsum("ijk,i->jk", M, 0.5 / (dist + 1e-6))
      sum_dist = dist.sum()
      return sum_deri / (sum_dist + 1e-6)
  
imports: import numpy
  from sklearn.base import TransformerMixin
  from sklearn.utils.validation import assert_all_finite
  from .base_metric import _PairsClassifierMixin, MahalanobisMixin
  from .constraints import Constraints, wrap_pairs
  from ._util import components_from_metric, _initialize_metric_mahalanobis
  import warnings
label_desc: Use image node_id 6 for calling the _BaseMMC obj's underlying member method code with example usage: obj._fD1(neg_pairs, A) and returns: unknown