Skip to content

Commit

Permalink
[Lang] Fix warning messages (taichi-dev#6716)
Browse files Browse the repository at this point in the history
This PR fixes some warning messages in the official code. Also, forbid
committing `.ply` files generated by running the `diff_sph` example in
this repo.

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
2 people authored and quadpixels committed May 13, 2023
1 parent 9572f9a commit 94ac895
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,4 @@ imgui.ini
.cache
.do-not-clean
*.dylib
*.ply
2 changes: 1 addition & 1 deletion python/taichi/_kernels.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def vector_to_fast_image(img: template(), out: ndarray_type.ndarray()):
r, g, b = 0, 0, 0
color = img[i, img.shape[1] - 1 - j]
if static(img.dtype in [f16, f32, f64]):
r, g, b = min(255, max(0, int(color * 255)))[:3]
r, g, b = ops.min(255, ops.max(0, int(color * 255)))[:3]
else:
static_assert(img.dtype == u8)
r, g, b = color[:3]
Expand Down
2 changes: 1 addition & 1 deletion python/taichi/examples/features/gui/gui_image_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@ti.kernel
def paint():
for I in ti.grouped(pixel):
pixel[I] = ti.random() * 255
pixel[I] = ti.u8(ti.random() * 255)


paint()
Expand Down
11 changes: 6 additions & 5 deletions python/taichi/ui/staging_buffer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy as np
from taichi.lang import ops
from taichi.lang._texture import Texture
from taichi.lang.impl import ndarray
from taichi.lang.kernel_impl import kernel
Expand Down Expand Up @@ -98,7 +99,7 @@ def copy_texture_to_rgba8(src: ti.types.texture(num_dimensions=2),
dst: ti.template(), w: ti.i32, h: ti.i32):
for (i, j) in ti.ndrange(w, h):
c = src.fetch(ti.Vector([i, j]), 0)
c = max(0.0, min(1.0, c))
c = ops.max(0.0, ops.min(1.0, c))
c = c * 255
px = ti.cast(c, u32)
dst[i, j] = (px[0] << 0 | px[1] << 8 | px[2] << 16 | px[3] << 24)
Expand All @@ -113,7 +114,7 @@ def copy_image_f32_to_rgba8(src: ti.template(), dst: ti.template(),
if ti.static(gray_scale):
c = 0.0
c = src[i, j]
c = max(0.0, min(1.0, c))
c = ops.max(0.0, ops.min(1.0, c))
c = c * 255
px[0] = px[1] = px[2] = ti.cast(c, u32)
else:
Expand All @@ -125,7 +126,7 @@ def copy_image_f32_to_rgba8(src: ti.template(), dst: ti.template(),
else:
# 2D vector field source image
c = src[i, j][k]
c = max(0.0, min(1.0, c))
c = ops.max(0.0, ops.min(1.0, c))
c = c * 255
px[k] = ti.cast(c, u32)
pack = (px[0] << 0 | px[1] << 8 | px[2] << 16 | px[3] << 24)
Expand All @@ -142,13 +143,13 @@ def copy_image_f32_to_rgba8_np(src: ti.types.ndarray(), dst: ti.template(),
if ti.static(gray_scale):
c = 0.0
c = src[i, j]
c = max(0.0, min(1.0, c))
c = ops.max(0.0, ops.min(1.0, c))
c = c * 255
px[0] = px[1] = px[2] = ti.cast(c, u32)
else:
for k in ti.static(range(num_components)):
c = src[i, j, k]
c = max(0.0, min(1.0, c))
c = ops.max(0.0, ops.min(1.0, c))
c = c * 255
px[k] = ti.cast(c, u32)
pack = (px[0] << 0 | px[1] << 8 | px[2] << 16 | px[3] << 24)
Expand Down

0 comments on commit 94ac895

Please sign in to comment.