use tract_core::internal::*;
use tract_core::ops::array::{Pad, PadMode};
use tract_core::ops::cnn::{rewrite_conv_with_n_axis, KernelFormat, MaxPool, PoolSpec, SumPool};
use tract_core::ops::cnn::{Conv, PaddingSpec};
use tract_core::ops::einsum::prefix_matmul::PrefixMatMul;
use tract_core::ops::element_wise::ElementWiseOp;
use tract_core::ops::math::Recip;
use tract_core::ops::nn::{
expand_mean_of_squares, rewrite_nearest_upsample_to_broadcast, DataFormat, Resize, Softmax,
};
use tract_core::tract_data::itertools::Itertools;
pub fn rewrite_for_tflite(model: &mut TypedModel) -> TractResult<()> {
tract_core::ops::einsum::prefix_matmul::rewrite_einsum_to_prefix_matmul(model, true)?;
Rewriter::default()
.with_rule_for("trivial_axes_around_matmul", trivial_axes_around_matmul)
.with_rule_for("kernel_in_ohwi", kernel_in_ohwi)
.with_rule_for("bias_as_vector", bias_as_vector)
// .with_rule_for("per_layer_in_u8", per_layer_in_u8)
.with_rule_for("make_1d_2d", make_1d_2d)
.with_rule_for("rewrite_conv_with_n_axis", rewrite_conv_with_n_axis)
.with_rule_for("conv-nchw-to-nhwc", conv_nchw_to_nhwc)
.with_rule_for("maxpool-nchw-to-nhwc", maxpool_nchw_to_nhwc)
.with_rule_for("sumpool-nchw-to-nhwc", sumpool_nchw_to_nhwc)
.with_rule_for("resize-nchw-to-nhwc", resize_nchw_to_nhwc)
.with_rule_for("nearest-upsample-to-broadcast", rewrite_nearest_upsample_to_broadcast)
.with_rule_for("padding", padding)
.with_rule_for("manual_recip", manual_recip)
.with_rule_for("softmax_on_last_axis", softmax_on_last_axis)
.with_rule_for("expand-means-of-square", expand_mean_of_squares)
.rewrite(&(), model)?;
tract_core::optim::Optimizer::prop_consts().optimize(model)
}
fn trivial_axes_around_matmul(
_ctx: &(),
model: &TypedModel,
node: &TypedNode,
name: &str,
conv: &PrefixMatMul,
) -> TractResult