//-*-c-*-
//=============================================================================
//
// Copyright (c) XXXX-XXXX
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//=============================================================================

// This file should be auto generated by onnx2c.py,
// it's used as driver for testing ONNX.

#include <math.h>

#include "common/rtlib.h"

double Expected_data[] = {0.8517979, -0.3005707, -0.22370327};
int    Expected_len    = 3;

/**
 * @brief generate input data for testing ONNX
 *
 *
 * @param n
 * @param c
 * @param h
 * @param w
 * @param data, data pointer
 * @return TENSOR input data
 */
TENSOR* Generate_input_data(size_t n, size_t c, size_t h, size_t w,
                            double* data) {
  return Alloc_tensor(n, c, h, w, data);
}

/**
 * @brief validate output vector with expect vector
 *
 *
 * @param result double *
 * @param expect double *
 * @param len int
 * @return return true if value match
 */
bool Validate_output_data(double* result, double* expect, int len) {
  double error = 1e-3;
  for (int i = 0; i < len; i++) {
    if (fabs(result[i] - expect[i]) > error) {
      printf("index: %d, value: %f != %f\n", i, result[i], expect[i]);
      return false;
    }
  }
  return true;
}

int main(int argc, char* argv[]) {
  Prepare_context();

  double input1[] = {
      0.26615628600120544,  0.46900254487991333,   2.608292579650879,
      -0.8082235455513,     0.5564211010932922,    0.19108423590660095,
      0.18549756705760956,  1.4080486297607422,    0.08843445032835007,
      -2.3713161945343018,  -0.015132186934351921, -2.158332109451294,
      -0.294656366109848,   1.561150312423706,     1.0915467739105225,
      -0.14140388369560242, -0.7831412553787231,   -1.5434366464614868,
      -0.14569178223609924, 0.5719127655029297,    1.0212806463241577,
      -0.6085147261619568,  0.540600597858429,     -0.9411096572875977,
      0.08990748971700668,  0.08146240562200546,   0.3806524872779846,
      0.8468196988105774,   -0.5267691016197205,   0.35367852449417114,
      1.057203769683838,    -0.17244449257850647,  1.1897387504577637,
      -0.6447869539260864,  -0.9401383996009827,   -0.5369666218757629,
      -0.5398589372634888,  -0.46925175189971924,  -0.18547113239765167,
      -1.5057023763656616,  -0.5085794925689697,   -0.3828832507133484,
      2.165236711502075,    0.6889519095420837,    -0.12725792825222015,
      -0.09265440702438354, -1.557511329650879,    1.189881682395935,
      0.3427375853061676};
  TENSOR* input_data1 = Generate_input_data(1, 1, 1, 49, input1);
  printf("input");
  Print_tensor(stdout, input_data1);
  Prepare_input(input_data1, "input");
  Free_tensor(input_data1);

  Run_main_graph();

  double* result = Handle_output("output");

  Finalize_context();

  bool res = Validate_output_data(result, Expected_data, Expected_len);
  free(result);
  if (res) {
    printf("SUCESS!\n");
  } else {
    printf("FAILED!\n");
    return 1;
  }

  return 0;
}
#include "eg_fhertlib_gemm_02.inc"