text:
#include <gsl/gsl_test.h>
#include <gsl/gsl_ieee_utils.h>
#include <gsl/gsl_math.h>
#include <gsl/gsl_cblas.h>

#include "tests.h"

void
test_trsv (void) {
const double flteps = 1e-4, dbleps = 1e-6;
  {
   int order = 101;
   int trans = 111;
   int uplo = 121;
   int diag = 131;
   int N = 1;
   int lda = 1;
   float A[] = { 0.995f };
   float X[] = { 0.348f };
   int incX = -1;
   float x_expected[] = { 0.349749f };
   cblas_strsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[i], x_expected[i], flteps, "strsv(case 1150)");
     }
   };
  };

  {
   int order = 101;
   int trans = 111;
   int uplo = 121;
   int diag = 132;
   int N = 1;
   int lda = 1;
   float A[] = { 0.995f };
   float X[] = { 0.348f };
   int incX = -1;
   float x_expected[] = { 0.348f };
   cblas_strsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[i], x_expected[i], flteps, "strsv(case 1151)");
     }
   };
  };

  {
   int order = 101;
   int trans = 111;
   int uplo = 122;
   int diag = 131;
   int N = 1;
   int lda = 1;
   float A[] = { 0.995f };
   float X[] = { 0.348f };
   int incX = -1;
   float x_expected[] = { 0.349749f };
   cblas_strsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[i], x_expected[i], flteps, "strsv(case 1152)");
     }
   };
  };

  {
   int order = 101;
   int trans = 111;
   int uplo = 122;
   int diag = 132;
   int N = 1;
   int lda = 1;
   float A[] = { 0.995f };
   float X[] = { 0.348f };
   int incX = -1;
   float x_expected[] = { 0.348f };
   cblas_strsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[i], x_expected[i], flteps, "strsv(case 1153)");
     }
   };
  };

  {
   int order = 102;
   int trans = 111;
   int uplo = 121;
   int diag = 131;
   int N = 1;
   int lda = 1;
   float A[] = { 0.995f };
   float X[] = { 0.348f };
   int incX = -1;
   float x_expected[] = { 0.349749f };
   cblas_strsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[i], x_expected[i], flteps, "strsv(case 1154)");
     }
   };
  };

  {
   int order = 102;
   int trans = 111;
   int uplo = 121;
   int diag = 132;
   int N = 1;
   int lda = 1;
   float A[] = { 0.995f };
   float X[] = { 0.348f };
   int incX = -1;
   float x_expected[] = { 0.348f };
   cblas_strsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[i], x_expected[i], flteps, "strsv(case 1155)");
     }
   };
  };

  {
   int order = 102;
   int trans = 111;
   int uplo = 122;
   int diag = 131;
   int N = 1;
   int lda = 1;
   float A[] = { 0.995f };
   float X[] = { 0.348f };
   int incX = -1;
   float x_expected[] = { 0.349749f };
   cblas_strsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[i], x_expected[i], flteps, "strsv(case 1156)");
     }
   };
  };

  {
   int order = 102;
   int trans = 111;
   int uplo = 122;
   int diag = 132;
   int N = 1;
   int lda = 1;
   float A[] = { 0.995f };
   float X[] = { 0.348f };
   int incX = -1;
   float x_expected[] = { 0.348f };
   cblas_strsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[i], x_expected[i], flteps, "strsv(case 1157)");
     }
   };
  };

  {
   int order = 101;
   int trans = 112;
   int uplo = 121;
   int diag = 131;
   int N = 1;
   int lda = 1;
   float A[] = { 0.793f };
   float X[] = { 0.338f };
   int incX = -1;
   float x_expected[] = { 0.42623f };
   cblas_strsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[i], x_expected[i], flteps, "strsv(case 1158)");
     }
   };
  };

  {
   int order = 101;
   int trans = 112;
   int uplo = 121;
   int diag = 132;
   int N = 1;
   int lda = 1;
   float A[] = { 0.793f };
   float X[] = { 0.338f };
   int incX = -1;
   float x_expected[] = { 0.338f };
   cblas_strsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[i], x_expected[i], flteps, "strsv(case 1159)");
     }
   };
  };

  {
   int order = 101;
   int trans = 112;
   int uplo = 122;
   int diag = 131;
   int N = 1;
   int lda = 1;
   float A[] = { 0.793f };
   float X[] = { 0.338f };
   int incX = -1;
   float x_expected[] = { 0.42623f };
   cblas_strsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[i], x_expected[i], flteps, "strsv(case 1160)");
     }
   };
  };

  {
   int order = 101;
   int trans = 112;
   int uplo = 122;
   int diag = 132;
   int N = 1;
   int lda = 1;
   float A[] = { 0.793f };
   float X[] = { 0.338f };
   int incX = -1;
   float x_expected[] = { 0.338f };
   cblas_strsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[i], x_expected[i], flteps, "strsv(case 1161)");
     }
   };
  };

  {
   int order = 102;
   int trans = 112;
   int uplo = 121;
   int diag = 131;
   int N = 1;
   int lda = 1;
   float A[] = { 0.793f };
   float X[] = { 0.338f };
   int incX = -1;
   float x_expected[] = { 0.42623f };
   cblas_strsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[i], x_expected[i], flteps, "strsv(case 1162)");
     }
   };
  };

  {
   int order = 102;
   int trans = 112;
   int uplo = 121;
   int diag = 132;
   int N = 1;
   int lda = 1;
   float A[] = { 0.793f };
   float X[] = { 0.338f };
   int incX = -1;
   float x_expected[] = { 0.338f };
   cblas_strsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[i], x_expected[i], flteps, "strsv(case 1163)");
     }
   };
  };

  {
   int order = 102;
   int trans = 112;
   int uplo = 122;
   int diag = 131;
   int N = 1;
   int lda = 1;
   float A[] = { 0.793f };
   float X[] = { 0.338f };
   int incX = -1;
   float x_expected[] = { 0.42623f };
   cblas_strsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[i], x_expected[i], flteps, "strsv(case 1164)");
     }
   };
  };

  {
   int order = 102;
   int trans = 112;
   int uplo = 122;
   int diag = 132;
   int N = 1;
   int lda = 1;
   float A[] = { 0.793f };
   float X[] = { 0.338f };
   int incX = -1;
   float x_expected[] = { 0.338f };
   cblas_strsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[i], x_expected[i], flteps, "strsv(case 1165)");
     }
   };
  };

  {
   int order = 101;
   int trans = 111;
   int uplo = 121;
   int diag = 131;
   int N = 1;
   int lda = 1;
   double A[] = { -0.21 };
   double X[] = { 0.473 };
   int incX = -1;
   double x_expected[] = { -2.25238095238 };
   cblas_dtrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[i], x_expected[i], dbleps, "dtrsv(case 1166)");
     }
   };
  };

  {
   int order = 101;
   int trans = 111;
   int uplo = 121;
   int diag = 132;
   int N = 1;
   int lda = 1;
   double A[] = { -0.21 };
   double X[] = { 0.473 };
   int incX = -1;
   double x_expected[] = { 0.473 };
   cblas_dtrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[i], x_expected[i], dbleps, "dtrsv(case 1167)");
     }
   };
  };

  {
   int order = 101;
   int trans = 111;
   int uplo = 122;
   int diag = 131;
   int N = 1;
   int lda = 1;
   double A[] = { -0.21 };
   double X[] = { 0.473 };
   int incX = -1;
   double x_expected[] = { -2.25238095238 };
   cblas_dtrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[i], x_expected[i], dbleps, "dtrsv(case 1168)");
     }
   };
  };

  {
   int order = 101;
   int trans = 111;
   int uplo = 122;
   int diag = 132;
   int N = 1;
   int lda = 1;
   double A[] = { -0.21 };
   double X[] = { 0.473 };
   int incX = -1;
   double x_expected[] = { 0.473 };
   cblas_dtrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[i], x_expected[i], dbleps, "dtrsv(case 1169)");
     }
   };
  };

  {
   int order = 102;
   int trans = 111;
   int uplo = 121;
   int diag = 131;
   int N = 1;
   int lda = 1;
   double A[] = { -0.21 };
   double X[] = { 0.473 };
   int incX = -1;
   double x_expected[] = { -2.25238095238 };
   cblas_dtrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[i], x_expected[i], dbleps, "dtrsv(case 1170)");
     }
   };
  };

  {
   int order = 102;
   int trans = 111;
   int uplo = 121;
   int diag = 132;
   int N = 1;
   int lda = 1;
   double A[] = { -0.21 };
   double X[] = { 0.473 };
   int incX = -1;
   double x_expected[] = { 0.473 };
   cblas_dtrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[i], x_expected[i], dbleps, "dtrsv(case 1171)");
     }
   };
  };

  {
   int order = 102;
   int trans = 111;
   int uplo = 122;
   int diag = 131;
   int N = 1;
   int lda = 1;
   double A[] = { -0.21 };
   double X[] = { 0.473 };
   int incX = -1;
   double x_expected[] = { -2.25238095238 };
   cblas_dtrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[i], x_expected[i], dbleps, "dtrsv(case 1172)");
     }
   };
  };

  {
   int order = 102;
   int trans = 111;
   int uplo = 122;
   int diag = 132;
   int N = 1;
   int lda = 1;
   double A[] = { -0.21 };
   double X[] = { 0.473 };
   int incX = -1;
   double x_expected[] = { 0.473 };
   cblas_dtrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[i], x_expected[i], dbleps, "dtrsv(case 1173)");
     }
   };
  };

  {
   int order = 101;
   int trans = 112;
   int uplo = 121;
   int diag = 131;
   int N = 1;
   int lda = 1;
   double A[] = { 0.748 };
   double X[] = { 0.979 };
   int incX = -1;
   double x_expected[] = { 1.30882352941 };
   cblas_dtrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[i], x_expected[i], dbleps, "dtrsv(case 1174)");
     }
   };
  };

  {
   int order = 101;
   int trans = 112;
   int uplo = 121;
   int diag = 132;
   int N = 1;
   int lda = 1;
   double A[] = { 0.748 };
   double X[] = { 0.979 };
   int incX = -1;
   double x_expected[] = { 0.979 };
   cblas_dtrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[i], x_expected[i], dbleps, "dtrsv(case 1175)");
     }
   };
  };

  {
   int order = 101;
   int trans = 112;
   int uplo = 122;
   int diag = 131;
   int N = 1;
   int lda = 1;
   double A[] = { 0.748 };
   double X[] = { 0.979 };
   int incX = -1;
   double x_expected[] = { 1.30882352941 };
   cblas_dtrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[i], x_expected[i], dbleps, "dtrsv(case 1176)");
     }
   };
  };

  {
   int order = 101;
   int trans = 112;
   int uplo = 122;
   int diag = 132;
   int N = 1;
   int lda = 1;
   double A[] = { 0.748 };
   double X[] = { 0.979 };
   int incX = -1;
   double x_expected[] = { 0.979 };
   cblas_dtrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[i], x_expected[i], dbleps, "dtrsv(case 1177)");
     }
   };
  };

  {
   int order = 102;
   int trans = 112;
   int uplo = 121;
   int diag = 131;
   int N = 1;
   int lda = 1;
   double A[] = { 0.748 };
   double X[] = { 0.979 };
   int incX = -1;
   double x_expected[] = { 1.30882352941 };
   cblas_dtrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[i], x_expected[i], dbleps, "dtrsv(case 1178)");
     }
   };
  };

  {
   int order = 102;
   int trans = 112;
   int uplo = 121;
   int diag = 132;
   int N = 1;
   int lda = 1;
   double A[] = { 0.748 };
   double X[] = { 0.979 };
   int incX = -1;
   double x_expected[] = { 0.979 };
   cblas_dtrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[i], x_expected[i], dbleps, "dtrsv(case 1179)");
     }
   };
  };

  {
   int order = 102;
   int trans = 112;
   int uplo = 122;
   int diag = 131;
   int N = 1;
   int lda = 1;
   double A[] = { 0.748 };
   double X[] = { 0.979 };
   int incX = -1;
   double x_expected[] = { 1.30882352941 };
   cblas_dtrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[i], x_expected[i], dbleps, "dtrsv(case 1180)");
     }
   };
  };

  {
   int order = 102;
   int trans = 112;
   int uplo = 122;
   int diag = 132;
   int N = 1;
   int lda = 1;
   double A[] = { 0.748 };
   double X[] = { 0.979 };
   int incX = -1;
   double x_expected[] = { 0.979 };
   cblas_dtrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[i], x_expected[i], dbleps, "dtrsv(case 1181)");
     }
   };
  };

  {
   int order = 101;
   int trans = 111;
   int uplo = 121;
   int diag = 131;
   int N = 1;
   int lda = 1;
   float A[] = { 0.529f, -0.348f };
   float X[] = { -0.95f, 0.343f };
   int incX = -1;
   float x_expected[] = { -1.55112f, -0.372004f };
   cblas_ctrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[2*i], x_expected[2*i], flteps, "ctrsv(case 1182) real");
       gsl_test_rel(X[2*i+1], x_expected[2*i+1], flteps, "ctrsv(case 1182) imag");
     };
   };
  };

  {
   int order = 101;
   int trans = 111;
   int uplo = 121;
   int diag = 132;
   int N = 1;
   int lda = 1;
   float A[] = { 0.529f, -0.348f };
   float X[] = { -0.95f, 0.343f };
   int incX = -1;
   float x_expected[] = { -0.95f, 0.343f };
   cblas_ctrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[2*i], x_expected[2*i], flteps, "ctrsv(case 1183) real");
       gsl_test_rel(X[2*i+1], x_expected[2*i+1], flteps, "ctrsv(case 1183) imag");
     };
   };
  };

  {
   int order = 101;
   int trans = 111;
   int uplo = 122;
   int diag = 131;
   int N = 1;
   int lda = 1;
   float A[] = { 0.529f, -0.348f };
   float X[] = { -0.95f, 0.343f };
   int incX = -1;
   float x_expected[] = { -1.55112f, -0.372004f };
   cblas_ctrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[2*i], x_expected[2*i], flteps, "ctrsv(case 1184) real");
       gsl_test_rel(X[2*i+1], x_expected[2*i+1], flteps, "ctrsv(case 1184) imag");
     };
   };
  };

  {
   int order = 101;
   int trans = 111;
   int uplo = 122;
   int diag = 132;
   int N = 1;
   int lda = 1;
   float A[] = { 0.529f, -0.348f };
   float X[] = { -0.95f, 0.343f };
   int incX = -1;
   float x_expected[] = { -0.95f, 0.343f };
   cblas_ctrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[2*i], x_expected[2*i], flteps, "ctrsv(case 1185) real");
       gsl_test_rel(X[2*i+1], x_expected[2*i+1], flteps, "ctrsv(case 1185) imag");
     };
   };
  };

  {
   int order = 102;
   int trans = 111;
   int uplo = 121;
   int diag = 131;
   int N = 1;
   int lda = 1;
   float A[] = { 0.529f, -0.348f };
   float X[] = { -0.95f, 0.343f };
   int incX = -1;
   float x_expected[] = { -1.55112f, -0.372004f };
   cblas_ctrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[2*i], x_expected[2*i], flteps, "ctrsv(case 1186) real");
       gsl_test_rel(X[2*i+1], x_expected[2*i+1], flteps, "ctrsv(case 1186) imag");
     };
   };
  };

  {
   int order = 102;
   int trans = 111;
   int uplo = 121;
   int diag = 132;
   int N = 1;
   int lda = 1;
   float A[] = { 0.529f, -0.348f };
   float X[] = { -0.95f, 0.343f };
   int incX = -1;
   float x_expected[] = { -0.95f, 0.343f };
   cblas_ctrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[2*i], x_expected[2*i], flteps, "ctrsv(case 1187) real");
       gsl_test_rel(X[2*i+1], x_expected[2*i+1], flteps, "ctrsv(case 1187) imag");
     };
   };
  };

  {
   int order = 102;
   int trans = 111;
   int uplo = 122;
   int diag = 131;
   int N = 1;
   int lda = 1;
   float A[] = { 0.529f, -0.348f };
   float X[] = { -0.95f, 0.343f };
   int incX = -1;
   float x_expected[] = { -1.55112f, -0.372004f };
   cblas_ctrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[2*i], x_expected[2*i], flteps, "ctrsv(case 1188) real");
       gsl_test_rel(X[2*i+1], x_expected[2*i+1], flteps, "ctrsv(case 1188) imag");
     };
   };
  };

  {
   int order = 102;
   int trans = 111;
   int uplo = 122;
   int diag = 132;
   int N = 1;
   int lda = 1;
   float A[] = { 0.529f, -0.348f };
   float X[] = { -0.95f, 0.343f };
   int incX = -1;
   float x_expected[] = { -0.95f, 0.343f };
   cblas_ctrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[2*i], x_expected[2*i], flteps, "ctrsv(case 1189) real");
       gsl_test_rel(X[2*i+1], x_expected[2*i+1], flteps, "ctrsv(case 1189) imag");
     };
   };
  };

  {
   int order = 101;
   int trans = 112;
   int uplo = 121;
   int diag = 131;
   int N = 1;
   int lda = 1;
   float A[] = { 0.6f, 0.041f };
   float X[] = { 0.896f, -0.447f };
   int incX = -1;
   float x_expected[] = { 1.43572f, -0.843108f };
   cblas_ctrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[2*i], x_expected[2*i], flteps, "ctrsv(case 1190) real");
       gsl_test_rel(X[2*i+1], x_expected[2*i+1], flteps, "ctrsv(case 1190) imag");
     };
   };
  };

  {
   int order = 101;
   int trans = 112;
   int uplo = 121;
   int diag = 132;
   int N = 1;
   int lda = 1;
   float A[] = { 0.6f, 0.041f };
   float X[] = { 0.896f, -0.447f };
   int incX = -1;
   float x_expected[] = { 0.896f, -0.447f };
   cblas_ctrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[2*i], x_expected[2*i], flteps, "ctrsv(case 1191) real");
       gsl_test_rel(X[2*i+1], x_expected[2*i+1], flteps, "ctrsv(case 1191) imag");
     };
   };
  };

  {
   int order = 101;
   int trans = 112;
   int uplo = 122;
   int diag = 131;
   int N = 1;
   int lda = 1;
   float A[] = { 0.6f, 0.041f };
   float X[] = { 0.896f, -0.447f };
   int incX = -1;
   float x_expected[] = { 1.43572f, -0.843108f };
   cblas_ctrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[2*i], x_expected[2*i], flteps, "ctrsv(case 1192) real");
       gsl_test_rel(X[2*i+1], x_expected[2*i+1], flteps, "ctrsv(case 1192) imag");
     };
   };
  };

  {
   int order = 101;
   int trans = 112;
   int uplo = 122;
   int diag = 132;
   int N = 1;
   int lda = 1;
   float A[] = { 0.6f, 0.041f };
   float X[] = { 0.896f, -0.447f };
   int incX = -1;
   float x_expected[] = { 0.896f, -0.447f };
   cblas_ctrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[2*i], x_expected[2*i], flteps, "ctrsv(case 1193) real");
       gsl_test_rel(X[2*i+1], x_expected[2*i+1], flteps, "ctrsv(case 1193) imag");
     };
   };
  };

  {
   int order = 102;
   int trans = 112;
   int uplo = 121;
   int diag = 131;
   int N = 1;
   int lda = 1;
   float A[] = { 0.6f, 0.041f };
   float X[] = { 0.896f, -0.447f };
   int incX = -1;
   float x_expected[] = { 1.43572f, -0.843108f };
   cblas_ctrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[2*i], x_expected[2*i], flteps, "ctrsv(case 1194) real");
       gsl_test_rel(X[2*i+1], x_expected[2*i+1], flteps, "ctrsv(case 1194) imag");
     };
   };
  };

  {
   int order = 102;
   int trans = 112;
   int uplo = 121;
   int diag = 132;
   int N = 1;
   int lda = 1;
   float A[] = { 0.6f, 0.041f };
   float X[] = { 0.896f, -0.447f };
   int incX = -1;
   float x_expected[] = { 0.896f, -0.447f };
   cblas_ctrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[2*i], x_expected[2*i], flteps, "ctrsv(case 1195) real");
       gsl_test_rel(X[2*i+1], x_expected[2*i+1], flteps, "ctrsv(case 1195) imag");
     };
   };
  };

  {
   int order = 102;
   int trans = 112;
   int uplo = 122;
   int diag = 131;
   int N = 1;
   int lda = 1;
   float A[] = { 0.6f, 0.041f };
   float X[] = { 0.896f, -0.447f };
   int incX = -1;
   float x_expected[] = { 1.43572f, -0.843108f };
   cblas_ctrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[2*i], x_expected[2*i], flteps, "ctrsv(case 1196) real");
       gsl_test_rel(X[2*i+1], x_expected[2*i+1], flteps, "ctrsv(case 1196) imag");
     };
   };
  };

  {
   int order = 102;
   int trans = 112;
   int uplo = 122;
   int diag = 132;
   int N = 1;
   int lda = 1;
   float A[] = { 0.6f, 0.041f };
   float X[] = { 0.896f, -0.447f };
   int incX = -1;
   float x_expected[] = { 0.896f, -0.447f };
   cblas_ctrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[2*i], x_expected[2*i], flteps, "ctrsv(case 1197) real");
       gsl_test_rel(X[2*i+1], x_expected[2*i+1], flteps, "ctrsv(case 1197) imag");
     };
   };
  };

  {
   int order = 101;
   int trans = 113;
   int uplo = 121;
   int diag = 131;
   int N = 1;
   int lda = 1;
   float A[] = { 0.397f, 0.683f };
   float X[] = { 0.765f, 0.18f };
   int incX = -1;
   float x_expected[] = { 0.289642f, 0.951701f };
   cblas_ctrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[2*i], x_expected[2*i], flteps, "ctrsv(case 1198) real");
       gsl_test_rel(X[2*i+1], x_expected[2*i+1], flteps, "ctrsv(case 1198) imag");
     };
   };
  };

  {
   int order = 101;
   int trans = 113;
   int uplo = 121;
   int diag = 132;
   int N = 1;
   int lda = 1;
   float A[] = { 0.397f, 0.683f };
   float X[] = { 0.765f, 0.18f };
   int incX = -1;
   float x_expected[] = { 0.765f, 0.18f };
   cblas_ctrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[2*i], x_expected[2*i], flteps, "ctrsv(case 1199) real");
       gsl_test_rel(X[2*i+1], x_expected[2*i+1], flteps, "ctrsv(case 1199) imag");
     };
   };
  };

  {
   int order = 101;
   int trans = 113;
   int uplo = 122;
   int diag = 131;
   int N = 1;
   int lda = 1;
   float A[] = { 0.397f, 0.683f };
   float X[] = { 0.765f, 0.18f };
   int incX = -1;
   float x_expected[] = { 0.289642f, 0.951701f };
   cblas_ctrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[2*i], x_expected[2*i], flteps, "ctrsv(case 1200) real");
       gsl_test_rel(X[2*i+1], x_expected[2*i+1], flteps, "ctrsv(case 1200) imag");
     };
   };
  };

  {
   int order = 101;
   int trans = 113;
   int uplo = 122;
   int diag = 132;
   int N = 1;
   int lda = 1;
   float A[] = { 0.397f, 0.683f };
   float X[] = { 0.765f, 0.18f };
   int incX = -1;
   float x_expected[] = { 0.765f, 0.18f };
   cblas_ctrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[2*i], x_expected[2*i], flteps, "ctrsv(case 1201) real");
       gsl_test_rel(X[2*i+1], x_expected[2*i+1], flteps, "ctrsv(case 1201) imag");
     };
   };
  };

  {
   int order = 102;
   int trans = 113;
   int uplo = 121;
   int diag = 131;
   int N = 1;
   int lda = 1;
   float A[] = { 0.397f, 0.683f };
   float X[] = { 0.765f, 0.18f };
   int incX = -1;
   float x_expected[] = { 0.289642f, 0.951701f };
   cblas_ctrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[2*i], x_expected[2*i], flteps, "ctrsv(case 1202) real");
       gsl_test_rel(X[2*i+1], x_expected[2*i+1], flteps, "ctrsv(case 1202) imag");
     };
   };
  };

  {
   int order = 102;
   int trans = 113;
   int uplo = 121;
   int diag = 132;
   int N = 1;
   int lda = 1;
   float A[] = { 0.397f, 0.683f };
   float X[] = { 0.765f, 0.18f };
   int incX = -1;
   float x_expected[] = { 0.765f, 0.18f };
   cblas_ctrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[2*i], x_expected[2*i], flteps, "ctrsv(case 1203) real");
       gsl_test_rel(X[2*i+1], x_expected[2*i+1], flteps, "ctrsv(case 1203) imag");
     };
   };
  };

  {
   int order = 102;
   int trans = 113;
   int uplo = 122;
   int diag = 131;
   int N = 1;
   int lda = 1;
   float A[] = { 0.397f, 0.683f };
   float X[] = { 0.765f, 0.18f };
   int incX = -1;
   float x_expected[] = { 0.289642f, 0.951701f };
   cblas_ctrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[2*i], x_expected[2*i], flteps, "ctrsv(case 1204) real");
       gsl_test_rel(X[2*i+1], x_expected[2*i+1], flteps, "ctrsv(case 1204) imag");
     };
   };
  };

  {
   int order = 102;
   int trans = 113;
   int uplo = 122;
   int diag = 132;
   int N = 1;
   int lda = 1;
   float A[] = { 0.397f, 0.683f };
   float X[] = { 0.765f, 0.18f };
   int incX = -1;
   float x_expected[] = { 0.765f, 0.18f };
   cblas_ctrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[2*i], x_expected[2*i], flteps, "ctrsv(case 1205) real");
       gsl_test_rel(X[2*i+1], x_expected[2*i+1], flteps, "ctrsv(case 1205) imag");
     };
   };
  };

  {
   int order = 101;
   int trans = 111;
   int uplo = 121;
   int diag = 131;
   int N = 1;
   int lda = 1;
   double A[] = { 0.977, -0.955 };
   double X[] = { -0.627, 0.281 };
   int incX = -1;
   double x_expected[] = { -0.471957414573, -0.173714770642 };
   cblas_ztrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[2*i], x_expected[2*i], dbleps, "ztrsv(case 1206) real");
       gsl_test_rel(X[2*i+1], x_expected[2*i+1], dbleps, "ztrsv(case 1206) imag");
     };
   };
  };

  {
   int order = 101;
   int trans = 111;
   int uplo = 121;
   int diag = 132;
   int N = 1;
   int lda = 1;
   double A[] = { 0.977, -0.955 };
   double X[] = { -0.627, 0.281 };
   int incX = -1;
   double x_expected[] = { -0.627, 0.281 };
   cblas_ztrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[2*i], x_expected[2*i], dbleps, "ztrsv(case 1207) real");
       gsl_test_rel(X[2*i+1], x_expected[2*i+1], dbleps, "ztrsv(case 1207) imag");
     };
   };
  };

  {
   int order = 101;
   int trans = 111;
   int uplo = 122;
   int diag = 131;
   int N = 1;
   int lda = 1;
   double A[] = { 0.977, -0.955 };
   double X[] = { -0.627, 0.281 };
   int incX = -1;
   double x_expected[] = { -0.471957414573, -0.173714770642 };
   cblas_ztrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[2*i], x_expected[2*i], dbleps, "ztrsv(case 1208) real");
       gsl_test_rel(X[2*i+1], x_expected[2*i+1], dbleps, "ztrsv(case 1208) imag");
     };
   };
  };

  {
   int order = 101;
   int trans = 111;
   int uplo = 122;
   int diag = 132;
   int N = 1;
   int lda = 1;
   double A[] = { 0.977, -0.955 };
   double X[] = { -0.627, 0.281 };
   int incX = -1;
   double x_expected[] = { -0.627, 0.281 };
   cblas_ztrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[2*i], x_expected[2*i], dbleps, "ztrsv(case 1209) real");
       gsl_test_rel(X[2*i+1], x_expected[2*i+1], dbleps, "ztrsv(case 1209) imag");
     };
   };
  };

  {
   int order = 102;
   int trans = 111;
   int uplo = 121;
   int diag = 131;
   int N = 1;
   int lda = 1;
   double A[] = { 0.977, -0.955 };
   double X[] = { -0.627, 0.281 };
   int incX = -1;
   double x_expected[] = { -0.471957414573, -0.173714770642 };
   cblas_ztrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[2*i], x_expected[2*i], dbleps, "ztrsv(case 1210) real");
       gsl_test_rel(X[2*i+1], x_expected[2*i+1], dbleps, "ztrsv(case 1210) imag");
     };
   };
  };

  {
   int order = 102;
   int trans = 111;
   int uplo = 121;
   int diag = 132;
   int N = 1;
   int lda = 1;
   double A[] = { 0.977, -0.955 };
   double X[] = { -0.627, 0.281 };
   int incX = -1;
   double x_expected[] = { -0.627, 0.281 };
   cblas_ztrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[2*i], x_expected[2*i], dbleps, "ztrsv(case 1211) real");
       gsl_test_rel(X[2*i+1], x_expected[2*i+1], dbleps, "ztrsv(case 1211) imag");
     };
   };
  };

  {
   int order = 102;
   int trans = 111;
   int uplo = 122;
   int diag = 131;
   int N = 1;
   int lda = 1;
   double A[] = { 0.977, -0.955 };
   double X[] = { -0.627, 0.281 };
   int incX = -1;
   double x_expected[] = { -0.471957414573, -0.173714770642 };
   cblas_ztrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[2*i], x_expected[2*i], dbleps, "ztrsv(case 1212) real");
       gsl_test_rel(X[2*i+1], x_expected[2*i+1], dbleps, "ztrsv(case 1212) imag");
     };
   };
  };

  {
   int order = 102;
   int trans = 111;
   int uplo = 122;
   int diag = 132;
   int N = 1;
   int lda = 1;
   double A[] = { 0.977, -0.955 };
   double X[] = { -0.627, 0.281 };
   int incX = -1;
   double x_expected[] = { -0.627, 0.281 };
   cblas_ztrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[2*i], x_expected[2*i], dbleps, "ztrsv(case 1213) real");
       gsl_test_rel(X[2*i+1], x_expected[2*i+1], dbleps, "ztrsv(case 1213) imag");
     };
   };
  };

  {
   int order = 101;
   int trans = 112;
   int uplo = 121;
   int diag = 131;
   int N = 1;
   int lda = 1;
   double A[] = { 0.076, -0.16 };
   double X[] = { 0.3, -0.874 };
   int incX = -1;
   double x_expected[] = { 5.18357980622, -0.587200407955 };
   cblas_ztrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[2*i], x_expected[2*i], dbleps, "ztrsv(case 1214) real");
       gsl_test_rel(X[2*i+1], x_expected[2*i+1], dbleps, "ztrsv(case 1214) imag");
     };
   };
  };

  {
   int order = 101;
   int trans = 112;
   int uplo = 121;
   int diag = 132;
   int N = 1;
   int lda = 1;
   double A[] = { 0.076, -0.16 };
   double X[] = { 0.3, -0.874 };
   int incX = -1;
   double x_expected[] = { 0.3, -0.874 };
   cblas_ztrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[2*i], x_expected[2*i], dbleps, "ztrsv(case 1215) real");
       gsl_test_rel(X[2*i+1], x_expected[2*i+1], dbleps, "ztrsv(case 1215) imag");
     };
   };
  };

  {
   int order = 101;
   int trans = 112;
   int uplo = 122;
   int diag = 131;
   int N = 1;
   int lda = 1;
   double A[] = { 0.076, -0.16 };
   double X[] = { 0.3, -0.874 };
   int incX = -1;
   double x_expected[] = { 5.18357980622, -0.587200407955 };
   cblas_ztrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[2*i], x_expected[2*i], dbleps, "ztrsv(case 1216) real");
       gsl_test_rel(X[2*i+1], x_expected[2*i+1], dbleps, "ztrsv(case 1216) imag");
     };
   };
  };

  {
   int order = 101;
   int trans = 112;
   int uplo = 122;
   int diag = 132;
   int N = 1;
   int lda = 1;
   double A[] = { 0.076, -0.16 };
   double X[] = { 0.3, -0.874 };
   int incX = -1;
   double x_expected[] = { 0.3, -0.874 };
   cblas_ztrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[2*i], x_expected[2*i], dbleps, "ztrsv(case 1217) real");
       gsl_test_rel(X[2*i+1], x_expected[2*i+1], dbleps, "ztrsv(case 1217) imag");
     };
   };
  };

  {
   int order = 102;
   int trans = 112;
   int uplo = 121;
   int diag = 131;
   int N = 1;
   int lda = 1;
   double A[] = { 0.076, -0.16 };
   double X[] = { 0.3, -0.874 };
   int incX = -1;
   double x_expected[] = { 5.18357980622, -0.587200407955 };
   cblas_ztrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[2*i], x_expected[2*i], dbleps, "ztrsv(case 1218) real");
       gsl_test_rel(X[2*i+1], x_expected[2*i+1], dbleps, "ztrsv(case 1218) imag");
     };
   };
  };

  {
   int order = 102;
   int trans = 112;
   int uplo = 121;
   int diag = 132;
   int N = 1;
   int lda = 1;
   double A[] = { 0.076, -0.16 };
   double X[] = { 0.3, -0.874 };
   int incX = -1;
   double x_expected[] = { 0.3, -0.874 };
   cblas_ztrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[2*i], x_expected[2*i], dbleps, "ztrsv(case 1219) real");
       gsl_test_rel(X[2*i+1], x_expected[2*i+1], dbleps, "ztrsv(case 1219) imag");
     };
   };
  };

  {
   int order = 102;
   int trans = 112;
   int uplo = 122;
   int diag = 131;
   int N = 1;
   int lda = 1;
   double A[] = { 0.076, -0.16 };
   double X[] = { 0.3, -0.874 };
   int incX = -1;
   double x_expected[] = { 5.18357980622, -0.587200407955 };
   cblas_ztrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[2*i], x_expected[2*i], dbleps, "ztrsv(case 1220) real");
       gsl_test_rel(X[2*i+1], x_expected[2*i+1], dbleps, "ztrsv(case 1220) imag");
     };
   };
  };

  {
   int order = 102;
   int trans = 112;
   int uplo = 122;
   int diag = 132;
   int N = 1;
   int lda = 1;
   double A[] = { 0.076, -0.16 };
   double X[] = { 0.3, -0.874 };
   int incX = -1;
   double x_expected[] = { 0.3, -0.874 };
   cblas_ztrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[2*i], x_expected[2*i], dbleps, "ztrsv(case 1221) real");
       gsl_test_rel(X[2*i+1], x_expected[2*i+1], dbleps, "ztrsv(case 1221) imag");
     };
   };
  };

  {
   int order = 101;
   int trans = 113;
   int uplo = 121;
   int diag = 131;
   int N = 1;
   int lda = 1;
   double A[] = { 0.372, -0.745 };
   double X[] = { -0.085, -0.303 };
   int incX = -1;
   double x_expected[] = { -0.371144591432, -0.0712292456544 };
   cblas_ztrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[2*i], x_expected[2*i], dbleps, "ztrsv(case 1222) real");
       gsl_test_rel(X[2*i+1], x_expected[2*i+1], dbleps, "ztrsv(case 1222) imag");
     };
   };
  };

  {
   int order = 101;
   int trans = 113;
   int uplo = 121;
   int diag = 132;
   int N = 1;
   int lda = 1;
   double A[] = { 0.372, -0.745 };
   double X[] = { -0.085, -0.303 };
   int incX = -1;
   double x_expected[] = { -0.085, -0.303 };
   cblas_ztrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[2*i], x_expected[2*i], dbleps, "ztrsv(case 1223) real");
       gsl_test_rel(X[2*i+1], x_expected[2*i+1], dbleps, "ztrsv(case 1223) imag");
     };
   };
  };

  {
   int order = 101;
   int trans = 113;
   int uplo = 122;
   int diag = 131;
   int N = 1;
   int lda = 1;
   double A[] = { 0.372, -0.745 };
   double X[] = { -0.085, -0.303 };
   int incX = -1;
   double x_expected[] = { -0.371144591432, -0.0712292456544 };
   cblas_ztrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[2*i], x_expected[2*i], dbleps, "ztrsv(case 1224) real");
       gsl_test_rel(X[2*i+1], x_expected[2*i+1], dbleps, "ztrsv(case 1224) imag");
     };
   };
  };

  {
   int order = 101;
   int trans = 113;
   int uplo = 122;
   int diag = 132;
   int N = 1;
   int lda = 1;
   double A[] = { 0.372, -0.745 };
   double X[] = { -0.085, -0.303 };
   int incX = -1;
   double x_expected[] = { -0.085, -0.303 };
   cblas_ztrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[2*i], x_expected[2*i], dbleps, "ztrsv(case 1225) real");
       gsl_test_rel(X[2*i+1], x_expected[2*i+1], dbleps, "ztrsv(case 1225) imag");
     };
   };
  };

  {
   int order = 102;
   int trans = 113;
   int uplo = 121;
   int diag = 131;
   int N = 1;
   int lda = 1;
   double A[] = { 0.372, -0.745 };
   double X[] = { -0.085, -0.303 };
   int incX = -1;
   double x_expected[] = { -0.371144591432, -0.0712292456544 };
   cblas_ztrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[2*i], x_expected[2*i], dbleps, "ztrsv(case 1226) real");
       gsl_test_rel(X[2*i+1], x_expected[2*i+1], dbleps, "ztrsv(case 1226) imag");
     };
   };
  };

  {
   int order = 102;
   int trans = 113;
   int uplo = 121;
   int diag = 132;
   int N = 1;
   int lda = 1;
   double A[] = { 0.372, -0.745 };
   double X[] = { -0.085, -0.303 };
   int incX = -1;
   double x_expected[] = { -0.085, -0.303 };
   cblas_ztrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[2*i], x_expected[2*i], dbleps, "ztrsv(case 1227) real");
       gsl_test_rel(X[2*i+1], x_expected[2*i+1], dbleps, "ztrsv(case 1227) imag");
     };
   };
  };

  {
   int order = 102;
   int trans = 113;
   int uplo = 122;
   int diag = 131;
   int N = 1;
   int lda = 1;
   double A[] = { 0.372, -0.745 };
   double X[] = { -0.085, -0.303 };
   int incX = -1;
   double x_expected[] = { -0.371144591432, -0.0712292456544 };
   cblas_ztrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[2*i], x_expected[2*i], dbleps, "ztrsv(case 1228) real");
       gsl_test_rel(X[2*i+1], x_expected[2*i+1], dbleps, "ztrsv(case 1228) imag");
     };
   };
  };

  {
   int order = 102;
   int trans = 113;
   int uplo = 122;
   int diag = 132;
   int N = 1;
   int lda = 1;
   double A[] = { 0.372, -0.745 };
   double X[] = { -0.085, -0.303 };
   int incX = -1;
   double x_expected[] = { -0.085, -0.303 };
   cblas_ztrsv(order, uplo, trans, diag, N, A, lda, X, incX);
   {
     int i;
     for (i = 0; i < 1; i++) {
       gsl_test_rel(X[2*i], x_expected[2*i], dbleps, "ztrsv(case 1229) real");
       gsl_test_rel(X[2*i+1], x_expected[2*i+1], dbleps, "ztrsv(case 1229) imag");
     };
   };
  };

}

max_stars_repo_name: utdsimmons/ohpc

max_issues_repo_name: utdsimmons/ohpc

max_forks_repo_name: utdsimmons/ohpc


text:
#include <config.h>
#include <math.h>
#include <gsl/gsl_statistics.h>

#define BASE_LONG_DOUBLE
#include "templates_on.h"
#include "wskew_source.c"
#include "templates_off.h"
#undef  BASE_LONG_DOUBLE

#define BASE_DOUBLE
#include "templates_on.h"
#include "wskew_source.c"
#include "templates_off.h"
#undef  BASE_DOUBLE

#define BASE_FLOAT
#include "templates_on.h"
#include "wskew_source.c"
#include "templates_off.h"
#undef  BASE_FLOAT

ext: c

max_stars_repo_name: manggoguy/parsec-modified

max_issues_repo_name: Brian-ning/HMNE

max_forks_repo_name: Brian-ning/HMNE


text:
#ifndef SPECTRALFUNCTIONS
#define SPECTRALFUNCTIONS

#include <string>
#include <iostream>
#include <vector>
#include <gsl/gsl_complex.h>
#include <tuple>

#include "Constants.h"
#include "NuclearUtilities.h"

namespace bsg {

/**
 * Namespace containing all correction factors to the allowed beta spectrum shape
 * as described by Hayen et al., Rev. Mod. Phys. 90 (2018) 015008
 */
namespace SpectralFunctions {
/// type of beta decay, negative or positive
enum BetaType { BETA_PLUS = -1, BETA_MINUS = 1 };
enum DecayType { FERMI, GAMOW_TELLER, MIXED };

// the different corrections
double PhaseSpace(double W, double W0, int motherSpinParity,
                  int daughterSpinParity);
/**
 * @brief Fermi function
 * @param W total energy in units of electron mass
 * @param Z the proton number of the daughter
 * @param R the nuclear radius of the daughter
 * @param betaType the BetaType of the transition
 * @return the value
 *
 * The point charge Fermi function @f$ F_0(Z, W) @f$
 * \f[ F_0(Z,W) = 2(\gamma+1) \Gamma(2\gamma+1)^{-2} (2pR)^{2(\gamma-1)}
 *e^{\pi\alpha Z W /p} |\Gamma(\gamma + i \alpha Z W /p) |^2\f]
 * the last factor \f$ |\Gamma(\gamma + i \alpha Z W /p) |^2 \f$ is calculated
 *using GSL. The GSL function returns the magnitude and phase, and here, as we
 *are interested in the absolute value of the result we just use the
 *magnitude.
 * The calculation of the 2nd factor \f$ \Gamma(2\gamma+1)^{-2} \f$ and the
 *last factor \f$ |\Gamma(\gamma + i \alpha Z W /p) |^2 \f$ is combined, i.e.
 * \f[ \ln\frac{a^2}{b^2} = 2\ln\frac{a}{b} = 2(\ln a - \ln b) \f]
 *
 */
double FermiFunction(double W, int Z, double R, int betaType);

/**
 * @brief C correction
 * @param W total energy in units of electron mass
 * @param W0 the total endpoint energy in units of the electron rest mass
 * @param Z proton number
 * @param A mass number
 * @param R nuclear radius in natural units
 * @param betaType the BetaType of the transition
 * @param decayType the DecayType of the transition
 * @param gA the axial vector coupling constant
 * @param gP the induced pseudoscalar coupling constant
 * @param fc1 the c1 form factor as per Holstein (@f$ g_A M_{GT} @f$)
 * @param fb the b form factor as per Holstein
 * @param fd the d form factor as per Holstein
 * @param ratioM121 the ratio of the @f$^AM_{121}@f$ and @f$ ^AM_{101}@f$ matrix elements in the Behrens-Buehring formalism
 * @param addCI boolean to decide whether or not to include the isovector correction to the shape part of C
 * @param NSShape string, says which charge distribution to use in the C correction
 * @param hoFit the fitted A value for the Modified Gaussian distribution
 * @param spsi NuclearStructure::SingleParticleState object denoting the initial nucleon state
 * @param spsf NuclearStructure::SingleParticleState object denoting the final nucleon state
 *
 * The C correction describing effects of finite nuclear size and induced currents when the connection
   to the NME library has been made and actual single-particle wave functions will be used in C_I
 */
double CCorrection(double W, double W0, int Z, int A, double R, int betaType,
                   int decayType, double gA, double gP, double fc1, double fb,
                   double fd, double ratioM121, bool addCI, std::string NSShape,
                   double hoFit, nme::NuclearStructure::SingleParticleState& spsi, nme::NuclearStructure::SingleParticleState& spsf);

/**
 * @brief C correction
 * @param W total energy in units of electron mass
 * @param W0 the total endpoint energy in units of the electron rest mass
 * @param Z proton number
 * @param A mass number
 * @param R nuclear radius in natural units
 * @param betaType the BetaType of the transition
 * @param decayType the DecayType of the transition
 * @param gA the axial vector coupling constant
 * @param gP the induced pseudoscalar coupling constant
 * @param fc1 the c1 form factor as per Holstein (@f$ g_A M_{GT} @f$)
 * @param fb the b form factor as per Holstein
 * @param fd the d form factor as per Holstein
 * @param ratioM121 the ratio of the @f$^AM_{121}@f$ and @f$ ^AM_{101}@f$ matrix elements in the Behrens-Buehring formalism
 * @param addCI boolean to decide whether or not to include the isovector correction to the shape part of C
 * @param NSShape string, says which charge distribution to use in the C correction
 * @param hoFit the fitted A value for the Modified Gaussian distribution
 *
 * The C correction describing effects of finite nuclear size and induced currents.
 */
double CCorrection(double W, double W0, int Z, int A, double R, int betaType,
                   int decayType, double gA, double gP, double fc1, double fb,
                   double fd, double ratioM121, bool addCI, std::string NSShape,
                   double hoFit);
/**
 * @brief C correction
 * @param W total energy in units of electron mass
 * @param W0 the total endpoint energy in units of the electron rest mass
 * @param Z proton number
 * @param A mass number
 * @param R nuclear radius in natural units
 * @param betaType the BetaType of the transition
 * @param hoFit the fitted A value for the Modified Gaussian distribution
 * @param decayType the DecayType of the transition
 * @param gA the axial vector coupling constant
 * @param gP the induced pseudoscalar coupling constant
 * @param fc1 the c1 form factor as per Holstein (@f$ g_A M_{GT} @f$)
 * @param fb the b form factor as per Holstein
 * @param fd the d form factor as per Holstein
 * @param ratioM121 the ratio of the @f$^AM_{121}@f$ and @f$ ^AM_{101}@f$ matrix elements in the Behrens-Buehring formalism
 * @param NSShape string, says which charge distribution to use in the C correction
 * @param hoFit the fitted A value for the Modified Gaussian distribution
 * @return the value
 *
 * The C correction describing effects of finite nuclear size and induced currents.
   Return the shape and nuclear-sensitive parts separately in a tuple.
 */
std::tuple<double, double> CCorrectionComponents(double W, double W0, int Z, int A, double R, int betaType,
                   int decayType, double gA, double gP, double fc1, double fb, double fd, double ratioM121,
                   std::string NSShape, double hoFit);

/**
 * Isovector correction to the charge density-calculated C correction
 *
 * @param W electron total energy in units of its rest mass
 * @param W0 total endpoint energy in units of the electron rest mass
 * @param Z proton number
 * @param A mass number
 * @param R nuclear radius in natural units
 * @param betaType BetaType of the transition
 * @param decayType DecayType of the transition
 */
double CICorrection(double W, double W0, int Z, int A, double R, int betaType);

/**
 * Isovector correction to the charge density-calculated C correction
 * Gets called when connection with NME is turned on, thereby using actual
 * single particle wave functions from a (deformed) Woods-Saxon potential
 *
 * @param W electron total energy in units of its rest mass
 * @param W0 total endpoint energy i units of the electron rest mass
 * @param Z proton number
 * @param R nuclear radius in natural units
 * @betaType beta type of the transition
 * @param spsi NuclearStructure::SingleParticleState object denoting the initial state
 * @param spsf NuclearStructure::SingleParticleState object denoting the final state
 */
double CICorrection(double W, double W0, double Z, double R, int betaType,
    nme::NuclearStructure::SingleParticleState& spsi, nme::NuclearStructure::SingleParticleState& spsf);

/**
 * Relativistic matrix element correction to the vector pahe "black hole girl" right now, and how she's being given too much credit for her role in the historic first image of a black hole. Because this is too important, I want to set the record straight.

Once Katie Bouman became the "face" of the black hole photo, and articles began to call her "the woman behind the black hole photo", an assortment of people that I'm strongly inclined to callrt of the C correction
 * as per Wilkinson.
 *
 * @param W electron total energy in units of its rest mass
 * @param W0 total endpoint energy in units of the electron rest mass
 * @param Z proton number
 * @param A mass number
 * @param R nuclear radius in natural units
 * @param betaType BetaType of the transition
 * @param decayType DecayType of the transition
 */
double RelativisticCorrection(double W, double W0, int Z, int A, double R,
                              int betaType, int decayType);

/**
 * Deformation correction to L0
 *
 * @param W electron total energy in units of its rest mass
 * @param W0 total endpoint energy in units of the electron rest mass
 * @param Z proton number
 * @param A mass number
 * @param R nuclear radius in natural units
 * @param beta2 quadrupole deformation
 * @param betaType BetaType of the transition
 * @param aPos array of fitted constants for beta+ decay
 * @param aNeg array of fitted constants for beta- decay
 */
double DeformationCorrection(double W, double W0, int Z, double R, double beta2,
                             int betaType, double aPos[], double aNeg[]);

/**
 * Electrostatic finite size correction to the point charge Fermi function
 * written as @f$L_0(Z, W) @f$
 *
 * @param W electron total energy in units of its rest mass
 * @param W0 total endpoint energy in units of the electron rest mass
 * @param Z proton number
 * @param r radius in natural units
 * @param betaType BetaType of the transition
 * @param aPos array of fitted constants for beta+ decay
 * @param aNeg array of fitted constants for beta- decay
 */
double L0Correction(double W, int Z, double r, int betaType, double aPos[],
                    double aNeg[]);

/**
 * Correction to L0 by moving from a uniformly charged sphere to a more elaborate nuclear shape
 *
 * @param W electron total energy in units of its rest mass
 * @param Z proton number
 * @param R nuclear radius in natural units
 * @param betaType BetaType of the transition
 * @param ESShape string denoting the name of the base shape. Currently only Fermi is implemented
 * @param v vector representing the first 3 terms in an even-r power expansion of the base shape
 * @param vp vector representing the first 3 terms in an even-r power expansion of the new shape
 */
double UCorrection(double W, int Z, double R, int betaType, std::string ESShape, std::vector<double>& v, std::vector<double>& vp);

/**
 * Correction to L0 by calculating @f$ \frac{L_0'}{L_0} @f$ using a power expansion of the potentials
 *
 * @param W electron total energy in units of its rest mass
 * @param Z proton number
 * @param R nuclear radius in natural units
 * @param betaType BetaType of the transition
 * @param v vector representing the first 3 terms in an even-r power expansion of the base shape
 * @param vp vector representing the first 3 terms in an even-r power expansion of the new shape
 * @see UCorrection
 */
double UCorrection(double W, int Z, double R, int betaType, std::vector<double>& v, std::vector<double>& vp);

/**
 * Electromagnetic correction to the Fermi function due to the change in the
 * electromagnetic field of the recoiling nucleus compared to it standing still
 *
 * @param W electron total energy in units of its rest mass
 * @param W0 total endpoint energy in units of the electron rest mass
 * @param Z proton number
 * @param A mass number
 * @param betaType BetaType of the transition
 * @param decayType decsay type of the transition
 * @double mixingRatio mixing ratio of Fermi versus Gamow-Teller
 */
double QCorrection(double W, double W0, int Z, int A, int betaType,
                   int decayType, double mixingRatio);

/**
 * The radiative correction up to order @f$ \alpha^3Z^2 @f$ as per Sirlin
 *
 * @param W total electron energy in units of its rest mass
 * @param W0 total endpoint energy in units of the electron rest mass
 * @param Z proton number
 * @param R nuclear radius in natural units
 * @param betaType BetaType of the transition
 * @param gA axial vector coupling constant @f$ g_A @f$
 * @param gM nucleon isovector moment @f$ g_M = 4.706 @f$
 *
 * The first order correction is \f$ \delta_1=\frac{\alpha}{2\pi}g(W_0,W) \f$,
 *where \f$ g \f$ is defined by Sirlin (1967).
 * \f{eqnarray*} g(W_0,W) = & 3 \ln{\frac{m_p}{m_e}} - \frac{3}{4} +
 *\frac{4}{\beta}\rm{Spence}{\frac{2\beta}{1+\beta}} + 4 \left(
 *\frac{\tanh^{-1}{\beta}}{\beta}-1 \right) \\
 * & \times \left[ \frac{W_0-W}{3W} - \frac{3}{2} + \ln{2(W_0-W)} \right]  \\
 * & + \frac{\tanh^{-1}{\beta}}{\beta} \left[ 2(1+\beta^2) +
 *\frac{(W_0-W)^2}{6W^2} -4\tanh^{-1}{\beta}\right]
 * \f}
 *
 * where \f$ \tanh^{-1} \f$ is the inverse hyperbolic tangent function, \f$
 *\beta = \sqrt{W^2-1} \f$ and the Spence function is defined elsewhere.
 * @see Spence()
 */
double RadiativeCorrection(double W, double W0, int Z, double R, int betaType,
                           double gA, double gM);

/**
 * Radiative correction to the neutrino spectrum by Sirlin and Marciano
 *
 * @param Wv neutrino total energy in units of the electron rest mass
 */
double NeutrinoRadiativeCorrection(double Wv);

/**
 * Kinematic recoil correction to the beta spectrum due to the enlargement of the phase space
 *
 * @param W electron total energy in units of its rest mass
 * @param W0 total endpoint energy in units of the electron rest mass
 * @param A mass number
 * @param decayType decsay type of the transition
 * @double mixingRatio mixing ratio of Fermi versus Gamow-Teller
 */
double RecoilCorrection(double W, double W0, int A, int decayType,
                        double mixingRatio);

/**
 * Correction due to atomic screening calculated using the Salvat potential
 *
 * @param W electron total energy in units of its rest mass
 * @param Z proton number
 * @param betaType the BetaType of the transition
 */
double AtomicScreeningCorrection(double W, int Z, int betaType);

/**
 * The atomic exchange correction where an electron decays into a bound state of the daughter atom
 * and its corresponding interference with the direct process
 *
 * @param W electron total energy in units of its rest mass
 * @param exPars array containing the 9 fit parameters required for the analytical parametrisation
 */
double AtomicExchangeCorrection(double W, double exPars[9]);

/**
 * Correction due to the mismatch between initial and final atomic states, causing the
 * endpoint of the transition to get smaller
 *
 * @param W electron total energy in units of its rest mass
 * @param W0 total endpoint energy in units of the electron rest mass
 * @param Z proton number
 * @param A mass number
 * @param betaType BetaType of the transition
 */
double AtomicMismatchCorrection(double W, double W0, int Z, int A,
                                int betaType);

/**
 * @brief Spence function
 * @param x
 * @return -gs_sf_dilog(x)
 *
 * The Spence function is included here because the Wilkinson article refers
 *to it. It's value is actually equal (with a sign change) to the DiLogarithm,
 *which is used from GSL.
 * \f[ \rm{Spence} = \int_0^x\frac{\ln{(1-t)}}{t}\mathrm{d}t \equiv -
 *\sum_{k=1}^{k=\infty}\frac{x^k}{k^2} \equiv -\mathrm{Li}_2(x) \f]
 */
double Spence(double x);
}
}

#endif  // SPECTRALFUNCTIONS

ext: h

max_stars_repo_name: MorisRand/BSG

max_issues_repo_name: MorisRand/BSG

max_forks_repo_name: MorisRand/BSG


text:
#include <stdio.h>
#include <gsl/gsl_vector.h>

int sum(double* arr, int size) {
    for (int i=0; i<size ; i++) {
        arr[i] += 10;
    }
    return 0;
}

gsl_vector* get_vector( int size )
{
    int i;
    gsl_vector * v = gsl_vector_alloc (size);

    for (i = 0; i < size; i++)
    {
        gsl_vector_set (v, i, 1.23 + i);

    }
    return v;
}

double * get_vector_pointer(gsl_vector* v){
    return gsl_vector_ptr(v, 0);
}

int print_array_data(double* arr, int size){
    for(int i=0; i<size; i++) {
        printf("%f\n", arr[i]);
    }
    return 0;
}

int free_vector(gsl_vector * v)
{
    gsl_vector_free(v);
    return 0;
}

int main(int argc, char *argv[]) {
    gsl_vector* vec = get_vector(1);
    double* darry = get_vector_pointer(vec);
    //incd(darry,1);
    printf("printing darry\n");
    print_array_data(darry, 1);
    free_vector(vec);

}

double* get_double_array(int size) {
    double* arr = (double*) malloc(size*sizeof(double));
    for (int i=0; i<size; i++ ) {
        arr[i] = i;
    }
    return arr;
}
int free_double_array(double* arr) {
    free(arr);
    return 0;
}

gsl_vector_view make_vector(double* arr, int size) {
    return gsl_vector_view_array(arr, size);
}

max_stars_repo_name: subramon/qlu

max_issues_repo_name: subramon/qlu

max_forks_repo_name: subramon/qlu


text:
#ifndef LOGSUMEXP_INCLUDED
#define LOGSUMEXP_INCLUDED

#include <limits>
#include <gsl/gsl_vector.h>
#include <gsl/gsl_matrix.h>
#include <cmath>
#include "vguard.h"

/* uncomment to disable lookup table */
/*
#define LOG_SUM_EXP_SLOW
*/

/* uncomment to catch NaN errors */
/*
#define NAN_DEBUG
*/

#define LOG_SUM_EXP_LOOKUP_MAX 10
#define LOG_SUM_EXP_LOOKUP_PRECISION .0001

#define LOG_SUM_EXP_LOOKUP_ENTRIES (((int) (LOG_SUM_EXP_LOOKUP_MAX / LOG_SUM_EXP_LOOKUP_PRECISION)) + 1)

/* comment to disable interpolation */
#define LOG_SUM_EXP_INTERPOLATE

namespace MachineBoss {

using namespace std;

typedef double LogProb;

double log_sum_exp_unary_slow (double x);  /* does not use lookup table */

struct LogSumExpLookupTable {
  double *lookup;
  LogSumExpLookupTable();
  ~LogSumExpLookupTable();
};

extern LogSumExpLookupTable logSumExpLookupTable;

inline double log_sum_exp_unary (double x) {
  /* returns log(1 + exp(-x)) for nonnegative x */
#ifdef LOG_SUM_EXP_SLOW
  return log_sum_exp_unary_slow(x);
#else /* LOG_SUM_EXP_SLOW */
  if (x >= LOG_SUM_EXP_LOOKUP_MAX || std::isnan(x) || std::isinf(x))
    return 0;
  if (x < 0) {  /* really dumb approximation for x < 0. Should never be encountered, so issue a warning */
    cerr << "Called log_sum_exp_unary(x) for negative x = " << x << endl;
    return -x;
  }
  const int n = (int) (x / LOG_SUM_EXP_LOOKUP_PRECISION);
  const double f0 = logSumExpLookupTable.lookup[n];
#ifdef LOG_SUM_EXP_INTERPOLATE
  const double dx = x - (n * LOG_SUM_EXP_LOOKUP_PRECISION);
  const double f1 = logSumExpLookupTable.lookup[n+1];
  const double df = f1 - f0;
  return f0 + df * (dx / LOG_SUM_EXP_LOOKUP_PRECISION);
#else /* LOG_SUM_EXP_INTERPOLATE */
  return f0;
#endif /* LOG_SUM_EXP_INTERPOLATE */
#endif /* LOG_SUM_EXP_SLOW */
}

inline double log_sum_exp (double a, double b) {
  /* returns log(exp(a) + exp(b)) */
  double max, diff, ret;
  // Note: Infinity plus or minus a finite quantity is still Infinity,
  // but Infinity - Infinity = NaN.
  // Thus, we are susceptible to NaN errors when trying to add 0+0 in log-space.
  // To work around this, we explicitly test for a==b.
  if (a == b) { max = a; diff = 0; }
  else if (a < b) { max = b; diff = b - a; }
  else { max = a; diff = a - b; }
  ret = max + log_sum_exp_unary (diff);
#if defined(NAN_DEBUG)
  if (std::isnan(ret)) {
    cerr << "NaN error in log_sum_exp" << endl;
    throw;
  }
#endif
  return ret;
}

inline double log_sum_exp (double a, double b, double c) {
    return log_sum_exp (log_sum_exp (a, b), c);
}

inline double log_sum_exp (double a, double b, double c, double d) {
    return log_sum_exp (log_sum_exp (log_sum_exp (a, b), c), d);
}

inline double log_accum_exp (double& a, double b) {
  a = log_sum_exp (a, b);
  return a;
}

inline double log_sum_exp (double a, double b, double c, double d, double e) {
    return log_sum_exp (log_sum_exp (log_sum_exp (log_sum_exp (a, b), c), d), e);
}

inline double log_sum_exp (const vguard<double>& v) {
  double lpTot = -numeric_limits<double>::infinity();
  for (auto lp : v)
    (void) log_accum_exp (lpTot, lp);
  return lpTot;
}

inline double log_sum_exp (const vguard<vguard<double> >& v) {
  double lpTot = -numeric_limits<double>::infinity();
  for (auto lp : v)
    (void) log_accum_exp (lpTot, log_sum_exp (lp));
  return lpTot;
}

double log_sum_exp_slow (double a, double b);  /* does not use lookup table */
double log_sum_exp_slow (double a, double b, double c);
double log_sum_exp_slow (double a, double b, double c, double d);

double log_accum_exp_slow (double& a, double b);

inline double log_subtract_exp (double a, double b) {
  if (a < b) {
    cerr << "Sign error in log_subtract_exp" << endl;
    throw;
  }
  return a + log (1. - exp(b-a));
}

vguard<LogProb> log_vector (const vguard<double>& v);
vguard<vguard<LogProb> > log_matrix (const vguard<vguard<double> >& m);

vguard<LogProb> log_gsl_vector (const gsl_vector* v);
vguard<double> gsl_vector_to_stl (const gsl_vector* v);

vguard<vguard<LogProb> > log_vector_gsl_vector (const vguard<const gsl_vector*>& v);

vguard<vguard<double> > gsl_matrix_to_stl (const gsl_matrix* m);
gsl_matrix* stl_to_gsl_matrix (const vguard<vguard<double> >& m);

inline LogProb logInnerProduct (const vguard<LogProb>& v1, const vguard<LogProb>& v2) {
  LogProb lip = -numeric_limits<double>::infinity();
  for (vguard<LogProb>::const_iterator iter1 = v1.begin(), iter2 = v2.begin(); iter1 != v1.end(); ++iter1, ++iter2)
    lip = log_sum_exp (lip, *iter1 + *iter2);
  return lip;
}

inline LogProb logInnerProduct (const vguard<LogProb>& v1, const vguard<LogProb>& v2, const vguard<LogProb>& v3) {
  LogProb lip = -numeric_limits<double>::infinity();
  for (vguard<LogProb>::const_iterator iter1 = v1.begin(), iter2 = v2.begin(), iter3 = v3.begin(); iter1 != v1.end(); ++iter1, ++iter2, ++iter3)
    lip = log_sum_exp (lip, *iter1 + *iter2 + *iter3);
  return lip;
}

inline LogProb logInnerProduct (const vguard<vguard<LogProb> >& v1, const vguard<vguard<LogProb> >& v2) {
  LogProb lip = -numeric_limits<double>::infinity();
  for (vguard<vguard<LogProb> >::const_iterator iter1 = v1.begin(), iter2 = v2.begin(); iter1 != v1.end(); ++iter1, ++iter2)
    lip = log_sum_exp (lip, logInnerProduct (*iter1, *iter2));
  return lip;
}

double logBetaPdf (double prob, double yesCount, double noCount);  // alpha = yesCount+1, beta = noCount+1
double logGammaPdf (double rate, double eventCount, double waitTime);  // alpha = shape = eventCount+1, beta = rate = 1/scale = 1/theta = waitTime
double logDirichletPdf (const vguard<double>& prob, const vguard<double>& count);  // alpha[n] = count[n] + 1
double logGaussianPdf (double x, double mu, double sigma);

}  // end namespace

#endif /* LOGSUMEXP_INCLUDED */

max_stars_repo_name: ihh/acidbot

max_issues_repo_name: evoldoers/bossmachine

max_forks_repo_name: evoldoers/bossmachine


text:
/**
 * This file is part of the Contour terminal project
 *   Copyright (c) 2019-2021 Christian Parpart <christian@parpart.family>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#pragma once

#include <gsl/span>
#include <gsl/span_ext>

#include <algorithm>
#include <cassert>
#include <iterator>
#include <stdexcept>
#include <vector>

namespace crispy
{

template <typename T, typename Vector>
struct RingIterator;
template <typename T, typename Vector>
struct RingReverseIterator;

/**
 * Implements an efficient ring buffer over type T
 * and the underlying storage Vector.
 */
template <typename T, typename Vector = std::vector<T>>
class basic_ring
{
  public:
    using value_type = T;
    using iterator = RingIterator<value_type, Vector>;
    using const_iterator = RingIterator<value_type const, Vector>;
    using reverse_iterator = RingReverseIterator<value_type, Vector>;
    using const_reverse_iterator = RingReverseIterator<value_type const, Vector>;
    using difference_type = long;
    using offset_type = long;

    basic_ring() = default;
    basic_ring(basic_ring const&) = default;
    basic_ring& operator=(basic_ring const&) = default;
    basic_ring(basic_ring&&) noexcept = default;
    basic_ring& operator=(basic_ring&&) noexcept = default;
    virtual ~basic_ring() = default;

    explicit basic_ring(Vector storage): _storage(std::move(storage)) {}

    value_type const& operator[](offset_type i) const noexcept
    {
        return _storage[size_t(offset_type(_zero + size()) + i) % size()];
    }
    value_type& operator[](offset_type i) noexcept
    {
        return _storage[size_t(offset_type(_zero + size()) + i) % size()];
    }

    value_type const& at(offset_type i) const noexcept
    {
        return _storage[size_t(_zero + size() + i) % size()];
    }
    value_type& at(offset_type i) noexcept
    {
        return _storage[size_t(offset_type(_zero + size()) + i) % size()];
    }

    Vector& storage() noexcept { return _storage; }
    Vector const& storage() const noexcept { return _storage; }
    std::size_t zero_index() const noexcept { return _zero; }

    void rezero(iterator i);
    void rezero();

    std::size_t size() const noexcept { return _storage.size(); }

    // positvie count rotates right, negative count rotates left
    void rotate(int count) noexcept { _zero = size_t(offset_type(_zero + size()) - count) % size(); }

    void rotate_left(std::size_t count) noexcept { _zero = (_zero + size() + count) % size(); }
    void rotate_right(std::size_t count) noexcept { _zero = (_zero + size() - count) % size(); }
    void unrotate() { _zero = 0; }

    value_type& front() noexcept { return at(0); }
    value_type const& front() const noexcept { return at(0); }

    value_type& back()
    {
        if (size() == 0)
            throw std::length_error("empty");

        return at(static_cast<offset_type>(size()) - 1);
    }

    value_type const& back() const
    {
        if (size() == 0)
            throw std::length_error("empty");

        return at(static_cast<offset_type>(size()) - 1);
    }

    iterator begin() noexcept { return iterator { this, 0 }; }
    iterator end() noexcept { return iterator { this, static_cast<difference_type>(size()) }; }

    const_iterator cbegin() const noexcept
    {
        return const_iterator { (basic_ring<value_type const, Vector>*) this, 0 };
    }
    const_iterator cend() const noexcept
    {
        return const_iterator { (basic_ring<value_type const, Vector>*) this,
                                static_cast<difference_type>(size()) };
    }

    const_iterator begin() const noexcept { return cbegin(); }
    const_iterator end() const noexcept { return cend(); }

    reverse_iterator rbegin() noexcept;
    reverse_iterator rend() noexcept;

    const_reverse_iterator rbegin() const noexcept;
    const_reverse_iterator rend() const noexcept;

    gsl::span<value_type> span(offset_type start, size_t count) noexcept
    {
        auto a = std::next(begin(), start);
        auto b = std::next(a, count);
        return gsl::make_span(a, b);
    }

    gsl::span<value_type const> span(offset_type start, size_t count) const noexcept
    {
        auto a = std::next(begin(), start);
        auto b = std::next(a, count);
        return gsl::make_span(a, b);
    }

  protected:
    Vector _storage;
    std::size_t _zero = 0;
};

/**
 * Implements an efficient ring buffer over type T
 * and the underlying dynamic storage type Vector<T, Allocator>.
 */
template <typename T,
          template <typename, typename> class Container = std::vector,
          typename Allocator = std::allocator<T>>
class ring: public basic_ring<T, Container<T, Allocator>>
{
  public:
    using basic_ring<T, Container<T, Allocator>>::basic_ring;

    ring(size_t capacity, T value): ring(Container<T, Allocator>(capacity, value)) {}
    explicit ring(size_t capacity): ring(capacity, T {}) {}

    size_t size() const noexcept { return this->_storage.size(); }

    void reserve(size_t capacity) { this->_storage.reserve(capacity); }
    void resize(size_t newSize)
    {
        this->rezero();
        this->_storage.resize(newSize);
    }
    void clear()
    {
        this->_storage.clear();
        this->_zero = 0;
    }
    void push_back(T const& _value) { this->_storage.push_back(_value); }

    void push_back(T&& _value) { this->emplace_back(std::move(_value)); }

    template <typename... Args>
    void emplace_back(Args&&... args)
    {
        this->_storage.emplace_back(std::forward<Args>(args)...);
    }

    void pop_front() { this->_storage.erase(this->_storage.begin()); }
};

/// Fixed-size basic_ring<T> implementation
template <typename T, std::size_t N>
using fixed_size_ring = basic_ring<T, std::array<T, N>>;

// {{{ iterator
template <typename T, typename Vector>
struct RingIterator
{
    using iterator_category = std::random_access_iterator_tag;
    using value_type = T;
    using difference_type = long;
    using pointer = T*;
    using reference = T&;

    basic_ring<T, Vector>* ring {};
    difference_type current {};

    RingIterator(basic_ring<T, Vector>* aRing, difference_type aCurrent): ring { aRing }, current { aCurrent }
    {
    }

    RingIterator() = default;

    RingIterator(RingIterator const&) = default;
    RingIterator& operator=(RingIterator const&) = default;

    RingIterator(RingIterator&&) noexcept = default;
    RingIterator& operator=(RingIterator&&) noexcept = default;

    RingIterator& operator++() noexcept
    {
        ++current;
        return *this;
    }

    RingIterator operator++(int) noexcept
    {
        auto old = *this;
        ++(*this);
        return old;
    }

    RingIterator& operator--() noexcept
    {
        --current;
        return *this;
    }

    RingIterator operator--(int) noexcept
    {
        auto old = *this;
        --(*this);
        return old;
    }

    RingIterator& operator+=(int n) noexcept
    {
        current += n;
        return *this;
    }
    RingIterator& operator-=(int n) noexcept
    {
        current -= n;
        return *this;
    }

    RingIterator operator+(difference_type n) noexcept { return RingIterator { ring, current + n }; }
    RingIterator operator-(difference_type n) noexcept { return RingIterator { ring, current - n }; }

    RingIterator operator+(RingIterator const& rhs) const noexcept
    {
        return RingIterator { ring, current + rhs.current };
    }
    difference_type operator-(RingIterator const& rhs) const noexcept { return current - rhs.current; }

    friend RingIterator operator+(difference_type n, RingIterator a)
    {
        return RingIterator { a.ring, n + a.current };
    }
    friend RingIterator operator-(difference_type n, RingIterator a)
    {
        return RingIterator { a.ring, n - a.current };
    }

    bool operator==(RingIterator const& rhs) const noexcept { return current == rhs.current; }
    bool operator!=(RingIterator const& rhs) const noexcept { return current != rhs.current; }

    T& operator*() noexcept { return (*ring)[current]; }
    T const& operator*() const noexcept { return (*ring)[current]; }

    T* operator->() noexcept { return &(*ring)[current]; }
    T* operator->() const noexcept { return &(*ring)[current]; }
};
// }}}

// {{{ reverse iterator
template <typename T, typename Vector>
struct RingReverseIterator
{
    using iterator_category = std::random_access_iterator_tag;
    using value_type = T;
    using difference_type = long;
    using pointer = T*;
    using reference = T&;

    basic_ring<T, Vector>* ring;
    difference_type current;

    RingReverseIterator(basic_ring<T, Vector>* _ring, difference_type _current):
        ring { _ring }, current { _current }
    {
    }

    RingReverseIterator(RingReverseIterator const&) = default;
    RingReverseIterator& operator=(RingReverseIterator const&) = default;

    RingReverseIterator(RingReverseIterator&&) noexcept = default;
    RingReverseIterator& operator=(RingReverseIterator&&) noexcept = default;

    RingReverseIterator& operator++() noexcept
    {
        ++current;
        return *this;
    }
    RingReverseIterator& operator++(int) noexcept { return ++(*this); }

    RingReverseIterator& operator--() noexcept
    {
        --current;
        return *this;
    }
    RingReverseIterator& operator--(int) noexcept { return --(*this); }

    RingReverseIterator& operator+=(int n) noexcept
    {
        current += n;
        return *this;
    }
    RingReverseIterator& operator-=(int n) noexcept
    {
        current -= n;
        return *this;
    }

    RingReverseIterator operator+(difference_type n) noexcept
    {
        return RingReverseIterator { ring, current + n };
    }
    RingReverseIterator operator-(difference_type n) noexcept
    {
        return RingReverseIterator { ring, current - n };
    }

    RingReverseIterator operator+(RingReverseIterator const& rhs) const noexcept
    {
        return RingReverseIterator { ring, current + rhs.current };
    }
    difference_type operator-(RingReverseIterator const& rhs) const noexcept { return current - rhs.current; }

    friend RingReverseIterator operator+(difference_type n, RingReverseIterator a)
    {
        return RingReverseIterator { a.ring, n + a.current };
    }
    friend RingReverseIterator operator-(difference_type n, RingReverseIterator a)
    {
        return RingReverseIterator { a.ring, n - a.current };
    }

    bool operator==(RingReverseIterator const& rhs) const noexcept { return current == rhs.current; }
    bool operator!=(RingReverseIterator const& rhs) const noexcept { return current != rhs.current; }

    T& operator*() noexcept { return (*ring)[ring->size() - current - 1]; }
    T const& operator*() const noexcept { return (*ring)[ring->size() - current - 1]; }

    T* operator->() noexcept { return &(*ring)[static_cast<difference_type>(ring->size()) - current - 1]; }

    T* operator->() const noexcept
    {
        return &(*ring)[static_cast<difference_type>(ring->size()) - current - 1];
    }
};
// }}}

// {{{ basic_ring<T> impl
template <typename T, typename Vector>
typename basic_ring<T, Vector>::reverse_iterator basic_ring<T, Vector>::rbegin() noexcept
{
    return reverse_iterator { this, 0 };
}

template <typename T, typename Vector>
typename basic_ring<T, Vector>::reverse_iterator basic_ring<T, Vector>::rend() noexcept
{
    return reverse_iterator { this, size() };
}

template <typename T, typename Vector>
typename basic_ring<T, Vector>::const_reverse_iterator basic_ring<T, Vector>::rbegin() const noexcept
{
    return const_reverse_iterator { (basic_ring<T const, Vector>*) this, 0 };
}

template <typename T, typename Vector>
typename basic_ring<T, Vector>::const_reverse_iterator basic_ring<T, Vector>::rend() const noexcept
{
    return const_reverse_iterator { (basic_ring<T const, Vector>*) this,
                                    static_cast<difference_type>(size()) };
}

template <typename T, typename Vector>
void basic_ring<T, Vector>::rezero()
{
    std::rotate(begin(), std::next(begin(), static_cast<difference_type>(_zero)), end()); // shift-left
    _zero = 0;
}

template <typename T, typename Vector>
void basic_ring<T, Vector>::rezero(iterator i)
{
    std::rotate(begin(), std::next(begin(), i.current), end()); // shift-left
    _zero = 0;
}
// }}}

} // namespace crispy

max_stars_repo_name: sebastianrakel/contour

max_issues_repo_name: sebastianrakel/contour

max_forks_repo_name: christianparpart/libterminal


text:
#include "ui/detail/ui_helpers_native.h"
#include <gsl/gsl>
struct Tcl_Interp;

namespace cws80 {

class TkUI : public NativeUI {
public:
    std::string choose_file(gsl::span<const FileChooserFilter> filters, const std::string &directory, const std::string &title, FileChooserMode mode) override;
    cxx::optional<std::string> edit_line(const std::string &title, const std::string &initial_value) override;
    uint select_by_menu(gsl::span<const std::string> choices, uint initial_selection) override;

private:
    static Tcl_Interp *create_tk_interp();
    static std::string quote(gsl::cstring_span str);
};

}  // namespace cws80


text:
/* Copyright 2015 The TensorFlow Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
// Portions Copyright (c) Microsoft Corporation

#pragma once

#include <functional>
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>
#include <gsl/gsl>

#include "core/common/common.h"
#include "core/common/path_string.h"
#include "core/framework/callback.h"
#include "core/platform/env_time.h"
#include "core/platform/telemetry.h"

#ifndef _WIN32
#include <sys/types.h>
#include <unistd.h>
#endif
namespace Eigen {
class ThreadPoolInterface;
}
namespace onnxruntime {

#ifdef _WIN32
using PIDType = unsigned long;
using FileOffsetType = int64_t;
#else
using PIDType = pid_t;
using FileOffsetType = off_t;
#endif

class EnvThread {
 public:
  virtual void OnCancel() = 0;
  virtual ~EnvThread() = default;
};

// Parameters that are required to create a set of threads for a thread pool
struct ThreadOptions {
  // Stack size for a new thread. If it is 0, the operating system uses the same value as the stack that's specified for
  // the main thread, which is usually set in the main executable(not controlled by onnxruntime.dll).
  unsigned int stack_size = 0;

  // Thread affinity means a thread can only run on the logical processors that the thread is allowed to run on.
  // If the vector is not empty, set the affinity of each thread to just one CPU.
  // Index is thread index, value is CPU ID, starting from zero. For example, the first thread in the pool will be bound
  // to the logical processor with id of affinity[0]. If the vector is empty, the thread can run on all the processors
  // its process can run on. NOTE: When hyperthreading is enabled, for example, on a 4 cores 8 physical threads CPU,
  // processor group [0,1,2,3] may only contain half of the physical cores.
  std::vector<size_t> affinity;

  // Set or unset denormal as zero.
  bool set_denormal_as_zero = false;
};
/// \brief An interface used by the onnxruntime implementation to
/// access operating system functionality like the filesystem etc.
///
/// Callers may wish to provide a custom Env object to get fine grain
/// control.
///
/// All Env implementations are safe for concurrent access from
/// multiple threads without any external synchronization.
class Env {
 public:
  using EnvThread = onnxruntime::EnvThread;
  virtual ~Env() = default;
  // clang-format off
  /**
   * Start a new thread for a thread pool
   * \param name_prefix A human-readable string for debugging purpose, can be NULL
   * \param index The index value of the thread, for each thread pool instance, the index should start from 0 and be continuous.
   * \param start_address The entry point of thread
   * \param threadpool The thread pool that the new thread belongs to
   * \param thread_options options to create the thread
   *
   * Caller is responsible for deleting the returned value
   */
  // clang-format on
  virtual EnvThread* CreateThread(_In_opt_z_ const ORTCHAR_T* name_prefix, int index,
                                  _In_ unsigned (*start_address)(int id, Eigen::ThreadPoolInterface* param),
                                  Eigen::ThreadPoolInterface* threadpool, const ThreadOptions& thread_options) = 0;

  /// \brief Returns a default environment suitable for the current operating
  /// system.
  ///
  /// Sophisticated users may wish to provide their own Env
  /// implementation instead of relying on this default environment.
  ///
  /// The result of Default() belongs to this library and must never be deleted.
  static Env& Default();

  virtual int GetNumCpuCores() const = 0;

  // This function doesn't support systems with more than 64 logical processors
  virtual std::vector<size_t> GetThreadAffinityMasks() const = 0;

  /// \brief Returns the number of micro-seconds since the Unix epoch.
  virtual uint64_t NowMicros() const {
    return env_time_->NowMicros();
  }

  /// \brief Returns the number of seconds since the Unix epoch.
  virtual uint64_t NowSeconds() const {
    return env_time_->NowSeconds();
  }

  /// Sleeps/delays the thread for the prescribed number of micro-seconds.
  /// On Windows, it's the min time to sleep, not the actual one.
  virtual void SleepForMicroseconds(int64_t micros) const = 0;

  /**
   * Gets the length of the specified file.
   */
  virtual common::Status GetFileLength(_In_z_ const ORTCHAR_T* file_path, size_t& length) const = 0;
  virtual common::Status GetFileLength(int fd, /*out*/ size_t& file_size) const = 0;

  /**
   * Copies the content of the file into the provided buffer.
   * @param file_path The path to the file.
   * @param offset The file offset from which to start reading.
   * @param length The length in bytes to read.
   * @param buffer The buffer in which to write.
   */
  virtual common::Status ReadFileIntoBuffer(_In_z_ const ORTCHAR_T* file_path, FileOffsetType offset, size_t length,
                                            gsl::span<char> buffer) const = 0;

  using MappedMemoryPtr = std::unique_ptr<char[], OrtCallbackInvoker>;

  /**
   * Maps the content of the file into memory.
   * This is a copy-on-write mapping, so any changes are not written to the
   * actual file.
   * @param file_path The path to the file.
   * @param offset The file offset from which to start the mapping.
   * @param length The length in bytes of the mapping.
   * @param[out] mapped_memory A smart pointer to the mapped memory which
   *             unmaps the memory (unless release()'d) when destroyed.
   */
  virtual common::Status MapFileIntoMemory(_In_z_ const ORTCHAR_T* file_path, FileOffsetType offset, size_t length,
                                           MappedMemoryPtr& mapped_memory) const = 0;

#ifdef _WIN32
  /// \brief Returns true if the directory exists.
  virtual bool FolderExists(const std::wstring& path) const = 0;
  /// \brief Recursively creates the directory, if it doesn't exist.
  virtual common::Status CreateFolder(const std::wstring& path) const = 0;
  // Mainly for use with protobuf library
  virtual common::Status FileOpenRd(const std::wstring& path, /*out*/ int& fd) const = 0;
  // Mainly for use with protobuf library
  virtual common::Status FileOpenWr(const std::wstring& path, /*out*/ int& fd) const = 0;
#endif
  /// \brief Returns true if the directory exists.
  virtual bool FolderExists(const std::string& path) const = 0;
  /// \brief Recursively creates the directory, if it doesn't exist.
  virtual common::Status CreateFolder(const std::string& path) const = 0;
  // Recursively deletes the directory and its contents.
  // Note: This function is not thread safe!
  virtual common::Status DeleteFolder(const PathString& path) const = 0;
  // Mainly for use with protobuf library
  virtual common::Status FileOpenRd(const std::string& path, /*out*/ int& fd) const = 0;
  // Mainly for use with protobuf library
  virtual common::Status FileOpenWr(const std::string& path, /*out*/ int& fd) const = 0;
  // Mainly for use with protobuf library
  virtual common::Status FileClose(int fd) const = 0;

  /** Gets the canonical form of a file path (symlinks resolved). */
  virtual common::Status GetCanonicalPath(
      const PathString& path,
      PathString& canonical_path) const = 0;

  // This functions is always successful. It can't fail.
  virtual PIDType GetSelfPid() const = 0;

  // \brief Load a dynamic library.
  //
  // Pass "library_filename" to a platform-specific mechanism for dynamically
  // loading a library.  The rules for determining the exact location of the
  // library are platform-specific and are not documented here.
  //
  // On success, returns a handle to the library in "*handle" and returns
  // OK from the function.
  // Otherwise returns nullptr in "*handle" and an error status from the
  // function.
  virtual common::Status LoadDynamicLibrary(const std::string& library_filename, void** handle) const = 0;

  virtual common::Status UnloadDynamicLibrary(void* handle) const = 0;

  // \brief Gets the file path of the onnx runtime code
  //
  // Used to help load other shared libraries that live in the same folder as the core code, for example
  // The DNNL provider shared library. Without this path, the module won't be found on windows in all cases.
  virtual std::string GetRuntimePath() const { return ""; }

  // \brief Get a pointer to a symbol from a dynamic library.
  //
  // "handle" should be a pointer returned from a previous call to LoadDynamicLibrary.
  // On success, store a pointer to the located symbol in "*symbol" and return
  // OK from the function. Otherwise, returns nullptr in "*symbol" and an error
  // status from the function.
  virtual common::Status GetSymbolFromLibrary(void* handle, const std::string& symbol_name, void** symbol) const = 0;

  // \brief build the name of dynamic library.
  //
  // "name" should be name of the library.
  // "version" should be the version of the library or NULL
  // returns the name that LoadDynamicLibrary() can use
  virtual std::string FormatLibraryFileName(const std::string& name, const std::string& version) const = 0;

  // \brief returns a provider that will handle telemetry on the current platform
  virtual const Telemetry& GetTelemetryProvider() const = 0;

  // \brief returns a value for the queried variable name (var_name)
  //
  // Returns the corresponding value stored in the environment variable if available
  // Returns empty string if there is no such environment variable available
  virtual std::string GetEnvironmentVar(const std::string& var_name) const = 0;

 protected:
  Env();

 private:
  ORT_DISALLOW_COPY_ASSIGNMENT_AND_MOVE(Env);
  EnvTime* env_time_ = EnvTime::Default();
};

}  // namespace onnxruntime

max_stars_repo_name: dennyac/onnxruntime

max_issues_repo_name: dennyac/onnxruntime

max_forks_repo_name: dennyac/onnxruntime


text:
/*
 * Copyright (c) 2016-2021 lymastee, All rights reserved.
 * Contact: lymastee@hotmail.com
 *
 * This file is part of the gslib project.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#pragma once

#ifndef sysop_eb634adc_cca3_4f8f_853c_7852abe06d2d_h
#define sysop_eb634adc_cca3_4f8f_853c_7852abe06d2d_h

#include <gslib/type.h>
#include <gslib/std.h>
#include <ariel/type.h>
#include <ariel/image.h>

__ariel_begin__

enum unimask
{
    declare_mask(um_shift,      0),
    declare_mask(um_sshift,     1),
    declare_mask(um_control,    2),
    declare_mask(um_scontrol,   3),
    declare_mask(um_reserve,    4),
    declare_mask(um_alter,      6),
    declare_mask(um_salter,     7),
    declare_mask(um_lmouse,     8),
    declare_mask(um_rmouse,     9),
};

enum stylemask
{
    declare_mask(sm_hitable,    0),
    declare_mask(sm_visible,    1),
};

/*
 * part1. ascii codes
 * part2. reserved
 * part3. mouse keys
 * part4. joystick keys
 * part5. keyboard controls
 */
enum unikey
{
    uk_null = 0,        /* null */
    uk_soh,             /* start of heading */
    uk_stx,             /* start of text */
    uk_etx,             /* end of text */
    uk_eot,             /* end of transmission */
    uk_enq,             /* enquiry */
    uk_ack,             /* acknowledge */
    uk_bel,             /* bell */
    uk_bs,              /* backspace */
    uk_tab,             /* horizontal tab */
    uk_lf,              /* nl line feed, new line */
    uk_vt,              /* vertical tab */
    uk_ff,              /* np form feed, new page */
    uk_cr,              /* carriage return */
    uk_so,              /* shift out */
    uk_si,              /* shift in */
    uk_dle,             /* data link escape */
    uk_dc1,             /* device control 1 */
    uk_dc2,             /* device control 2 */
    uk_dc3,             /* device control 3 */
    uk_dc4,             /* device control 4 */
    uk_nak,             /* negative acknowledge */
    uk_syn,             /* synchronous idle */
    uk_etb,             /* end of trans. block */
    uk_can,             /* cancel */
    uk_em,              /* end of medium */
    uk_sub,             /* substitute */
    uk_esc,             /* escape */
    uk_fs,              /* file separator */
    uk_gs,              /* group separator */
    uk_rs,              /* record separator */
    uk_us,              /* unit separator */
    uk_sp,              /* space, blank */
                        /* ! - ~ */
    uk_del  = 0x7f,     /* delete */

    mk_left,
    mk_center,
    mk_right,

    vk_insert,          /* insert */
    vk_caps,            /* caps lock */
    vk_pscr,            /* print screen */
    vk_numlock,         /* number lock */
    vk_home,            /* home */
    vk_end,             /* end */
    vk_pageup,          /* page up */
    vk_pagedown,        /* page down */
    vk_left,            /* left arrow */
    vk_up,              /* up arrow */
    vk_right,           /* right arrow */
    vk_down,            /* down arrow */

    vk_shift,
    vk_control,
    vk_alter,

    vk_f1,              /* f1 - f12 */
    vk_f2,
    vk_f3,
    vk_f4,
    vk_f5,
    vk_f6,
    vk_f7,
    vk_f8,
    vk_f9,
    vk_f10,
    vk_f11,
    vk_f12,
};

enum cursor_type
{
    cur_arrow,
    cur_beam,
    cur_cross,
    cur_up_arrow,
    cur_size_nwse,
    cur_size_nesw,
    cur_size_we,
    cur_size_ns,
    cur_size_all,
    cur_hand,
    cur_help,
};

class system_driver;
typedef render_texture2d texture2d;

class __gs_novtable system_notify abstract
{
public:
    virtual void on_show(bool b) = 0;
    virtual void on_create(system_driver* ptr, const rect& rc) = 0;
    virtual void on_close() = 0;
    virtual void on_resize(const rect& rc) = 0;
    virtual void on_paint(const rect& rc) = 0;
    virtual void on_halt() = 0;
    virtual void on_resume() = 0;
    virtual bool on_mouse_down(uint um, unikey uk, const point& pt) = 0;
    virtual bool on_mouse_up(uint um, unikey uk, const point& pt) = 0;
    virtual bool on_mouse_move(uint um, const point& pt) = 0;
    virtual bool on_key_down(uint um, unikey uk) = 0;
    virtual bool on_key_up(uint um, unikey uk) = 0;
    virtual bool on_char(uint um, uint ch) = 0;
    virtual void on_timer(uint tid) = 0;
};

enum clipfmt
{
    cf_text,
    cf_bitmap,
};

class __gs_novtable clipboard_data abstract
{
public:
    virtual ~clipboard_data() {}
    virtual clipfmt get_format() const = 0;
    virtual void* get_ptr() = 0;
    virtual int get_size() const = 0;
    template<class _tdata>
    _tdata* get_data() { return (_tdata*)get_ptr(); }
};

class clipboard_list:
    public list<clipboard_data*>
{
public:
    ~clipboard_list()
    {
        for(auto* p : *this) {
            assert(p);
            delete p;
        }
        clear();
    }
};

struct clipboard_text:
    public clipboard_data, public string
{
    virtual clipfmt get_format() const { return cf_text; }
    virtual void* get_ptr() { return (void*)static_cast<string*>(this); }
    virtual int get_size() const { return string::length(); }
};

struct clipboard_bitmap:
    public clipboard_data, public image
{
    virtual clipfmt get_format() const { return cf_bitmap; }
    virtual void* get_ptr() { return (void*)static_cast<image*>(this); }
    virtual int get_size() const { return -1; }
};

struct system_context
{
    enum
    {
        sct_notify      = 0x01,
        sct_painter     = 0x02,
        sct_rectangle   = 0x04,
        sct_hwnd        = 0x08,
        sct_hinst       = 0x10,
        sct_everything  = 0xffffffff,
    };

    uint                mask;
    system_notify*      notify;
    void*               painter;
    rect                rectangle;
    uint                hwnd;
    uint                hinst;
};

class __gs_novtable system_driver abstract
{
public:
    virtual ~system_driver() {}
    virtual void initialize(const system_context& ctx) = 0;
    virtual void setup() = 0;
    virtual void close() = 0;
    virtual void set_timer(uint tid, int t) = 0;
    virtual void kill_timer(uint tid) = 0;
    virtual void update() = 0;
    virtual void emit(int msgid, void* msg, int size) = 0;
    virtual void set_ime(point pt, const font& ft) = 0;
    virtual void set_cursor(cursor_type curty) = 0;
    //virtual void set_clipboard(const gchar* fmt, const void* ptr, int size) = 0;
    //virtual int get_clipboard(const gchar* fmt, const void*& ptr) = 0;
    //virtual int get_clipboard(clipboard_list& cl, int c) = 0;
};

class __gs_novtable fontsys abstract
{
public:
    virtual ~fontsys() {}
    virtual void initialize() = 0;
    virtual void set_font(const font& f) = 0;
    virtual bool query_size(const gchar* str, int& w, int& h, int len = -1) = 0;
    virtual bool create_text_image(image& img, const gchar* str, int x, int y, const color& cr, int len = -1) = 0;
    virtual bool create_text_texture(texture2d** tex, const gchar* str, int margin, const color& cr, int len = -1) = 0;
    virtual void draw(image& img, const gchar* str, int x, int y, const color& cr, int len = -1) = 0;
};

__ariel_end__

#endif

max_stars_repo_name: lymastee/gslib

max_issues_repo_name: lymastee/gslib

max_forks_repo_name: lymastee/gslib