Skip to content

Commit

Permalink
small example
Browse files Browse the repository at this point in the history
  • Loading branch information
Doug Friedman committed Sep 18, 2018
1 parent 39520ff commit 4c7dba7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
7 changes: 7 additions & 0 deletions aten/src/ATen/native/TensorShape.cpp
Expand Up @@ -148,6 +148,13 @@ Tensor &as_strided_(Tensor& self, IntList size, IntList stride) {
return at::as_strided_(self, size, stride, self.storage_offset());
}

Tensor my_op(const Tensor& self) {
if(self.is_sparse()){
printf("%ld\n", self._sparseDims()); // prints "2"
printf("%lld\n", _get_sparse_impl(self)->sparseDims()); // prints "140495002593472" on CPU; segfault on CUDA
}
}

Tensor narrow(const Tensor& self, int64_t dim, int64_t start, int64_t length) {
AT_CHECK(self.dim() > 0, "narrow() cannot be applied to a 0-dim tensor.");
auto cur_size = self.size(dim);
Expand Down
3 changes: 3 additions & 0 deletions aten/src/ATen/native/native_functions.yaml
Expand Up @@ -1188,6 +1188,9 @@
- func: mvlgamma_(Tensor self, int64_t p) -> Tensor
variants: method

- func: my_op(Tensor self) -> Tensor
variants: method

- func: narrow(Tensor self, int64_t dim, int64_t start, int64_t length) -> Tensor
variants: function, method

Expand Down

0 comments on commit 4c7dba7

Please sign in to comment.