use crate::op::ReduceOp;
use crate::{Graph, NodeId, Op, Shape};
impl Graph {
pub fn reduce(
&mut self,
input: NodeId,
op: ReduceOp,
axes: Vec<usize>,
keep_dim: bool,
shape: Shape,
) -> NodeId {
self.push(Op::Reduce { op, axes, keep_dim }, vec![input], shape, None)
}
pub fn softmax(&mut self, input: NodeId, axis: i32, shape: Shape) -> NodeId {
self.push(Op::Softmax { axis }, vec![input], shape, None)
}
pub fn histogram(&mut self, input: NodeId, bins: usize, min: f32, max: f32) -> NodeId {
let out = Shape::new(&[bins], crate::DType::F32);
self.push(Op::Histogram { bins, min, max }, vec![input], out, None)
}
pub fn cumsum(&mut self, input: NodeId, axis: i32, exclusive: bool, shape: Shape) -> NodeId {
self.push(Op::Cumsum { axis, exclusive }, vec![input], shape, None)
}
pub fn cumprod(&mut self, input: NodeId, axis: i32, exclusive: bool, shape: Shape) -> NodeId {
self.push(Op::CumProd { axis, exclusive }, vec![input], shape, None)
}
pub fn cummax(&mut self, input: NodeId, axis: i32, exclusive: bool, shape: Shape) -> NodeId {
self.push(Op::CumMax { axis, exclusive }, vec![input], shape, None)
}
pub fn argmax(&mut self, input: NodeId, axis: usize, keep_dim: bool, shape: Shape) -> NodeId {
self.push(Op::ArgMax { axis, keep_dim }, vec![input], shape, None)
}
pub fn argmin(&mut self, input: NodeId, axis: usize, keep_dim: bool, shape: Shape) -> NodeId {
self.push(Op::ArgMin { axis, keep_dim }, vec![input], shape, None)
}
pub fn sample(
&mut self,
logits: NodeId,
top_k: usize,
top_p: f32,
temperature: f32,
seed: u64,
output_shape: Shape,
) -> NodeId {
self.push(
Op::Sample {
top_k,
top_p,
temperature,
seed,
},
vec![logits],
output_shape,
None,
)
}
}