aten/src/ATen/native/sparse/SparseTensor.cpp
// NB: Got rid of the sizes == NULL case
Got rid of the sizes == NULL case
Got rid of the sizes == NULL case
SparseTensor new_with_tensor_and_size_unsafe_sparse(const LongTensor& indices, const Tensor& values_, ArrayRef<int64_t> sizes) {
  Tensor values;
  if (values_.dim() == 0) {
    values = values_.expand({1});
  } else {
    values = values_;
  }
  const SparseType& dtype = values.type().toSparse();
  if (indices.numel() == 0 && values.numel() == 0) {
    return new_with_size_sparse(dtype, sizes);
  }
  int64_t sparseDims = indices.size(0);
  int64_t denseDims = values.dim() - 1;
  return _new_with_dims_and_tensor_sparse(dtype, sparseDims, denseDims, sizes, indices, values);
}
SparseTensor new_with_tensor_and_size_unsafe_sparse ( const LongTensor & indices , const Tensor & values_ , ArrayRef < int64_t > sizes ) { Tensor values ; if ( values_ . dim ( ) == 0 ) { values = values_ . expand ( { 1 } ) ; } else { values = values_ ; } const SparseType & dtype = values . type ( ) . toSparse ( ) ; if ( indices . numel ( ) == 0 && values . numel ( ) == 0 ) { return new_with_size_sparse ( dtype , sizes ) ; } int64_t sparseDims = indices . size ( 0 ) ; int64_t denseDims = values . dim ( ) - 1 ; return _new_with_dims_and_tensor_sparse ( dtype , sparseDims , denseDims , sizes , indices , values ) ; }
NB: Got rid of the sizes == NULL case
NB : Got rid of the sizes == NULL case
// Mimic Numpy behavior here and treat it as a 1D tensor // NB: used to be a dim() == 0 test, but that's legacy TH semantics