Skip to content

Commit

Permalink
[rust] Allows -1 dim for normalize() (#3442)
Browse files Browse the repository at this point in the history
  • Loading branch information
xyang16 authored Aug 27, 2024
1 parent be48ce7 commit 687dca9
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions extensions/tokenizers/rust/src/ndarray/reduce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ pub extern "system" fn Java_ai_djl_engine_rust_RustLibrary_normalize<'local>(
let normalize = || {
let tensor = cast_handle::<Tensor>(handle);
let device = tensor.device();
let rank = tensor.shape().rank() as i32;
let dim: i32 = if dim < 0 { rank + dim } else { dim };
let pow = Tensor::new(vec![p as f64], device)?.to_dtype(tensor.dtype())?;
let root = Tensor::new(vec![1f64 / p as f64], device)?.to_dtype(tensor.dtype())?;
let eps = Tensor::new(vec![eps as f64], device)?.to_dtype(tensor.dtype())?;
Expand Down

0 comments on commit 687dca9

Please sign in to comment.