use crate::array::State;
use crate::{Array, DType, Result};
pub use crate::custom::CustomCall;
pub use crate::fast::FastOp;
pub use crate::fused::{Fused, FusedRef};
pub use crate::primitive::{
ArgReduceOp, BinaryOp, Primitive, ReduceOp, ScanOp, ScatterReduce, UnaryOp,
};
pub use crate::shape::Flags;
pub use crate::view::SliceArg;
pub fn from_primitive(primitive: Primitive, inputs: Vec<Array>) -> Result<Vec<Array>> {
Array::from_op(primitive, inputs)
}
pub fn placeholder(dtype: DType, shape: &[i32]) -> Result<Array> {
let dims = shape
.iter()
.map(|&d| {
usize::try_from(d).map_err(|_| {
crate::Error::invalid_shape("placeholder", shape.iter().map(|&d| i64::from(d)))
})
})
.collect::<Result<Vec<_>>>()?;
Array::placeholder(dtype, &dims)
}
pub fn inputs(a: &Array) -> Vec<Array> {
match &*a.node.lock() {
State::Pending { inputs, .. } | State::Retained { inputs, .. } => inputs.clone(),
State::Running { .. } | State::Done | State::Failed { .. } => Vec::new(),
}
}
pub fn siblings(a: &Array) -> Vec<Array> {
(0..a.node.outputs.len() as u32)
.map(|output| Array {
node: a.node.clone(),
output,
})
.collect()
}
pub fn output_index(a: &Array) -> usize {
a.output as usize
}
pub fn id(a: &Array) -> usize {
std::sync::Arc::as_ptr(&a.node) as usize
}
pub fn is_tracer(a: &Array) -> bool {
a.node.is_tracer()
}
pub fn primitive(a: &Array) -> Option<Primitive> {
match &*a.node.lock() {
State::Pending { primitive, .. } => Some(primitive.clone()),
_ => None,
}
}
pub fn strides(a: &Array) -> &[isize] {
&a.out().strides
}
pub fn flags(a: &Array) -> Flags {
a.out().flags
}
pub fn slice(a: &Array, args: &[SliceArg]) -> Result<Array> {
crate::ops::imp::slice(a, args)
}