mirror of
https://github.com/huggingface/candle.git
synced 2025-06-16 10:38:54 +00:00
Fix linspace implementation (#1358)
* Fix linspace implementation `steps` should be strictly greater than 1 to make it consistent with the context. * Handle steps == 0 and steps == 1. * Fix rustfmt. --------- Co-authored-by: laurent <laurent.mazare@gmail.com>
This commit is contained in:
@ -7,7 +7,7 @@ extern crate accelerate_src;
|
||||
mod model;
|
||||
use model::{Multiples, YoloV8, YoloV8Pose};
|
||||
|
||||
use candle::{DType, IndexOp, Result, Tensor, Device};
|
||||
use candle::{DType, Device, IndexOp, Result, Tensor};
|
||||
use candle_nn::{Module, VarBuilder};
|
||||
use candle_transformers::object_detection::{non_maximum_suppression, Bbox, KeyPoint};
|
||||
use clap::{Parser, ValueEnum};
|
||||
|
@ -1,12 +1,15 @@
|
||||
use candle::{Device, Result, Tensor};
|
||||
|
||||
pub fn linspace(start: f64, stop: f64, steps: usize) -> Result<Tensor> {
|
||||
if steps < 1 {
|
||||
candle::bail!("cannot use linspace with steps {steps} <= 1")
|
||||
if steps == 0 {
|
||||
Tensor::from_vec(Vec::<f64>::new(), steps, &Device::Cpu)
|
||||
} else if steps == 1 {
|
||||
Tensor::from_vec(vec![start], steps, &Device::Cpu)
|
||||
} else {
|
||||
let delta = (stop - start) / (steps - 1) as f64;
|
||||
let vs = (0..steps)
|
||||
.map(|step| start + step as f64 * delta)
|
||||
.collect::<Vec<_>>();
|
||||
Tensor::from_vec(vs, steps, &Device::Cpu)
|
||||
}
|
||||
let delta = (stop - start) / (steps - 1) as f64;
|
||||
let vs = (0..steps)
|
||||
.map(|step| start + step as f64 * delta)
|
||||
.collect::<Vec<_>>();
|
||||
Tensor::from_vec(vs, steps, &Device::Cpu)
|
||||
}
|
||||
|
Reference in New Issue
Block a user