tensorflow / tensorflow/tensorflow

tf.raw_ops.Digamma(0) returns NaN instead of -inf

Open
#111,917 2 comments 0 reactions 1 assignee View on GitHub

@Kayyuri is already working on this.

Since Aug 24, 2026.

2.20.0 comp:ops stat:contribution welcome type:bug
Dominant language
C++
Stars
200k
Forks
76.9k
Avg merge
2d 3h
Merged PRs (30d)
433

Description

Issue type

Bug

Have you reproduced the bug with TensorFlow Nightly?

Yes

Source

source

TensorFlow version

tf 2.20

Custom code

Yes

OS platform and distribution

macOS 15.6.1

Mobile device

No response

Python version

3.13

Bazel version

No response

GCC/compiler version

No response

CUDA/cuDNN version

No response

GPU model and memory

No response

Current behavior?
Description

When calling tf.raw_ops.Digamma with input 0, TensorFlow returns NaN.
However, mathematically the Digamma function ψ(x) has a pole at zero and its limit is -inf.
Other numerical libraries such as PyTorch and SciPy return -inf for the same input. This suggests that TensorFlow’s implementation may produce a numerical instability near the pole instead of returning the expected limit.

Standalone code to reproduce the issue
import tensorflow as tf
import torch
import numpy as np
from scipy.special import digamma

input = np.array([0.0], dtype=np.float32)
x_tf = tf.constant(input)
out_tf = tf.raw_ops.Digamma(x=x_tf)
print(out_tf)

x_torch = torch.tensor(input, dtype=torch.float32)
out_torch = torch.digamma(x_torch)
print(out_torch)

out_scipy = digamma(input)
print(out_scipy)
Relevant log output
tf.Tensor([nan], shape=(1,), dtype=float32)
tensor([-inf])
[-inf]

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.