aten/src/ATen/native/Gesv.cpp
// Supports arbitrary batch dimensions for self and A
Supports arbitrary batch dimensions for self and A
Supports arbitrary batch dimensions for self and A
std::tuple<Tensor,Tensor> gesv(const Tensor& self, const Tensor& A) {
  if (self.dim() <= 2 && A.dim() <= 2) {
    return at::_gesv_single(self, A);
  }
  checkInputs(self, A);
  IntList self_batch_sizes(self.sizes().data(), self.ndimension() - 2);
  IntList A_batch_sizes(A.sizes().data(), A.ndimension() - 2);
  std::vector<int64_t> expand_batch_portion =
      infer_size(self_batch_sizes, A_batch_sizes);
  std::vector<int64_t> self_expand_size({expand_batch_portion});
  self_expand_size.insert(self_expand_size.end(),
      { self.size(-2), self.size(-1) });
  std::vector<int64_t> A_expand_size({expand_batch_portion});
  A_expand_size.insert(A_expand_size.end(),
      { A.size(-2), A.size(-1) });
  Tensor self_broadcasted  = self.expand(self_expand_size);
  Tensor A_broadcasted = A.expand(A_expand_size);
  return self.type()._gesv_helper(self_broadcasted, A_broadcasted);
}
std :: tuple < Tensor , Tensor > gesv ( const Tensor & self , const Tensor & A ) { if ( self . dim ( ) <= 2 && A . dim ( ) <= 2 ) { return at :: _gesv_single ( self , A ) ; } checkInputs ( self , A ) ; IntList self_batch_sizes ( self . sizes ( ) . data ( ) , self . ndimension ( ) - 2 ) ; IntList A_batch_sizes ( A . sizes ( ) . data ( ) , A . ndimension ( ) - 2 ) ; std :: vector < int64_t > expand_batch_portion = infer_size ( self_batch_sizes , A_batch_sizes ) ; std :: vector < int64_t > self_expand_size ( { expand_batch_portion } ) ; self_expand_size . insert ( self_expand_size . end ( ) , { self . size ( -2 ) , self . size ( -1 ) } ) ; std :: vector < int64_t > A_expand_size ( { expand_batch_portion } ) ; A_expand_size . insert ( A_expand_size . end ( ) , { A . size ( -2 ) , A . size ( -1 ) } ) ; Tensor self_broadcasted = self . expand ( self_expand_size ) ; Tensor A_broadcasted = A . expand ( A_expand_size ) ; return self . type ( ) . _gesv_helper ( self_broadcasted , A_broadcasted ) ; }
Supports arbitrary batch dimensions for self and A
Supports arbitrary batch dimensions for self and A
// TODO: #7102: It's not necessary to have gesv (single) bindings for both // TH and ATen. We should remove the TH gesv bindings, especially // since the lapackGesv function is already in ATen. // broadcast the batch dimensions of self and A.