#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_ML_WEBNN_ML_GRAPH_UTILS_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_ML_WEBNN_ML_GRAPH_UTILS_H_
#include <utility>
#include <vector>
#include "base/types/expected.h"
#include "services/webnn/public/cpp/graph_validation_utils.h"
#include "services/webnn/public/cpp/operand_descriptor.h"
#include "services/webnn/public/mojom/webnn_graph.mojom-blink.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_ml_conv_2d_filter_operand_layout.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_ml_conv_transpose_2d_options.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_ml_input_operand_layout.h"
#include "third_party/blink/renderer/core/typed_arrays/array_buffer/array_buffer_contents.h"
#include "third_party/blink/renderer/core/typed_arrays/dom_array_buffer_view.h"
#include "third_party/blink/renderer/modules/ml/webnn/ml_graph.h"
#include "third_party/blink/renderer/modules/ml/webnn/ml_graph_builder.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/heap/collection_support/heap_vector.h"
#include "third_party/blink/renderer/platform/heap/member.h"
namespace blink {
class MLOperator;
MODULES_EXPORT HeapVector<Member<const MLOperator>>*
GetOperatorsInTopologicalOrder(const MLNamedOperands& named_outputs);
MODULES_EXPORT std::unique_ptr<Vector<std::pair<String, ArrayBufferViewInfo>>>
TransferNamedArrayBufferViews(v8::Isolate* isolate,
const MLNamedArrayBufferViews& source_views,
ExceptionState& exception_state);
MODULES_EXPORT DOMArrayBufferView* CreateArrayBufferView(
ArrayBufferViewInfo view_info);
MODULES_EXPORT MLNamedArrayBufferViews* CreateNamedArrayBufferViews(
std::unique_ptr<Vector<std::pair<String, ArrayBufferViewInfo>>> views_info);
MODULES_EXPORT DOMArrayBufferView::ViewType GetArrayBufferViewType(
webnn::OperandDataType data_type);
Vector<uint32_t> CreateDefaultPermutation(const wtf_size_t rank);
Vector<uint32_t> CreateAllAxes(const wtf_size_t rank);
Vector<uint32_t> CreateLayerNormalizationDefaultAxes(const wtf_size_t rank);
base::expected<void, String> ValidateFilterLayout(
bool depthwise,
V8MLInputOperandLayout input_layout,
V8MLConv2dFilterOperandLayout filter_layout);
webnn::Size2d<uint32_t> CalculateConvTransposeOutputSize2D(
const blink::MLConvTranspose2dOptions* options,
uint32_t input_height,
uint32_t input_width,
uint32_t filter_height,
uint32_t filter_width,
uint32_t stride_height,
uint32_t stride_width,
uint32_t dilation_height,
uint32_t dilation_width,
uint32_t output_padding_height,
uint32_t output_padding_width);
V8MLOperandDataType ToBlinkDataType(webnn::OperandDataType data_type);
webnn::OperandDataType FromBlinkDataType(V8MLOperandDataType::Enum data_type);
MODULES_EXPORT bool IsLogicalBinaryOperator(
webnn::mojom::blink::ElementWiseBinary::Kind kind);
}
#endif