use crate::cached_property;
use crate::types::ConstValue;
use crate::{Op, UOpKey};
use std::collections::HashSet;
use std::sync::Arc;
cached_property! {
ShapeProperty: crate::Result<Option<crate::shape::Shape>> {
cache_field: shape_cache,
compute: |uop| crate::shape::infer_shape_from_op(uop)
}
}
cached_property! {
RangesProperty: Vec<Arc<crate::UOp>> {
cache_field: ranges_cache,
compute: |uop| {
let mut seen = std::collections::HashSet::new();
let mut result = Vec::new();
if matches!(uop.op, Op::Range { .. }) {
seen.insert(uop.id);
result.push(uop.clone());
}
uop.op.map_child(|src| {
for r in RangesProperty::get(src) {
if seen.insert(r.id) {
result.push(r.clone());
}
}
});
result
}
}
}
cached_property! {
InScopeRangesProperty: HashSet<UOpKey> {
cache_field: in_scope_ranges_cache,
compute: |uop| {
#[allow(clippy::mutable_key_type)]
let mut result: HashSet<UOpKey> = HashSet::new();
uop.op.map_child(|src| {
for r in InScopeRangesProperty::get(src).iter() {
result.insert(r.clone());
}
});
for ended in uop.op.ended_ranges() {
match ended.op() {
Op::Range { .. } => {
result.remove(&UOpKey(ended.clone()));
}
_ => {
for r in InScopeRangesProperty::get(ended).iter() {
result.remove(r);
}
}
}
}
if matches!(uop.op, Op::Range { .. }) {
result.insert(UOpKey(uop.clone()));
}
result
}
}
}
cached_property! {
BackwardSliceProperty: std::collections::HashSet<u64> {
cache_field: backward_slice_cache,
compute: |uop| {
let mut result = std::collections::HashSet::new();
result.insert(uop.id);
uop.op.map_child(|src| {
for &id in BackwardSliceProperty::get(src).iter() {
result.insert(id);
}
});
result
}
}
}
cached_property! {
VminVmaxProperty: (ConstValue, ConstValue) {
cache_field: vmin_vmax_cache,
compute: |uop| {
crate::uop::range_eval::compute_sound_vmin_vmax(uop)
.unwrap_or_else(|| crate::uop::range_eval::dtype_bounds(&uop.dtype))
}
}
}
cached_property! {
SoundVminVmaxProperty: Option<(ConstValue, ConstValue)> {
cache_field: sound_vmin_vmax_cache,
compute: |uop| crate::uop::range_eval::compute_sound_vmin_vmax(uop)
}
}