Skip to content

Commit

Permalink
added signum for floats
Browse files Browse the repository at this point in the history
  • Loading branch information
shiinamiyuki committed Mar 15, 2024
1 parent 716c603 commit c4f379d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 2 deletions.
10 changes: 10 additions & 0 deletions luisa_compute/src/lang/ops/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,16 @@ where
fn sin_cos(&self) -> (Self, Self) {
(self.sin(), self.cos())
}
fn signum(&self) -> Self {
let self_node = self.node().get();
<Self as FromNode>::from_node(
__current_scope(|b| {
let one = b.const_(Const::One(<X as TypeOf>::type_()));
b.call(Func::Copysign, &[one, self_node], <X as TypeOf>::type_())
})
.into(),
)
}
}
impl<const N: usize, X: Floating> NormExpr for Expr<Vector<X, N>>
where
Expand Down
1 change: 1 addition & 0 deletions luisa_compute/src/lang/ops/spread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ where
Expr::<T>::_mul_add(self, S::lift_self(mul), S::lift_other(add))
}
}

impl<T, S> FloatCopySignExpr<S> for T
where
T: SpreadOps<S>,
Expand Down
1 change: 1 addition & 0 deletions luisa_compute/src/lang/ops/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ pub trait FloatExpr: Sized {
fn cube(&self) -> Self;
fn recip(&self) -> Self;
fn sin_cos(&self) -> (Self, Self);
fn signum(&self) -> Self;
}

pub trait ReduceExpr: Sized {
Expand Down
6 changes: 5 additions & 1 deletion luisa_compute/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,11 @@ impl Context {
pub fn create_device<D: IntoDeviceName>(&self, device: D) -> Device {
self.create_device_with_config(device, serde_json::json!({}))
}
pub fn create_device_with_config<D: IntoDeviceName>(&self, device: D, config: serde_json::Value) -> Device {
pub fn create_device_with_config<D: IntoDeviceName>(
&self,
device: D,
config: serde_json::Value,
) -> Device {
let backend = self.inner.create_device(&device.into_device_name(), config);
let default_stream = backend.create_stream(api::StreamTag::Graphics);
Device {
Expand Down
2 changes: 1 addition & 1 deletion luisa_compute_sys/LuisaCompute
Submodule LuisaCompute updated 211 files

0 comments on commit c4f379d

Please sign in to comment.