Trouble using ATen methods in native function

I am adding a native function and having trouble using other utility methods w/in ATen. For example, see this simple native function

This is the quick test I’m using:

import torch

s = torch.sparse.DoubleTensor(
                torch.LongTensor([[0,2,0], [0,2,1]]),
                torch.FloatTensor([[1,2],[3,4],[5,6]]),
                torch.Size([3,3,2]))

s.my_op()

Calling self._sparseDims() on line 153 works just fine as expected. This function is part of the public API and is dispatched to _sparseDims_sparse here, which calls _get_sparse_impl. And _get_sparse_impl is defined in this header, which is included in the file I’m defining my function in.

So the question is this: what magic am I missing to be able to use the same helper function in the same way in my native op?

For reference, this is the native function I added:

aten/src/ATen/native/TensorShape.cpp

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
  }
}

native_functions.yaml

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