Issue 1:
Currently F.pairwise_distance and F.cosine_similarity accept two sets of vectors of the same size and compute similarity between corresponding vectors.

However, it's often useful to compute pairwise similarities or distances between all points of the set (in mini-batch metric learning scenarios), or between all possible pairs of two sets (e.g. to build a bi-partite weighted graph). It's trivial to write ad-hoc functions like this, but I believe it's also a useful and a frequent primitive (for euclidean, square euclidean, etc).

One way to introduce this would be modifying pairwise_distance to allow other shapes and an argument for metric type.

Such a function for example exists in SciPy: https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.distance.pdist.html (computes all pairwise distances within one set of vectors)

Also exists in MatLab: https://www.mathworks.com/help/stats/pdist.html

Issue 2:
Steps to reproduce:

Build Caffe2 (e.g., with python setup_caffe2.py develop) at def3715

Apply 6a55238 Grid sampler: nearest interpolation & reflection padding (#10051) and rebuild

Actual result:

./caffe2/contrib/aten/aten_op.h:8536:75: error: too few arguments to function ‘at::Tensor at::grid_sampler
(const at::Tensor&, const at::Tensor&, int64_t, int64_t)’
auto the_result = at::grid_sampler(input, grid, padding_mode);
^
In file included from ../aten/src/ATen/ATen.h:13:0,
from ./caffe2/contrib/aten/aten_op.h:4,
from ../caffe2/contrib/aten/aten_op.cc:1:
aten/src/ATen/Functions.h:3589:22: note: declared here
static inline Tensor grid_sampler(const Tensor & input, const Tensor & grid, int64_t interpolation_mode,
int64_t padding_mode) {
^
In file included from /usr/include/c++/4.8.2/memory:79:0,
from ../aten/src/ATen/Allocator.h:3,
from ../aten/src/ATen/ATen.h:4,
from ./caffe2/contrib/aten/aten_op.h:4,
from ../caffe2/contrib/aten/aten_op.cc:1:
/usr/include/c++/4.8.2/functional: In substitution of ‘template<class _Res, class ... _ArgTypes> template<
class _Functor> using _Invoke = decltype (std::__callable_functor(declval<_Functor&>())((declval<_ArgTypes
>)()...)) [with _Functor = std::decay<caffe2::ATenOp<Context>::ATenOp(const caffe2::OperatorDef&, caffe2::
Workspace*) [with Context = caffe2::CPUContext]::__lambda660>::type; _Res = bool; _ArgTypes = {}]’:
/usr/include/c++/4.8.2/functional:2334:2: required by substitution of ‘template<class _Functor> std::fun
ction<_Res(_ArgTypes ...)>::_Requires<std::__and_<std::__not_<std::is_same<typename std::decay<_Tp>::type,
std::function<_Res(_ArgTypes ...)> > >, std::__or_<std::is_void<_Tp>, std::is_convertible<std::function<_
Res(_ArgTypes ...)>::_Invoke<typename std::decay<_Tp>::type>, _Res> > >, std::function<_Res(_ArgTypes ...)
>&> std::function<_Res(_ArgTypes ...)>::operator=(_Functor&&) [with _Functor = _Functor; _Res = bool; _Arg
Types = {}] [with _Functor = caffe2::ATenOp<Context>::ATenOp(const caffe2::OperatorDef&, caffe2::Workspace
*) [with Context = caffe2::CPUContext]::__lambda660]’
./caffe2/contrib/aten/aten_op.h:8544:18: required from ‘caffe2::ATenOp<Context>::ATenOp(const caffe2::Op
eratorDef&, caffe2::Workspace*) [with Context = caffe2::CPUContext]’
../caffe2/core/registry.h:131:50: required from ‘static ObjectPtrType caffe2::Registerer<SrcType, Object
PtrType, Args>::DefaultCreator(Args ...) [with DerivedType = caffe2::ATenOp<caffe2::CPUContext>; SrcType =
std::basic_string<char>; ObjectPtrType = std::unique_ptr<caffe2::OperatorBase>; Args = {const caffe2::Ope
ratorDef&, caffe2::Workspace*}]’
../caffe2/contrib/aten/aten_op.cc:6:1: required from here
/usr/include/c++/4.8.2/functional:2181:71: error: use of ‘caffe2::ATenOp<Context>::ATenOp(const caffe2::Op
eratorDef&, caffe2::Workspace*) [with Context = caffe2::CPUContext]::__lambda660’ before deduction of ‘aut
o’
using _Invoke = decltype(__callable_functor(std::declval<_Functor&>())
^