Skip to content

Commit

Permalink
added more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shiinamiyuki committed Sep 24, 2023
1 parent dc0f729 commit 6a36e1e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
4 changes: 3 additions & 1 deletion luisa_compute/src/rtx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ pub enum HitType {
Procedural = 2,
}

pub fn offset_ray_origin(p: Expr<Float3>, n: Expr<Float3>) -> Expr<Float3> {
pub fn offset_ray_origin(p: impl AsExpr<Value = Float3>, n: impl AsExpr<Value = Float3>) -> Expr<Float3> {
lazy_static! {
static ref F: Callable<fn(Expr<Float3>, Expr<Float3>) -> Expr<Float3>> =
Callable::<fn(Expr<Float3>, Expr<Float3>) -> Expr<Float3>>::new_static(|p, n| {
Expand All @@ -402,6 +402,8 @@ pub fn offset_ray_origin(p: Expr<Float3>, n: Expr<Float3>) -> Expr<Float3> {
})
});
}
let p = p.as_expr();
let n = n.as_expr();
F.call(p, n)
}
pub type Index = [u32; 3];
Expand Down
51 changes: 51 additions & 0 deletions luisa_compute/tests/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,57 @@ fn bindless_byte_buffer() {
}
}

#[test]
fn is_finite() {
let device = get_device();
let x = device.create_buffer::<f32>(1024);
x.fill_fn(|i| i as f32);
let kernel = Kernel::<fn()>::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::<f32>(1024);
x.fill_fn(|i| 1.0 + i as f32);
let kernel = Kernel::<fn()>::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::<f32>(1024);
x.fill_fn(|i| i as f32);
let kernel = Kernel::<fn()>::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)]
Expand Down

0 comments on commit 6a36e1e

Please sign in to comment.