From 94ac895f0144058aee5c5503320edff16d4e41dd Mon Sep 17 00:00:00 2001 From: Zhao Liang Date: Thu, 24 Nov 2022 12:43:02 +0800 Subject: [PATCH] [Lang] Fix warning messages (#6716) 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> --- .gitignore | 1 + python/taichi/_kernels.py | 2 +- python/taichi/examples/features/gui/gui_image_io.py | 2 +- python/taichi/ui/staging_buffer.py | 11 ++++++----- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 8ec0247e17ac8..868b1ae350d69 100644 --- a/.gitignore +++ b/.gitignore @@ -89,3 +89,4 @@ imgui.ini .cache .do-not-clean *.dylib +*.ply diff --git a/python/taichi/_kernels.py b/python/taichi/_kernels.py index 97091d447e0a9..5b743ecced0e8 100644 --- a/python/taichi/_kernels.py +++ b/python/taichi/_kernels.py @@ -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] diff --git a/python/taichi/examples/features/gui/gui_image_io.py b/python/taichi/examples/features/gui/gui_image_io.py index 4c301058ba19d..84cbbffecac65 100644 --- a/python/taichi/examples/features/gui/gui_image_io.py +++ b/python/taichi/examples/features/gui/gui_image_io.py @@ -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() diff --git a/python/taichi/ui/staging_buffer.py b/python/taichi/ui/staging_buffer.py index a19c98e8a84c4..bee7e3feb61bc 100644 --- a/python/taichi/ui/staging_buffer.py +++ b/python/taichi/ui/staging_buffer.py @@ -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 @@ -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) @@ -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: @@ -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) @@ -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)