A question on how to use at::Tensor & clamp_min_ function


I am trying to use at::Tensor & clamp_min_ function which takes two arguments, one is the tensor passed by reference and the other one is the scalar passed by the const reference.
The inline function is:

inline at::Tensor & clamp_min_(at::Tensor & self, const at::Tensor & min) {
     return at::_ops::clamp_min__Tensor::call(self, min);

In my codes, I tried to call by doing this:

const at::Scalar testmin(0);
torch::Tensor::clamp_min_(yPreds_ts, testmin);

However, the error appears when compiling, which follows:

error: no matching function for call to ‘at::Tensor::clamp_min_(at::Tensor&, const c10::Scalar&)’
  207 |     torch::Tensor::clamp_min_(yPreds_ts, testmin);

I am not sure of the reason. Has anyone met a similar issue before?

Thanks, Weitao.

if there’s a trailing underscore, its a member of the tensor.

Can you try this instead:


yes, yPreds_ts.clamp_min_(testmin) works well. Thanks! :smiley: