Skip to content

Created .ceil() entry for PyTorch #7030

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 9, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions content/pytorch/concepts/tensor-operations/terms/ceil/ceil.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
Title: '.ceil()'
Description: 'Returns a new tensor with the smallest integer greater than or equal to each element of the input tensor.'
Subjects:
- 'Computer Science'
- 'Machine Learning'
Tags:
- 'Functions'
- 'Machine Learning'
- 'Python'
- 'Values'
CatalogContent:
- 'intro-to-py-torch-and-neural-networks'
- 'paths/computer-science'
---

In PyTorch, the **`.ceil()`** function returns a new tensor with the smallest integer greater than or equal to each element of the input tensor. This operation is commonly used in applications that require rounding values up, such as setting upper bounds in optimization problems, discretizing continuous outputs, or preparing pixel-based image data where fractional values are invalid.

## Syntax

```pseudo
torch.ceil(input,*, out=None)
```

**Parameters:**

- `input`: The input tensor whose elements are to be rounded up.
- `out` (optional): A tensor to store the output. Must have the same shape as `input`.

**Return value:**

The `.ceil()` returns a new tensor containing the ceiling values of each element in the `input` tensor. Unless the `out` parameter is specified, the result is a new tensor.

## Example: Applying `.ceil()` to a 1D Tensor

```py
import torch

# Create a tensor
x = torch.tensor([1.2, -0.8, 3.0, -2.7, 5.5])

# Apply the ceil operation
y = torch.ceil(x)

print(f"Original tensor: {x}")
print(f"Ceil tensor: {y}")
```

This program gives the following output:

```shell
Original tensor: tensor([ 1.2000, -0.8000, 3.0000, -2.7000, 5.5000])
Ceil tensor: tensor([ 2., -0., 3., -2., 6.])
```

> **Note:** The result may display `-0.` due to floating-point formatting, but it is functionally equivalent to `0.`.