From 6a36e1e478301768b3e2f008b1d03f726cd2bb13 Mon Sep 17 00:00:00 2001 From: Xiaochun Tong Date: Sun, 24 Sep 2023 10:14:44 -0400 Subject: [PATCH] added more tests --- luisa_compute/src/rtx.rs | 4 ++- luisa_compute/tests/misc.rs | 51 +++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/luisa_compute/src/rtx.rs b/luisa_compute/src/rtx.rs index 1ba2f80..50d9295 100644 --- a/luisa_compute/src/rtx.rs +++ b/luisa_compute/src/rtx.rs @@ -388,7 +388,7 @@ pub enum HitType { Procedural = 2, } -pub fn offset_ray_origin(p: Expr, n: Expr) -> Expr { +pub fn offset_ray_origin(p: impl AsExpr, n: impl AsExpr) -> Expr { lazy_static! { static ref F: Callable, Expr) -> Expr> = Callable::, Expr) -> Expr>::new_static(|p, n| { @@ -402,6 +402,8 @@ pub fn offset_ray_origin(p: Expr, n: Expr) -> Expr { }) }); } + let p = p.as_expr(); + let n = n.as_expr(); F.call(p, n) } pub type Index = [u32; 3]; diff --git a/luisa_compute/tests/misc.rs b/luisa_compute/tests/misc.rs index 6558625..dd32337 100644 --- a/luisa_compute/tests/misc.rs +++ b/luisa_compute/tests/misc.rs @@ -1047,6 +1047,57 @@ fn bindless_byte_buffer() { } } +#[test] +fn is_finite() { + let device = get_device(); + let x = device.create_buffer::(1024); + x.fill_fn(|i| i as f32); + let kernel = Kernel::::new( + &device, + &track!(|| { + let tid = dispatch_id().x; + let x = x.read(tid); + lc_assert!(x.is_finite()); + lc_assert!(!x.is_nan()); + lc_assert!(!x.is_infinite()); + }), + ); + kernel.dispatch([1024, 1, 1]); +} +#[test] +fn is_infinite() { + let device = get_device(); + let x = device.create_buffer::(1024); + x.fill_fn(|i| 1.0 + i as f32); + let kernel = Kernel::::new( + &device, + &track!(|| { + let tid = dispatch_id().x; + let x = x.read(tid) / 0.0; + lc_assert!(!x.is_finite()); + lc_assert!(!x.is_nan()); + lc_assert!(x.is_infinite()); + }), + ); + kernel.dispatch([1024, 1, 1]); +} +#[test] +fn is_nan() { + let device = get_device(); + let x = device.create_buffer::(1024); + x.fill_fn(|i| i as f32); + let kernel = Kernel::::new( + &device, + &track!(|| { + let tid = dispatch_id().x; + let x = x.read(tid) / 0.0 - x.read(tid) / 0.0; + lc_assert!(!x.is_finite()); + lc_assert!(x.is_nan()); + lc_assert!(!x.is_infinite()); + }), + ); + kernel.dispatch([1024, 1, 1]); +} // #[derive(Clone, Copy, Debug, Value, PartialEq)] // #[repr(C)] // #[value_new(pub)]