| {"text": "#include <stdio.h>\n#include <stdlib.h>\n#include <math.h>\n#include <gsl/gsl_sf_gamma.h>\n#ifndef M_PI\n#define M_PI 3.14159265358979323846\n#endif\n\n/* very simple approximation */\ndouble st_gamma(double x)\n{\n return sqrt(2.0*M_PI/x)*pow(x/M_E, x);\n}\n\n#define A 12\ndouble sp_gamma(double z)\n{\n const int a = A;\n static double c_space[A];\n static double *c = NULL;\n int k;\n double accm;\n\n if ( c == NULL ) {\n double k1_factrl = 1.0; /* (k - 1)!*(-1)^k with 0!==1*/\n c = c_space;\n c[0] = sqrt(2.0*M_PI);\n for(k=1; k < a; k++) {\n c[k] = exp(a-k) * pow(a-k, k-0.5) / k1_factrl;\n\t k1_factrl *= -k;\n }\n }\n accm = c[0];\n for(k=1; k < a; k++) {\n accm += c[k] / ( z + k );\n }\n accm *= exp(-(z+a)) * pow(z+a, z+0.5); /* Gamma(z+1) */\n return accm/z;\n}\n\nint main()\n{\n double x;\n\n\n printf(\"%15s%15s%15s%15s\\n\", \"Stirling\", \"Spouge\", \"GSL\", \"libm\");\n for(x=1.0; x <= 10.0; x+=1.0) {\n printf(\"%15.8lf%15.8lf%15.8lf%15.8lf\\n\", st_gamma(x/3.0), sp_gamma(x/3.0),\n\t gsl_sf_gamma(x/3.0), tgamma(x/3.0));\n }\n return 0;\n}\n", "meta": {"hexsha": "81dcdc28a9966ca55713c786507f286cbddad6af", "size": 1043, "ext": "c", "lang": "C", "max_stars_repo_path": "lang/C/gamma-function.c", "max_stars_repo_name": "ethansaxenian/RosettaDecode", "max_stars_repo_head_hexsha": "8ea1a42a5f792280b50193ad47545d14ee371fb7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2.0, "max_stars_repo_stars_event_min_datetime": "2017-06-10T14:21:53.000Z", "max_stars_repo_stars_event_max_datetime": "2017-06-26T18:52:29.000Z", "max_issues_repo_path": "lang/C/gamma-function.c", "max_issues_repo_name": "ethansaxenian/RosettaDecode", "max_issues_repo_head_hexsha": "8ea1a42a5f792280b50193ad47545d14ee371fb7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lang/C/gamma-function.c", "max_forks_repo_name": "ethansaxenian/RosettaDecode", "max_forks_repo_head_hexsha": "8ea1a42a5f792280b50193ad47545d14ee371fb7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1.0, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 19.679245283, "max_line_length": 78, "alphanum_fraction": 0.5445829338, "num_tokens": 427, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9525741227833249, "lm_q2_score": 0.837619959279793, "lm_q1q2_score": 0.7978950979367532}} |
| {"text": "\n#include <math.h>\n#include <cblas.h>\n\nvoid matmult_mnk(int M, int N, int K, double **A, double **B, double **C) {\n\tfor (int l = 0; l < M*N; l++) {\n\t\tC[0][l] = 0;\n\t}\n \tfor (int m = 0; m < M; m++) {\n \t\tfor (int n = 0; n < N; n++) {\n\t\t\tfor (int k = 0; k < K; k++) {\n\t\t\t\tC[m][n] += A[m][k] * B[k][n];\n\t\t}\n \t}\t\n }\n}\n\nvoid matmult_mkn(int M, int N, int K, double **A, double **B, double **C) {\n\tfor (int l = 0; l < M*N; l++) {\n\t\tC[0][l] = 0;\n\t}\n for (int m = 0; m < M; m++) {\n \tfor (int k = 0; k < K; k++) {\n\t\t\tfor (int n = 0; n < N; n++) {\n\t\t\t\tC[m][n] += A[m][k] * B[k][n];\n\t\t\t}\n \t}\t\n }\n}\n\nvoid matmult_nmk(int M, int N, int K, double **A, double **B, double **C) {\n\tfor (int l = 0; l < M*N; l++) {\n\t\tC[0][l] = 0;\n\t}\n for (int n = 0; n < N; n++) {\n \tfor (int m = 0; m < M; m++) {\n\t\t\tfor (int k = 0; k < K; k++) {\n\t\t\t\tC[m][n] += A[m][k] * B[k][n];\n\t\t\t}\n \t}\t\n }\n}\n\nvoid matmult_nkm(int M, int N, int K, double **A, double **B, double **C) {\n\tfor (int l = 0; l < M*N; l++) {\n\t\tC[0][l] = 0;\n\t}\n for (int n = 0; n < N; n++) {\n \tfor (int k = 0; k < K; k++) {\n\t\t\tfor (int m = 0; m < M; m++) {\n\t\t\t\tC[m][n] += A[m][k] * B[k][n];\n\t\t\t}\n \t}\t\n }\n}\n\nvoid matmult_kmn(int M, int N, int K, double **A, double **B, double **C) {\n\tfor (int l = 0; l < M*N; l++) {\n\t\tC[0][l] = 0;\n\t}\n for (int k = 0; k < K; k++) {\n \tfor (int m = 0; m < M; m++) {\n\t\t\tfor (int n = 0; n < N; n++) {\n\t\t\t\tC[m][n] += A[m][k] * B[k][n];\n\t\t\t}\n \t}\t\n }\n}\n\nvoid matmult_knm(int M, int N, int K, double **A, double **B, double **C) {\n\tfor (int l = 0; l < M*N; l++) {\n\t\tC[0][l] = 0;\n\t}\n for (int k = 0; k < K; k++) {\n \tfor (int n = 0; n < N; n++) {\n\t\t\tfor (int m = 0; m < M; m++) {\n\t\t\t\tC[m][n] += A[m][k] * B[k][n];\n\t\t\t}\n \t}\t\n }\n}\n\n\nvoid matmult_nat(int M, int N, int K, double **A, double **B, double **C) {\n\tfor (int m = 0; m < M; m++) {\n\t\tfor (int n = 0; n < N; n++) {\n\t\t\tC[m][n] = 0;\n\t\t\tfor (int k = 0; k < K; k++) {\n\t\t\t\tC[m][n] += A[m][k] * B[k][n];\n\t\t\t}\n \t}\t\n }\n}\n\nvoid matmult_lib(int M, int N, int K, double **A, double **B, double **C) {\n\tint layout, TRANSA, TRANSB, LDA, LDB, LDC;\n\tdouble alpha, beta;\n\n layout = 101; // rowmajor\n\tTRANSA = 111; // A is not transposed\n\tTRANSB = 111; // B is not transposed\n\n\n\tLDA = fmax(1,K); // leading dimension of A\n\tLDB = fmax(1,N); // leading dimension of B\n\tLDC = fmax(1,N); // leading dimension of C\n\n\talpha = 1.0; // no scaling\n\tbeta = 0.0; //\n\n\tcblas_dgemm(layout, TRANSA, TRANSB, M, N, K, alpha, *A, LDA, *B, LDB, beta, *C, LDC); \n}\n\nvoid matmult_blk(int M, int N, int K, double **A, double **B, double **C, int bs) \n{\n\t// MKN\n\n\tbs = fmax(1, fmin(bs, K));\n\n\tfor (int i = 0; i < M*N; i++)\n\t\tC[0][i] = 0.0;\n\n\tfor (int m0 = 0; m0 < M; m0 += bs)\n\t{\n\t\tfor (int k0 = 0; k0 < K; k0 += bs)\n\t\t{\n\t\t\tfor (int n0 = 0; n0 < N; n0 += bs)\n\t\t\t{\n\t\t\t\tfor (int m = m0; m < fmin(m0 + bs, M); m++)\n\t\t\t\t{\n\t\t\t\t\tfor (int k = k0; k < fmin(k0 + bs, K); k++)\n\t\t\t\t\t{\n\t\t\t\t\t\tfor (int n = n0; n < fmin(n0 + bs, N); n++)\n\t\t\t\t\t\t\tC[m][n] += A[m][k] * B[k][n];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n", "meta": {"hexsha": "07955c9e0d7df07054cff0d20eb9f89c20fcbb1b", "size": 3036, "ext": "c", "lang": "C", "max_stars_repo_path": "projects/assign_1/func.c", "max_stars_repo_name": "anderslaunerbaek/HPC", "max_stars_repo_head_hexsha": "c63201022e2715112bc38dcc2a53316ea1e2b055", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1.0, "max_stars_repo_stars_event_min_datetime": "2022-01-06T08:58:43.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-06T08:58:43.000Z", "max_issues_repo_path": "projects/assign_1/func.c", "max_issues_repo_name": "anderslaunerbaek/HPC", "max_issues_repo_head_hexsha": "c63201022e2715112bc38dcc2a53316ea1e2b055", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "projects/assign_1/func.c", "max_forks_repo_name": "anderslaunerbaek/HPC", "max_forks_repo_head_hexsha": "c63201022e2715112bc38dcc2a53316ea1e2b055", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3.0, "max_forks_repo_forks_event_min_datetime": "2019-01-22T10:34:10.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-18T16:42:40.000Z", "avg_line_length": 21.5319148936, "max_line_length": 90, "alphanum_fraction": 0.4209486166, "num_tokens": 1358, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404038127071, "lm_q2_score": 0.8479677526147223, "lm_q1q2_score": 0.7881354904103812}} |
| {"text": "//STARTWHOLE\nstatic char help[] = \"Solve a tridiagonal system of arbitrary size.\\n\"\n\"Option prefix = tri_.\\n\";\n\n#include <petsc.h>\n\nint main(int argc,char **args) {\n PetscErrorCode ierr;\n Vec x, b, xexact;\n Mat A;\n KSP ksp;\n int m = 4, i, Istart, Iend, j[3];\n double v[3], xval, errnorm;\n\n PetscInitialize(&argc,&args,NULL,help);\n\n ierr = PetscOptionsBegin(PETSC_COMM_WORLD,\"tri_\",\"options for tri\",\"\"); CHKERRQ(ierr);\n ierr = PetscOptionsInt(\"-m\",\"dimension of linear system\",\"tri.c\",m,&m,NULL); CHKERRQ(ierr);\n ierr = PetscOptionsEnd(); CHKERRQ(ierr);\n\n ierr = VecCreate(PETSC_COMM_WORLD,&x); CHKERRQ(ierr);\n ierr = VecSetSizes(x,PETSC_DECIDE,m); CHKERRQ(ierr);\n ierr = VecSetFromOptions(x); CHKERRQ(ierr);\n ierr = VecDuplicate(x,&b); CHKERRQ(ierr);\n ierr = VecDuplicate(x,&xexact); CHKERRQ(ierr);\n\n ierr = MatCreate(PETSC_COMM_WORLD,&A); CHKERRQ(ierr);\n ierr = MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,m,m); CHKERRQ(ierr);\n ierr = MatSetOptionsPrefix(A,\"a_\"); CHKERRQ(ierr);\n ierr = MatSetFromOptions(A); CHKERRQ(ierr);\n ierr = MatSetUp(A); CHKERRQ(ierr);\n ierr = MatGetOwnershipRange(A,&Istart,&Iend); CHKERRQ(ierr);\n for (i=Istart; i<Iend; i++) {\n if (i == 0) {\n v[0] = 3.0; v[1] = -1.0;\n j[0] = 0; j[1] = 1;\n ierr = MatSetValues(A,1,&i,2,j,v,INSERT_VALUES); CHKERRQ(ierr);\n } else {\n v[0] = -1.0; v[1] = 3.0; v[2] = -1.0;\n j[0] = i-1; j[1] = i; j[2] = i+1;\n if (i == m-1) {\n ierr = MatSetValues(A,1,&i,2,j,v,INSERT_VALUES); CHKERRQ(ierr);\n } else {\n ierr = MatSetValues(A,1,&i,3,j,v,INSERT_VALUES); CHKERRQ(ierr);\n }\n }\n xval = exp(cos(i));\n ierr = VecSetValues(xexact,1,&i,&xval,INSERT_VALUES); CHKERRQ(ierr);\n }\n ierr = MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY); CHKERRQ(ierr);\n ierr = MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY); CHKERRQ(ierr);\n ierr = VecAssemblyBegin(xexact); CHKERRQ(ierr);\n ierr = VecAssemblyEnd(xexact); CHKERRQ(ierr);\n ierr = MatMult(A,xexact,b); CHKERRQ(ierr);\n\n ierr = KSPCreate(PETSC_COMM_WORLD,&ksp); CHKERRQ(ierr);\n ierr = KSPSetOperators(ksp,A,A); CHKERRQ(ierr);\n ierr = KSPSetFromOptions(ksp); CHKERRQ(ierr);\n ierr = KSPSolve(ksp,b,x); CHKERRQ(ierr);\n\n ierr = VecAXPY(x,-1.0,xexact); CHKERRQ(ierr);\n ierr = VecNorm(x,NORM_2,&errnorm); CHKERRQ(ierr);\n ierr = PetscPrintf(PETSC_COMM_WORLD,\n \"error for m = %d system is |x-xexact|_2 = %.1e\\n\",m,errnorm); CHKERRQ(ierr);\n\n KSPDestroy(&ksp); MatDestroy(&A);\n VecDestroy(&x); VecDestroy(&b); VecDestroy(&xexact);\n return PetscFinalize();\n}\n//ENDWHOLE\n", "meta": {"hexsha": "52d3afa88cd5ce62c1c745cf6439421941375a89", "size": 2719, "ext": "c", "lang": "C", "max_stars_repo_path": "c/ch2/tri.c", "max_stars_repo_name": "mapengfei-nwpu/p4pdes", "max_stars_repo_head_hexsha": "706411c1e745d7f825f336dcab3a62852538eaa4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "c/ch2/tri.c", "max_issues_repo_name": "mapengfei-nwpu/p4pdes", "max_issues_repo_head_hexsha": "706411c1e745d7f825f336dcab3a62852538eaa4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "c/ch2/tri.c", "max_forks_repo_name": "mapengfei-nwpu/p4pdes", "max_forks_repo_head_hexsha": "706411c1e745d7f825f336dcab3a62852538eaa4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.2957746479, "max_line_length": 95, "alphanum_fraction": 0.6031629275, "num_tokens": 868, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297861178929, "lm_q2_score": 0.867035771827307, "lm_q1q2_score": 0.780791538160207}} |
| {"text": "//============================================================================\n// Name : main.c\n// Author : Cesare De Cal\n// Version :\n// Copyright : Cesare De Cal\n// Description : Exercise 7 - System of Linear Equations\n//============================================================================\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <gsl/gsl_vector.h>\n#include <gsl/gsl_matrix.h>\n#include <gsl/gsl_linalg.h>\n\n// Useful: https://gist.github.com/bjd2385/7f4685e703f7437e513608f41c65bbd7 (LU decomposition)\n// Useful: https://github.com/rwinlib/gsl/blob/master/include/gsl/gsl_linalg.h#L173 (GEPP)\n\ngsl_matrix *createMatrix(int size) {\n gsl_matrix *matrix = gsl_matrix_alloc(size, size);\n gsl_matrix_set_zero(matrix);\n\n for (int i = 1; i <= size; i++) {\n for (int j = 1; j <= size; j++) {\n // Fill diagonal\n if (i == j) {\n if ((i+1) % 3 == 0) {\n double value = (2.0*(i+1))/3;\n gsl_matrix_set(matrix, i-1, j-1, value);\n } else {\n gsl_matrix_set(matrix, i-1, j-1, 1);\n }\n // Fill adjacent lower diagonal\n } else if (i == j+1) {\n gsl_matrix_set(matrix, i-1, j-1, 1);\n // Fill adjacent upper diagonal\n } else if (i+1 == j) {\n gsl_matrix_set(matrix, i-1, j-1, -1);\n }\n }\n }\n return matrix;\n}\n\n// Helper methods\n\nvoid printVectorContents(gsl_vector *vector) {\n for (int i = 0; i < vector->size; i++) {\n printf(\"%.9e\\\\\\\\\\n\", gsl_vector_get(vector, i));\n }\n printf(\"\\n\");\n}\n\nvoid printMatrixContents(gsl_matrix *matrix) {\n for (int i = 0; i < matrix->size1; ++i) {\n for (int j = 0; j < matrix->size2; ++j) {\n printf(\"%.9e \", gsl_matrix_get(matrix, i, j));\n\n if (j == matrix->size2-1) {\n printf(\"\\\\\\\\\");\n } else {\n printf(\"& \");\n }\n }\n printf(\"\\n\");\n }\n printf(\"\\n\");\n}\n\nvoid computeForOrder(int size, int shouldPrintVerboseOutput) {\n gsl_matrix *matrixA = createMatrix(size);\n if (shouldPrintVerboseOutput) {\n printf(\"Creating matrix A:\\n\");\n printMatrixContents(matrixA);\n }\n\n // Right-hand side vector y\n gsl_vector *bVector = gsl_vector_alloc(matrixA->size2);\n gsl_vector_set_zero(bVector);\n // Fill element at index 0 with 1\n gsl_vector_set(bVector, 0, 1);\n\n if (shouldPrintVerboseOutput) {\n printf(\"Creating vector y (b):\\n\");\n printVectorContents(bVector);\n }\n\n // Solve system using LU decomposition\n gsl_matrix *luMatrix = gsl_matrix_alloc(matrixA->size1, matrixA->size2);\n gsl_permutation *permutation = gsl_permutation_alloc(matrixA->size1);\n int signum; // Sign of the permutation\n // Copy A over newly created matrixA\n gsl_matrix_memcpy(luMatrix, matrixA);\n // Compute LU decomposition\n gsl_linalg_LU_decomp(luMatrix, permutation, &signum);\n\n if (shouldPrintVerboseOutput) {\n printf(\"LU decomposition of A:\\n\");\n printMatrixContents(luMatrix);\n }\n\n // Result vector v\n gsl_vector *xVector = gsl_vector_alloc(matrixA->size2);\n gsl_vector_set_zero(xVector);\n\n gsl_linalg_LU_solve(luMatrix, permutation, bVector, xVector);\n\n if (shouldPrintVerboseOutput) {\n printf(\"Solutions x vector:\\n\");\n printVectorContents(xVector);\n }\n\n // Calculate condition number\n // There is no function in GSL to directly compute this number\n // the condition number is given by taking the absolute value of the ratio of the largest singular value and the smallest singular value\n // cond(A) = abs( largest_sing_val / smallest_sing_val )\n gsl_matrix *matrixV = gsl_matrix_alloc(matrixA->size1, matrixA->size2);\n gsl_vector *vectorS = gsl_vector_alloc(matrixA->size1);\n gsl_vector *vectorWorkspace = gsl_vector_alloc(matrixA->size1);\n gsl_linalg_SV_decomp(matrixA, matrixV, vectorS, vectorWorkspace);\n\n if (shouldPrintVerboseOutput) {\n printf(\"Singular diagonal vector:\\n\");\n printVectorContents(vectorS);\n }\n\n double minSingularValue, maxSingularValue;\n gsl_vector_minmax(vectorS, &minSingularValue, &maxSingularValue);\n if (shouldPrintVerboseOutput) {\n printf(\"Max: %.9e, min: %.9e\\n\", maxSingularValue, minSingularValue);\n }\n\n double conditionNumber = fabs(maxSingularValue/minSingularValue);\n double x1 = gsl_vector_get(xVector, 0);\n double error = (M_E - 2) - x1;\n\n printf(\"%d & %.9e & %.9e & %.9e \\\\\\\\\", size, x1, error, conditionNumber);\n\n // Free memory space\n gsl_matrix_free(matrixA);\n gsl_vector_free(bVector);\n gsl_matrix_free(luMatrix);\n gsl_permutation_free(permutation);\n gsl_vector_free(xVector);\n gsl_matrix_free(matrixV);\n gsl_vector_free(vectorS);\n gsl_vector_free(vectorWorkspace);\n}\n\nint main() {\n printf(\"This program is going to generate a LaTeX friendly output to be used in the report table.\\n\");\n printf(\"------------------------------\\n\");\n printf(\"n, x1, error, condition number\\n\");\n for (int n = 1; n <= 50; n++) {\n computeForOrder(n, 0);\n printf(\"\\n\");\n }\n printf(\"------------------------------\\n\");\n return 0;\n}\n\n", "meta": {"hexsha": "25a2c6f22761b9df3833e63da1bba0c882ffd997", "size": 4919, "ext": "c", "lang": "C", "max_stars_repo_path": "Linear Systems/CesareDeCal_Exercise7/exercise7/main.c", "max_stars_repo_name": "csr/MATLAB-Scientific-Programming", "max_stars_repo_head_hexsha": "ac2d64ea235d7bee9cf0de8bbe42d06a3986bd5a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Linear Systems/CesareDeCal_Exercise7/exercise7/main.c", "max_issues_repo_name": "csr/MATLAB-Scientific-Programming", "max_issues_repo_head_hexsha": "ac2d64ea235d7bee9cf0de8bbe42d06a3986bd5a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Linear Systems/CesareDeCal_Exercise7/exercise7/main.c", "max_forks_repo_name": "csr/MATLAB-Scientific-Programming", "max_forks_repo_head_hexsha": "ac2d64ea235d7bee9cf0de8bbe42d06a3986bd5a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.5527950311, "max_line_length": 138, "alphanum_fraction": 0.6348851393, "num_tokens": 1358, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797003640645, "lm_q2_score": 0.8519528000888386, "lm_q1q2_score": 0.7762820971092736}} |
| {"text": "#include <stdio.h>\n#include <sys/time.h>\n#include <gsl/gsl_rng.h>\n#include <gsl/gsl_randist.h>\n\n#define NUMBER_OF_ELEMENTS 1\n#define MEAN 0\n#define STANDARD_DEVIATION 1\n\nint main (int argc, char *argv[])\n{\n int number_of_elements;\n \n if (argc == 1) {\n number_of_elements = NUMBER_OF_ELEMENTS;\n } else if (argc == 2) {\n number_of_elements = atoi(argv[1]);\n } else {\n fprintf(stderr, \"%s\\n\", \"Wrong number of arguments.\");\n fprintf(stderr, \"%s\\n\", \"Use: ./normal_numbers number_of_elements\");\n exit(EXIT_FAILURE);\n }\n\n double *numbers = malloc (number_of_elements * sizeof(double));\n\n double mean = MEAN;\n double standard_deviation = STANDARD_DEVIATION;\n \n // declare the necessary random number generator variables\n const gsl_rng_type *T;\n gsl_rng *r;\n\n // set the default values for the random number generator variables\n gsl_rng_env_setup();\n\n // create a seed based on time\n struct timeval tv;\n gettimeofday(&tv,0);\n unsigned long seed = tv.tv_sec + tv.tv_usec;\n\n // setup the generator using the seed just created\n T = gsl_rng_default;\n r = gsl_rng_alloc (T);\n gsl_rng_set(r, seed);\n\n // generate number_of_elements normal random numbers\n for (int i = 0; i < number_of_elements; i++) {\n numbers[i] = mean + gsl_ran_gaussian (r, standard_deviation);\n }\n\n // print numbers\n if(number_of_elements < 10) {\n for (int i = 0; i < number_of_elements; i++) {\n printf (\" %f\", numbers[i]);\n }\n printf(\"\\n\");\n } else {\n printf(\"Done.\\n\");\n }\n\n // free memory \n gsl_rng_free (r);\n free(numbers);\n \n return 0;\n}\n", "meta": {"hexsha": "0f69e0694792514b7561aaf7b092a4321bea431a", "size": 1920, "ext": "c", "lang": "C", "max_stars_repo_path": "C/normal_numbers.c", "max_stars_repo_name": "sernamar/random-numbers", "max_stars_repo_head_hexsha": "9117a59b246ced3d82803cfd7b82b05f8a456d97", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "C/normal_numbers.c", "max_issues_repo_name": "sernamar/random-numbers", "max_issues_repo_head_hexsha": "9117a59b246ced3d82803cfd7b82b05f8a456d97", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "C/normal_numbers.c", "max_forks_repo_name": "sernamar/random-numbers", "max_forks_repo_head_hexsha": "9117a59b246ced3d82803cfd7b82b05f8a456d97", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.6567164179, "max_line_length": 84, "alphanum_fraction": 0.54375, "num_tokens": 430, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026573249612, "lm_q2_score": 0.84594244507642, "lm_q1q2_score": 0.7759852528125751}} |
| {"text": "#include <stdio.h>\n#include <gsl/gsl_min.h>\n#include <gsl/gsl_multimin.h>\n/* Paraboloid with a minimum at f(dp[0],dp[1]) = 30.0 */\n\ndouble\nmy_f (const gsl_vector * v, void *params)\n{\n double x, y;\n double *dp = (double *) params;\n\n x = gsl_vector_get (v, 0);\n y = gsl_vector_get (v, 1);\n\n return 10.0 * (x - dp[0]) * (x - dp[0]) +\n 20.0 * (y - dp[1]) * (y - dp[1]) + 30.0;\n}\n\n/* The gradient of f, df = (df/dx, df/dy). */\nvoid\nmy_df (const gsl_vector * v, void *params, gsl_vector * df)\n{\n double x, y;\n double *dp = (double *) params;\n\n x = gsl_vector_get (v, 0);\n y = gsl_vector_get (v, 1);\n\n gsl_vector_set (df, 0, 20.0 * (x - dp[0]));\n gsl_vector_set (df, 1, 40.0 * (y - dp[1]));\n}\n\n/* Now both f and df together. */\nvoid\nmy_fdf (const gsl_vector * x, void *params, double *f, gsl_vector * df)\n{\n *f = my_f (x, params);\n my_df (x, params, df);\n}\n\nint\nmain (void)\n{\n size_t iter = 0;\n int status;\n\n const gsl_multimin_fdfminimizer_type *T;\n gsl_multimin_fdfminimizer *s;\n\n /* Position of the minimum (1,2). */\n double par[2] = { 1.0, 2.0 };\n\n gsl_vector *x;\n gsl_multimin_function_fdf my_func;\n\n my_func.f = &my_f;\n my_func.df = &my_df;\n my_func.fdf = &my_fdf;\n my_func.n = 2;\n my_func.params = ∥\n\n /* Starting point, x = (5,7) */\n\n x = gsl_vector_alloc (2);\n gsl_vector_set (x, 0, 5.0);\n gsl_vector_set (x, 1, 7.0);\n\n T = gsl_multimin_fdfminimizer_conjugate_fr;\n s = gsl_multimin_fdfminimizer_alloc (T, 2);\n\n gsl_multimin_fdfminimizer_set (s, &my_func, x, 0.01, 1e-4);\n\n do\n {\n iter++;\n status = gsl_multimin_fdfminimizer_iterate (s);\n\n if (status)\n break;\n\n status = gsl_multimin_test_gradient (s->gradient, 1e-3);\n\n if (status == GSL_SUCCESS)\n printf (\"Minimum found at:\\n\");\n\n printf (\"%5d %.5f %.5f %10.5f\\n\", iter,\n gsl_vector_get (s->x, 0), gsl_vector_get (s->x, 1), s->f);\n\n }\n while (status == GSL_CONTINUE && iter < 100);\n\n gsl_multimin_fdfminimizer_free (s);\n gsl_vector_free (x);\n\n return 0;\n}\n", "meta": {"hexsha": "12489dc48c61f0ffb722aba6b2a905f188064452", "size": 2017, "ext": "c", "lang": "C", "max_stars_repo_path": "Chimera/3rd_Party/GSL_MSVC/multimin/demo.c", "max_stars_repo_name": "zzpwahaha/Chimera-Control-Trim", "max_stars_repo_head_hexsha": "df1bbf6bea0b87b8c7c9a99dce213fdc249118f2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1.0, "max_stars_repo_stars_event_min_datetime": "2021-06-14T11:51:37.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-14T11:51:37.000Z", "max_issues_repo_path": "Chimera/3rd_Party/GSL_MSVC/multimin/demo.c", "max_issues_repo_name": "zzpwahaha/Chimera-Control-Trim", "max_issues_repo_head_hexsha": "df1bbf6bea0b87b8c7c9a99dce213fdc249118f2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Chimera/3rd_Party/GSL_MSVC/multimin/demo.c", "max_forks_repo_name": "zzpwahaha/Chimera-Control-Trim", "max_forks_repo_head_hexsha": "df1bbf6bea0b87b8c7c9a99dce213fdc249118f2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2.0, "max_forks_repo_forks_event_min_datetime": "2021-01-20T16:22:57.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-14T12:31:02.000Z", "avg_line_length": 20.793814433, "max_line_length": 72, "alphanum_fraction": 0.5999008428, "num_tokens": 736, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418199787564, "lm_q2_score": 0.8376199592797929, "lm_q1q2_score": 0.7740796336193597}} |
| {"text": "//\n// Created by robin on 2018/9/1.\n// Copyright (c) 2018 Robin. All rights reserved.\n//\n\n#pragma once\n\n#include <gsl/gsl>\n\nnamespace satz {\n\ntemplate <typename P>\nconst P zero = P::ZERO;\n\ntemplate <typename P>\nconst P one = P::ONE;\n\ntemplate <typename P>\nconst P X = P::X;\n\n/**\n * @brief Compute $b^e$.\n * @param b base\n * @param e exponent\n * @param acc\n * @pre $e \\ge 0, acc = 1$.\n */\ntemplate <typename P, typename N>\nP pow (P b, N e, P acc = one<P>) {\n Expects(e >= 0);\n\n while (e) {\n if (e % 2) acc = acc * b;\n b = b * b;\n e = e / 2;\n }\n\n return acc;\n}\n\n/**\n * @brief Compute $(b^e) mod m$.\n * @param b base\n * @param e exponent\n * @param m modulus\n * @param acc\n * @pre $e >= 0, acc = 1$\n */\ntemplate <typename P, typename N>\nP mod_pow (P b, N e, const P& m, P acc = one<P>) {\n Expects(e >= 0);\n\n while (e) {\n if (e % 2) acc = (acc * b) % m;\n b = (b * b) % m;\n e = e / 2;\n }\n\n return acc;\n}\n\ntemplate <typename P>\nP gcd (P a, P b) {\n while (b) {\n std::tie(a, b) = std::make_pair(b, a % b);\n }\n return a;\n}\n\n/**\n * @brief Compute $(x^{2^p} - x) mod m$.\n * @param p\n * @param m modulus\n */\ntemplate <typename P, typename N>\nP reduce_exponent (N p, const P& m) {\n auto r = X<P>;\n for (; p > 0; --p) r = (r * r) % m;\n return (r - X<P>) % m;\n}\n\n/**\n * @brief Given a polynomial p over GF(2) return whether it is irreducible\n * with Ben-Or's algorithm.\n * @param p polynomial over GF(2)\n * @return true if p is irreducible.\n * @pre p is non-constant.\n */\ntemplate <typename P>\nbool ben_or_test (const P& p) {\n Expects(p.degree() > 0);\n\n auto d = p.degree();\n for (decltype(d) i = 1; i <= d / 2; ++i) {\n auto b = reduce_exponent(i, p);\n auto g = gcd(p, b);\n if (g != one<P>) return false;\n }\n return true;\n}\n\n/**\n * @brief Given a polynomial p over GF(2), return whether it is irreducible.\n * @param p polynomial over GF(2)\n * @return true if p is irreducible.\n */\ntemplate <typename P>\nbool is_irreducible (const P& p) {\n if (p.degree() > 0) return ben_or_test(p);\n else return false;\n}\n\n}\n\n", "meta": {"hexsha": "03fbc522b69ab5f05176ff15e330f47d46e09271", "size": 2058, "ext": "h", "lang": "C", "max_stars_repo_path": "src/arithmetic.h", "max_stars_repo_name": "lie-yan/rabin-fingerprint", "max_stars_repo_head_hexsha": "834d2d52e4c5967fe4b7aa6026742cc82c6bc031", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/arithmetic.h", "max_issues_repo_name": "lie-yan/rabin-fingerprint", "max_issues_repo_head_hexsha": "834d2d52e4c5967fe4b7aa6026742cc82c6bc031", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/arithmetic.h", "max_forks_repo_name": "lie-yan/rabin-fingerprint", "max_forks_repo_head_hexsha": "834d2d52e4c5967fe4b7aa6026742cc82c6bc031", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1.0, "max_forks_repo_forks_event_min_datetime": "2021-03-26T11:41:15.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-26T11:41:15.000Z", "avg_line_length": 17.8956521739, "max_line_length": 76, "alphanum_fraction": 0.5563654033, "num_tokens": 715, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896780646393, "lm_q2_score": 0.8376199673867852, "lm_q1q2_score": 0.7712718201105916}} |
| {"text": "/* File: set_cosmo_dist.c */\n/*\n This file is a part of the Corrfunc package\n Copyright (C) 2015-- Manodeep Sinha (manodeep@gmail.com)\n License: MIT LICENSE. See LICENSE file under the top-level\n directory at https://github.com/manodeep/Corrfunc/\n*/\n\n/* function set_cosmo_dist (modelled after cosmodist.c)\n\n --- Computes the comoving distance as a function of redshift for\n a given cosmological model.\n*/\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <math.h>\n#include <gsl/gsl_integration.h>\n\n#include \"set_cosmo_dist.h\"\n#include \"cosmology_params.h\"\n\n#define SQR(x) ((x)*(x))\n#define CUBE(x) ((x)*(x)*(x))\n#define epsilon 1e-10\n\nint set_cosmo_dist(const double zmax,const int max_size,double *zc,double *dc,const int lasdamas_cosmology)\n{\n /* First, initialize cosmology*/\n int status = init_cosmology(lasdamas_cosmology);\n if(status != EXIT_SUCCESS) {\n return -1;\n }\n\n int i = 0;\n double Omegak;\n double smallh = 1.0;//Andreas pointed out that I don't need the real value of LITTLE_H\n Omegak = 1.0 - OMEGA_M - OMEGA_L;\n const double Dh = SPEED_OF_LIGHT*0.01/smallh ;// c/(100) -> in units of little h^-1 Mpc\n\n const double Deltaz = 1.0/max_size;\n const double dz = 1e-2*Deltaz;\n\n double Eint = 0.0;\n double E2 = 1.0 ;\n double z2 = Deltaz ;\n for(double z=2.0*dz;z<zmax;z+=2.0*dz) {\n double E0 = E2 ;\n\n double E1 = 1.0/sqrt(OMEGA_M * CUBE(1+z-dz) + Omegak *(1+z-dz) + OMEGA_L);\n E2 = 1.0/sqrt(OMEGA_M * CUBE(1+z) + Omegak *(1+z) + OMEGA_L);\n Eint += dz*(E0 + 4.*E1 + E2)/3. ;\n\n if(z>(z2-epsilon) && z<(z2+epsilon)) {\n if( i >= max_size )\n break ;\n\n const double Dc = Eint*Dh ;\n zc[i] = z ;\n dc[i] = Dc ;\n z2 += Deltaz ;\n i++ ;\n }\n }\n\n#ifdef DEBUG\n fprintf(stderr,\"%s> (Omega_m, Omega_L, Omega_k, h, zmax) = (%4.2f, %4.2f, %4.2f, %4.2f,%4.2lf)\\n\", __FUNCTION__, OMEGA_M,OMEGA_L,Omegak,LITTLE_H,zmax) ;\n fprintf(stderr,\"%s> tabulated redshift: %g to %g (distance: %g to %g Mpc)\\n\", __FUNCTION__, zc[0], zc[i-1], dc[0], dc[i-1]) ;\n#endif\n return i ;\n}\n", "meta": {"hexsha": "51ea3c9b8713dca934eacee7e93aa05e823f3af1", "size": 2150, "ext": "c", "lang": "C", "max_stars_repo_path": "utils/set_cosmo_dist.c", "max_stars_repo_name": "laperezNYC/Corrfunc", "max_stars_repo_head_hexsha": "3064f82df0b9ecba0898ee5d2731b44149849f23", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 139.0, "max_stars_repo_stars_event_min_datetime": "2016-02-10T01:41:55.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T10:33:38.000Z", "max_issues_repo_path": "utils/set_cosmo_dist.c", "max_issues_repo_name": "laperezNYC/Corrfunc", "max_issues_repo_head_hexsha": "3064f82df0b9ecba0898ee5d2731b44149849f23", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 227.0, "max_issues_repo_issues_event_min_datetime": "2015-11-13T06:31:46.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-03T21:12:36.000Z", "max_forks_repo_path": "utils/set_cosmo_dist.c", "max_forks_repo_name": "laperezNYC/Corrfunc", "max_forks_repo_head_hexsha": "3064f82df0b9ecba0898ee5d2731b44149849f23", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 58.0, "max_forks_repo_forks_event_min_datetime": "2016-03-15T07:25:33.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-22T09:38:27.000Z", "avg_line_length": 29.8611111111, "max_line_length": 156, "alphanum_fraction": 0.6023255814, "num_tokens": 736, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768588653856, "lm_q2_score": 0.8128673133042217, "lm_q1q2_score": 0.7674905065499253}} |
| {"text": "static char help[] = \"Newton's method for a three-variable system.\\n\"\n\"The system is from fitting logistic population model\\n\"\n\"P(t) = N / (1 + A exp(-Nbt)) to 3 points (t,P) from census data in\\n\"\n\"D. Zill, 11th ed., exercise 4 in section 3.2. The points are\\n\"\n\"(1790,3.929), (1850,23.192), (1910,91.972); populations in millions.\\n\";\n\n/*\nexample:\n$ make census\n$ ./census -snes_fd -snes_monitor\n 0 SNES Function norm 2.233793904584e+01\n...\n 17 SNES Function norm 6.521724317021e-07\n 18 SNES Function norm 4.358557709045e-09\nVec Object: 1 MPI processes\n type: seq\n197.274\n49.2096\n0.000158863\n*/\n\n#include <petsc.h>\n\nextern PetscErrorCode FormFunction(SNES, Vec, Vec, void*);\n\nint main(int argc,char **argv) {\n PetscErrorCode ierr;\n SNES snes; // nonlinear solver context\n Vec x, r; // solution, residual vectors\n double *ax;\n\n PetscInitialize(&argc,&argv,NULL,help);\n ierr = VecCreate(PETSC_COMM_WORLD,&x); CHKERRQ(ierr);\n ierr = VecSetSizes(x,PETSC_DECIDE,3); CHKERRQ(ierr);\n ierr = VecSetFromOptions(x); CHKERRQ(ierr);\n ierr = VecSetUp(x); CHKERRQ(ierr);\n ierr = VecGetArray(x,&ax);CHKERRQ(ierr);\n // ax = [N, A, b]; see equations in FormFunction() below\n // these initial values are based on *guessing* N=300\n // as the limiting population, then computing A, then b\n ax[0] = 300.0;\n ax[1] = 75.0;\n ax[2] = 1.0e-4;\n ierr = VecRestoreArray(x,&ax);CHKERRQ(ierr);\n ierr = VecAssemblyBegin(x);CHKERRQ(ierr);\n ierr = VecAssemblyEnd(x);CHKERRQ(ierr);\n ierr = VecDuplicate(x,&r); CHKERRQ(ierr);\n\n ierr = SNESCreate(PETSC_COMM_WORLD,&snes); CHKERRQ(ierr);\n ierr = SNESSetFunction(snes,r,FormFunction,NULL); CHKERRQ(ierr);\n ierr = SNESSetFromOptions(snes); CHKERRQ(ierr);\n ierr = SNESSolve(snes,NULL,x); CHKERRQ(ierr);\n ierr = VecView(x,PETSC_VIEWER_STDOUT_WORLD); CHKERRQ(ierr);\n\n VecDestroy(&x); VecDestroy(&r); SNESDestroy(&snes);\n return PetscFinalize();\n}\n\nPetscErrorCode FormFunction(SNES snes, Vec x, Vec F, void *ctx) {\n PetscErrorCode ierr;\n const double *ax;\n double *aF;\n\n ierr = VecGetArrayRead(x,&ax);CHKERRQ(ierr);\n ierr = VecGetArray(F,&aF);CHKERRQ(ierr);\n // ax = [N, A, b]\n // 3.929 (1 + A) - N = 0\n // 23.192 (1 + A exp(-60*N*b)) - N = 0\n // 91.972 (1 + A exp(-120*N*b)) - N = 0\n aF[0] = 3.929 * (1.0 + ax[1]) - ax[0];\n aF[1] = 23.192 * (1.0 + ax[1] * PetscExpReal(-60.0*ax[0]*ax[2])) - ax[0];\n aF[2] = 91.972 * (1.0 + ax[1] * PetscExpReal(-120.0*ax[0]*ax[2])) - ax[0];\n ierr = VecRestoreArray(F,&aF);CHKERRQ(ierr);\n ierr = VecRestoreArrayRead(x,&ax);CHKERRQ(ierr);\n return 0;\n}\n\n\n", "meta": {"hexsha": "9f1d01a1dccc638701844594d66682e12a2eae47", "size": 2669, "ext": "c", "lang": "C", "max_stars_repo_path": "c/ch4/solns/census.c", "max_stars_repo_name": "mapengfei-nwpu/p4pdes", "max_stars_repo_head_hexsha": "706411c1e745d7f825f336dcab3a62852538eaa4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "c/ch4/solns/census.c", "max_issues_repo_name": "mapengfei-nwpu/p4pdes", "max_issues_repo_head_hexsha": "706411c1e745d7f825f336dcab3a62852538eaa4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "c/ch4/solns/census.c", "max_forks_repo_name": "mapengfei-nwpu/p4pdes", "max_forks_repo_head_hexsha": "706411c1e745d7f825f336dcab3a62852538eaa4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.7848101266, "max_line_length": 78, "alphanum_fraction": 0.6294492319, "num_tokens": 900, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952893703477, "lm_q2_score": 0.8539127603871312, "lm_q1q2_score": 0.7665534625327581}} |
| {"text": "#include <stdio.h>\n#include <math.h>\n#include <gsl/gsl_statistics.h>\n#include <gsl/gsl_math.h>\n#include <gsl/gsl_cdf.h>\n#include <gsl/gsl_randist.h>\n#include \"stats.h\"\n\ndouble ttest_equalvar(const double *data1, int n1, const double *data2, int n2)\n{\n double mean1, mean2, var1, var2, num, sp, denom, t, dof, p;\n mean1 = gsl_stats_mean(data1, 1, n1);\n mean2 = gsl_stats_mean(data2, 1, n2);\n var1 = gsl_stats_variance(data1, 1, n1);\n var2 = gsl_stats_variance(data2, 1, n2);\n num = mean1 - mean2;\n sp = sqrt((((n1 - 1) * var1) + ((n2 - 1) * var2)) / (n1 + n2 - 2));\n denom = sp * sqrt((1 / (double) n1) + (1 / (double) n2));\n t = fabs(num / denom);\n dof = (double) n1 + n2 - 2;\n p = (1 - gsl_cdf_tdist_P(t, dof)) * 2;\n return p;\n}\n\ndouble ttest_unequalvar(const double *data1, int n1, const double *data2, int n2)\n{\n double mean1, mean2, var1, var2, r1, r2, t, dof, p;\n mean1 = gsl_stats_mean(data1, 1, n1);\n mean2 = gsl_stats_mean(data2, 1, n2);\n var1 = gsl_stats_variance(data1, 1, n1);\n var2 = gsl_stats_variance(data2, 1, n2);\n r1 = var1 / n1;\n r2 = var2 / n2;\n // Compute t-statistic\n t = fabs((mean1 - mean2) / sqrt(r1 + r2));\n dof = pow(r1 + r2, 2) / ((pow(r1, 2) / (n1 - 1)) + (pow(r2, 2) / (n2 - 1)));\n p = (1 - gsl_cdf_tdist_P(t, dof)) * 2;\n return p;\n}\n\ndouble ttest_paired(const double *data1, const double *data2, int n)\n{\n double data[n];\n double mean, sd, t, dof, p;\n for (int i = 0; i < n; i++)\n {\n data[i] = data1[i] - data2[i];\n }\n p = ttest(data, n); \n return p;\n}\n\ndouble ttest(const double *data, int n)\n{\n double mean, sd, t, dof, p;\n mean = gsl_stats_mean(data, 1, n);\n sd = gsl_stats_sd(data, 1, n);\n t = fabs((mean - 0) / (sd / sqrt((double) n)));\n dof = (double) n - 1;\n p = (1 - gsl_cdf_tdist_P(t, dof)) * 2;\n return p;\n}\n", "meta": {"hexsha": "64ede97a8b59ee9d71617b4d68f6804fd999d90c", "size": 1869, "ext": "c", "lang": "C", "max_stars_repo_path": "python-c-api/v3/stats.c", "max_stars_repo_name": "kgoettler/python-c-ext", "max_stars_repo_head_hexsha": "96a89cf9ee32a074185ffce842a999975ba0de19", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "python-c-api/v3/stats.c", "max_issues_repo_name": "kgoettler/python-c-ext", "max_issues_repo_head_hexsha": "96a89cf9ee32a074185ffce842a999975ba0de19", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "python-c-api/v3/stats.c", "max_forks_repo_name": "kgoettler/python-c-ext", "max_forks_repo_head_hexsha": "96a89cf9ee32a074185ffce842a999975ba0de19", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.6666666667, "max_line_length": 81, "alphanum_fraction": 0.5708935259, "num_tokens": 717, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9539660923657094, "lm_q2_score": 0.8031737963569016, "lm_q1q2_score": 0.7662005680011255}} |
| {"text": "/* sum/demo.c\n * \n * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Gerard Jungman, Brian Gough\n * \n * This program is free software; you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation; either version 3 of the License, or (at\n * your option) any later version.\n * \n * This program is distributed in the hope that it will be useful, but\n * WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * General Public License for more details.\n * \n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\n */\n\n#include <stdio.h>\n#include <gsl/gsl_math.h>\n#include <gsl/gsl_sum.h>\n\n#define N 20\n\nint \nmain (void)\n{\n double t[N];\n double sum_accel, err;\n double sum = 0;\n int n;\n \n gsl_sum_levin_u_workspace * w = gsl_sum_levin_u_alloc (N);\n\n const double zeta_2 = M_PI * M_PI / 6.0;\n \n /* terms for zeta(2) = \\sum_{n=1}^{\\infty} 1/n^2 */\n\n for (n = 0; n < N; n++)\n {\n double np1 = n + 1.0;\n t[n] = 1.0 / (np1 * np1);\n sum += t[n] ;\n }\n \n gsl_sum_levin_u_accel (t, N, w, &sum_accel, &err);\n\n printf(\"term-by-term sum = % .16f using %d terms\\n\", sum, N) ;\n\n printf(\"term-by-term sum = % .16f using %d terms\\n\", \n w->sum_plain, w->terms_used) ;\n\n printf(\"exact value = % .16f\\n\", zeta_2) ;\n printf(\"accelerated sum = % .16f using %d terms\\n\", \n sum_accel, w->terms_used) ;\n\n printf(\"estimated error = % .16f\\n\", err) ;\n printf(\"actual error = % .16f\\n\", sum_accel - zeta_2) ;\n\n gsl_sum_levin_u_free (w);\n\n return 0;\n}\n", "meta": {"hexsha": "1a1b4ba0a630f8635166ad404c8558a934d27711", "size": 1799, "ext": "c", "lang": "C", "max_stars_repo_path": "Chimera/3rd_Party/GSL_MSVC/sum/demo.c", "max_stars_repo_name": "zzpwahaha/Chimera-Control-Trim", "max_stars_repo_head_hexsha": "df1bbf6bea0b87b8c7c9a99dce213fdc249118f2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1.0, "max_stars_repo_stars_event_min_datetime": "2021-06-14T11:51:37.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-14T11:51:37.000Z", "max_issues_repo_path": "Chimera/3rd_Party/GSL_MSVC/sum/demo.c", "max_issues_repo_name": "zzpwahaha/Chimera-Control-Trim", "max_issues_repo_head_hexsha": "df1bbf6bea0b87b8c7c9a99dce213fdc249118f2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Chimera/3rd_Party/GSL_MSVC/sum/demo.c", "max_forks_repo_name": "zzpwahaha/Chimera-Control-Trim", "max_forks_repo_head_hexsha": "df1bbf6bea0b87b8c7c9a99dce213fdc249118f2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2.0, "max_forks_repo_forks_event_min_datetime": "2021-01-20T16:22:57.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-14T12:31:02.000Z", "avg_line_length": 27.6769230769, "max_line_length": 81, "alphanum_fraction": 0.6425792107, "num_tokens": 573, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392695254318, "lm_q2_score": 0.8652240773641087, "lm_q1q2_score": 0.7648920613287823}} |
| {"text": "/*\n * Take the input stream and tally the distribution of 8-bit bytes.\n * Calculate the entropy.\n */\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <gsl/gsl_sf_log.h>\n#include <gsl/gsl_math.h>\n\nint main(int argc, char **argv) {\n\tint tally[256];\n\tint ch;\n\tint n = 0;\n\tdouble h = 0;\n\n\tfor (int i=0; i<256; i++) tally[i] = 0;\n\tFILE *in;\n\n\tprintf (\"argc = %d\\n\", argc);\n\n\tif (argc < 2) {\n\t\tprintf (\"Input from stdin.\\n\");\n\t\tin = stdin;\n\t} else {\n\t\tprintf (\"Input file: %s\\n\", argv[1]);\n\t\tin = fopen(argv[1], \"r\");\n\t\tif (in == NULL) {\n\t\t\tprintf(\"BAD file: Usage: %s <random_file>\\n\", argv[0]);\n\t\t\treturn 1;\n\t\t}\n\t}\n\n\twhile ((ch = fgetc(in)) != EOF) {\n\t\ttally[ch] ++;\n\t\tn ++;\n\t}\n\tfclose(in);\n\n\tprintf(\"Frequency by byte:\");\n\tfor (int i=0; i<256; i++) {\n\t\tprintf(\" %d\", tally[i]);\n\t}\n\tprintf(\"\\n\");\n\tprintf(\"Input length = %d\\n\", n);\n\n\tfor (int i=0; i<256; i++) {\n\t\tdouble p = (double)(tally[i])/n;\n\t\tif (p>0) {\n\t\t\th = h - p*gsl_sf_log(p);\n\t\t}\n\t}\n\t// Divide by ln(2) to produce base 2 logarithms to calculate bits of entropy.\n\th = h/M_LN2;\n\tprintf(\"Entropy (h) = %1.10f\\n\", h);\n\n\t// Maximum entropy on bytes is 8 bits. Efficiency is calculated by dividing by the max.\n\tdouble eta = h/8;\n\tprintf(\"Efficiency (eta) = %1.10f\\n\", eta);\n\tprintf(\"ln(1-eta) = %1.10f\\n\", gsl_sf_log(1-eta));\n\n\t// This prediction is based on the regression from test5.\n\tprintf(\"Predicted value = %1.10f\\n\", -1.035*gsl_sf_log(n) + 3.562);\n\n\treturn 0;\n}\n\n", "meta": {"hexsha": "e722a40edfe932807cc5164bc77428b0005b5c2e", "size": 1422, "ext": "c", "lang": "C", "max_stars_repo_path": "tests/entropy_tests/exp01.c", "max_stars_repo_name": "jonkanderson/BitBalancedTableHash", "max_stars_repo_head_hexsha": "dc103a67d0826f09b07196217f00a454441d5011", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tests/entropy_tests/exp01.c", "max_issues_repo_name": "jonkanderson/BitBalancedTableHash", "max_issues_repo_head_hexsha": "dc103a67d0826f09b07196217f00a454441d5011", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tests/entropy_tests/exp01.c", "max_forks_repo_name": "jonkanderson/BitBalancedTableHash", "max_forks_repo_head_hexsha": "dc103a67d0826f09b07196217f00a454441d5011", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.9117647059, "max_line_length": 88, "alphanum_fraction": 0.5857946554, "num_tokens": 488, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942119105696, "lm_q2_score": 0.8459424431344437, "lm_q1q2_score": 0.7641349124928292}} |
| {"text": "#ifndef __MATH_SO3_H__\n#define __MATH_SO3_H__\n\n#include <string.h>\n#include <assert.h>\n#include <gsl/gsl_matrix.h>\n#include <gsl/gsl_vector.h>\n\n#include \"fasttrig.h\"\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n/*\n% ROTX Compute a rotation matrix about the X-axis.\n% R = ROTX(PHI) returns [3x3] rotation matrix R. Note: PHI\n% is measured in radians. PHI measures orientation of coordinate\n% frame 2 relative to coordinate frame 1. Multiplication by rotation\n% matrix R rotates a vector in coordinate frame 1 into coordinate\n% frame 2.\n*/\nstatic inline void\nso3_rotx (double Rx[9], const double phi)\n{\n double s, c;\n fsincos (phi, &s, &c);\n const double data[] = { 1, 0, 0,\n 0, c, s,\n 0, -s, c };\n memcpy (Rx, data, 9 * sizeof(double));\n}\n\nstatic inline void\nso3_rotx_gsl (gsl_matrix *Rx, const double phi)\n{\n assert (Rx->size1==3 && Rx->size2==3 && Rx->tda==3);\n so3_rotx (Rx->data, phi);\n}\n\n/*\n% ROTY Compute a rotation matrix about the Y-axis.\n% R = ROTY(THETA) returns [3x3] rotation matrix R. Note: THETA\n% is measured in radians. THETA measures orientation of coordinate\n% frame 2 relative to coordinate frame 1. Multiplication by rotation\n% matrix R rotates a vector in coordinate frame 1 into coordinate\n% frame 2.\n*/\nstatic inline void\nso3_roty (double Ry[9], const double theta)\n{\n double s, c;\n fsincos (theta, &s, &c);\n const double data[] = { c, 0, -s,\n 0, 1, 0,\n s, 0, c };\n memcpy (Ry, data, 9 * sizeof(double));\n}\n\nstatic inline void\nso3_roty_gsl (gsl_matrix *Ry, const double theta)\n{\n assert (Ry->size1==3 && Ry->size2==3 && Ry->tda==3);\n so3_roty (Ry->data, theta);\n}\n\n\n/*\n% ROTZ Compute a rotation matrix about the Z-axis.\n% R = ROTZ(PSI) returns [3x3] rotation matrix R. Note: PSI\n% is measured in radians. PSI measures orientation of coordinate\n% frame 2 relative to coordinate frame 1. Multiplication by rotation\n% matrix R rotates a vector in coordinate frame 1 into coordinate\n% frame 2.\n*/\nstatic inline void\nso3_rotz (double Rz[9], const double psi)\n{\n double s, c;\n fsincos (psi, &s, &c);\n const double data[] = { c, s, 0,\n -s, c, 0,\n 0, 0, 1 };\n memcpy (Rz, data, 9 * sizeof(double));\n}\n\nstatic inline void\nso3_rotz_gsl (gsl_matrix *Rz, const double psi)\n{\n assert (Rz->size1==3 && Rz->size2==3 && Rz->tda==3);\n so3_rotz (Rz->data, psi);\n}\n\n/*\n% ROTXYZ Compute a rotation matrix about the XYZ-axes.\n% R = ROTXYZ(RPH) returns [3x3] rotation matrix R where RPH\n% is a 3-vector of Euler angles [roll,pitch,heading] measured in\n% radians. RPH measures orientation of coordinate frame 2\n% relative to coordinate frame 1. Multiplication by rotation\n% matrix R rotates a vector in coordinate frame 2 into coordinate\n% frame 1.\n*/\nstatic inline void\nso3_rotxyz (double R[9], const double rph[3])\n{\n double sr, sp, sh, cr, cp, ch;\n fsincos (rph[0], &sr, &cr);\n fsincos (rph[1], &sp, &cp);\n fsincos (rph[2], &sh, &ch);\n const double data[] = { ch*cp, -sh*cr + ch*sp*sr, sh*sr + ch*sp*cr,\n sh*cp, ch*cr + sh*sp*sr, -ch*sr + sh*sp*cr,\n -sp, cp*sr, cp*cr };\n memcpy (R, data, 9 * sizeof(double));\n}\n\nstatic inline void\nso3_rotxyz_gsl (gsl_matrix *R, const gsl_vector *rph)\n{\n assert (R->size1==3 && R->size2==3 && rph->size==3);\n\n // when rph is vector view, stride might not be 1\n double rph_data[3] = {rph->data[0], rph->data[rph->stride], rph->data[2*rph->stride]};\n\n if (R->tda==3) {\n so3_rotxyz (R->data, rph_data);\n }\n else {\n double rot[9];\n so3_rotxyz (rot, rph_data);\n for (int i=0; i < 3; ++i)\n for (int j=0; j < 3; ++j)\n gsl_matrix_set (R, i, j, rot[i*3 + j]);\n }\n}\n\nstatic inline void\nso3_rotxyz_cmath (double R[9], const double rph[3])\n{\n double sr, sp, sh, cr, cp, ch;\n sr = sin(rph[0]); cr = cos(rph[0]);\n sp = sin(rph[1]); cp = cos(rph[1]);\n sh = sin(rph[2]); ch = cos(rph[2]);\n const double data[] = { ch*cp, -sh*cr + ch*sp*sr, sh*sr + ch*sp*cr,\n sh*cp, ch*cr + sh*sp*sr, -ch*sr + sh*sp*cr,\n -sp, cp*sr, cp*cr };\n memcpy (R, data, 9 * sizeof(double));\n}\n\n/*\n%ROT2RPH Convert rotation matrix into Euler roll,pitch,heading.\n% RPH = ROT2RPH(R) computes 3-vector of Euler angles\n% [roll,pitch,heading] from [3x3] rotation matrix R. Angles are\n% measured in radians.\n%\n*/\nstatic inline void\nso3_rot2rph (const double R[9], double rph[3])\n{\n#define R(i,j) (R[i*3+j])\n // heading\n rph[2] = fatan2 (R(1,0), R(0,0));\n double sh, ch;\n fsincos (rph[2], &sh, &ch);\n\n // pitch\n rph[1] = fatan2 (-R(2,0), R(0,0)*ch + R(1,0)*sh);\n\n // roll\n rph[0] = fatan2 (R(0,2)*sh - R(1,2)*ch, -R(0,1)*sh + R(1,1)*ch);\n#undef R\n}\n\nstatic inline void\nso3_rot2rph_gsl (const gsl_matrix *R, gsl_vector *rph)\n{\n assert (R->size1==3 && R->size2==3 && R->tda==3 && rph->size==3);\n so3_rot2rph (R->data, rph->data);\n}\n\n/*\n% DROTX Compute the derivative of a rotation matrix about the X-axis.\n% dRx = DROTZ(PHI) returns [3x3] rotation matrix dRx. Note: PHI\n% is measured in radians. PHI measures orientation of coordinate\n% frame 2 relative to coordinate frame 1.\n*/\nstatic inline void\nso3_drotx (double dRx[9], const double phi)\n{\n double s, c;\n fsincos (phi, &s, &c);\n const double data[9] = { 0, 0, 0,\n 0, -s, c,\n 0, -c, -s };\n memcpy (dRx, data, 9 * sizeof(double));\n}\n\nstatic inline void\nso3_drotx_gsl (gsl_matrix *dRx, const double phi)\n{\n assert (dRx->size1==3 && dRx->size2==3 && dRx->tda==3);\n so3_drotx (dRx->data, phi);\n}\n\n/*\n% DROTY Compute the derivative of a rotation matrix about the Y-axis.\n% dRy = DROTY(THETA) returns [3x3] rotation matrix dRy. Note: THETA\n% is measured in radians. THETA measures orientation of coordinate\n% frame 2 relative to coordinate frame 1.\n*/\nstatic inline void\nso3_droty (double dRy[9], const double theta)\n{\n double s, c;\n fsincos (theta, &s, &c);\n const double data[9] = { -s, 0, -c,\n 0, 0, 0,\n c, 0, -s };\n memcpy (dRy, data, 9 * sizeof(double));\n}\n\nstatic inline void\nso3_droty_gsl (gsl_matrix *dRy, const double theta)\n{\n assert (dRy->size1==3 && dRy->size2==3 && dRy->tda==3);\n so3_droty (dRy->data, theta);\n}\n\n/*\n% DROTZ Compute the derivative of a rotation matrix about the Z-axis.\n% dRz = DROTZ(PSI) returns [3x3] rotation matrix dRz. Note: PSI\n% is measured in radians. PSI measures orientation of coordinate\n% frame 2 relative to coordinate frame 1.\n*/\nstatic inline void\nso3_drotz (double dRz[9], const double psi)\n{\n double s, c;\n fsincos (psi, &s, &c);\n const double data[9] = { -s, c, 0,\n -c, -s, 0,\n 0, 0, 0 };\n memcpy (dRz, data, 9 * sizeof(double));\n}\n\nstatic inline void\nso3_drotz_gsl (gsl_matrix *dRz, const double psi)\n{\n assert (dRz->size1==3 && dRz->size2==3 && dRz->tda==3);\n so3_drotz (dRz->data, psi);\n}\n\n/*\n% QUAT2ROT quaternion to rotation matrix.\n% R = QUAT2ROT(q) takes a 4-vector unit quaternion reprsented by q,\n% (i.e. q = [q0;qx;qy;qz]) and returns the corresponding [3 x 3]\n% orthonormal rotation matrix R.\n*/\nstatic inline void\nso3_quat2rot (const double q[4], double R[9])\n{\n const double q0 = q[0], qx = q[1], qy = q[2], qz = q[3];\n\n const double q0q0 = q0*q0;\n const double qxqx = qx*qx;\n const double qyqy = qy*qy;\n const double qzqz = qz*qz;\n\n const double q0qx = q0*qx;\n const double q0qz = q0*qz;\n const double q0qy = q0*qy;\n const double qxqy = qx*qy;\n const double qxqz = qx*qz;\n const double qyqz = qy*qz;\n\n const double data[9] =\n { q0q0 + qxqx - qyqy - qzqz, 2*(qxqy - q0qz), 2*(qxqz + q0qy),\n 2*(qxqy + q0qz), q0q0 - qxqx + qyqy - qzqz, 2*(qyqz - q0qx),\n 2*(qxqz - q0qy), 2*(qyqz + q0qx), q0q0 - qxqx - qyqy + qzqz };\n memcpy (R, data, 9 * sizeof(double));\n}\n\nstatic inline void\nso3_quat2rot_gsl (const gsl_vector *q, gsl_matrix *R)\n{\n assert (q->size==4 && R->size1==3 && R->size2==3 && R->tda==3);\n so3_quat2rot (q->data, R->data);\n}\n\n\n/*\n% ROT2QUAT rotation matrix to quaternion.\n% q = ROT2QUAT(R) returns a 4-vector unit quaternion reprsented by q,\n% (i.e. q = [q0;qx;qy;qz]) corresponding to the [3 x 3]\n% orthonormal rotation matrix R.\n*/\nstatic inline void\nso3_rot2quat (const double R[9], double q[4])\n{\n // read\n const double r00 = R[0], r01 = R[1], r02 = R[2];\n const double r10 = R[3], r11 = R[4], r12 = R[5];\n const double r20 = R[6], r21 = R[7], r22 = R[8];\n\n const double tr = r00 + r11 + r22;\n\n double qw, qx, qy, qz;\n if (tr > 0) {\n const double S = sqrt (tr+1.0) * 2; // S=4*qw\n qw = 0.25 * S;\n qx = (r21 - r12) / S;\n qy = (r02 - r20) / S;\n qz = (r10 - r01) / S;\n } else if ((r00 > r11) && (r00 > r22)) {\n const double S = sqrt (1.0 + r00 - r11 - r22) * 2; // S=4*qx\n qw = (r21 - r12) / S;\n qx = 0.25 * S;\n qy = (r01 + r10) / S;\n qz = (r02 + r20) / S;\n } else if (r11 > r22) {\n const double S = sqrt (1.0 + r11 - r00 - r22) * 2; // S=4*qy\n qw = (r02 - r20) / S;\n qx = (r01 + r10) / S;\n qy = 0.25 * S;\n qz = (r12 + r21) / S;\n } else {\n const double S = sqrt (1.0 + r22 - r00 - r11) * 2; // S=4*qz\n qw = (r10 - r01) / S;\n qx = (r02 + r20) / S;\n qy = (r12 + r21) / S;\n qz = 0.25 * S;\n }\n\n // write\n q[0] = qw; q[1] = qx; q[2] = qy; q[3] = qz;\n}\n\nstatic inline void\nso3_rot2quat_gsl (const gsl_matrix *R, gsl_vector *q)\n{\n assert (q->size==4 && R->size1==3 && R->size2==3 && R->tda==3);\n so3_rot2quat (R->data, q->data);\n}\n\n\n/*\n% QUAT2RPH converts unit quaternion to Euler RPH.\n% rph = QUAT2RPH(q) returns a [3 x 1] Euler xyz representation\n% equivalent to the [4 x 1] unit quaternion (provided q is\n% not near an Euler singularity).\n*/\nstatic inline void\nso3_quat2rph (const double q[4], double rph[3])\n{\n double R[9];\n so3_quat2rot (q, R);\n so3_rot2rph (R, rph);\n}\n\nstatic inline void\nso3_quat2rph_gsl (const gsl_vector *q, gsl_vector *rph)\n{\n assert (q->size==4 && rph->size==4);\n so3_quat2rph (q->data, rph->data);\n}\n\n/*\n% RPH2QUAT converts Euler RPH to unit quaternion.\n% q = RPH2QUAT(R) converts [3 x 1] Euler xyz representation\n% to an equivalent [4 x 1] unit quaternion (provided R is\n% not near an Euler singularity).\n*/\nstatic inline void\nso3_rph2quat (const double rph[3], double q[4])\n{\n double R[9];\n so3_rotxyz (R, rph);\n so3_rot2quat (R, q);\n}\n\nstatic inline void\nso3_rph2quat_gsl (const gsl_vector *rph, gsl_vector *q)\n{\n assert (q->size==4 && rph->size==4);\n so3_rph2quat (rph->data, q->data);\n}\n\n\n/*\n% function [rph_dot,J] = body2euler(pqr,rph)\n% BODY2EULER converts body frame angular rates to Euler rates.\n% RPH_DOT = BODY2EULER(PQR,RPH) converts body frame angular rates PQR to\n% Euler angular rates RPH_DOT given Euler angles RPH.\n%\n% [RPH_DOT,J] = BODY2EULER(PQR,RPH) also returns the [3 x 6] Jacobian J\n% associated with the transformation where J = [J_pqr, J_rph].\n% see body2euler.m for cleaner notation\n*/\nstatic inline void\nso3_body2euler (const double pqr[3], const double rph[3],\n double rph_dot[3], double J[18]) {\n\n double p = pqr[0];\n double q = pqr[1];\n double r = pqr[2];\n\n double sr, cr;\n fsincos (rph[0], &sr, &cr);\n double sp, cp;\n fsincos (rph[1], &sp, &cp);\n double tp = ftan (rph[1]);\n double kp = 1.0/cp;\n\n //Euler angular rates\n rph_dot[0] = p+sr*tp*q+cr*tp*r;\n rph_dot[1] = cr*q-sr*r;\n rph_dot[2] = sr*kp*q+cr*kp*r;\n\n if (J != NULL) {\n // Jacobian wrt\n // first row\n J[0] = 1; J[1] = sr*tp; J[2] = cr*tp;\n J[3] = cr*tp*q-sr*tp*r; J[4] = sr*kp*kp*q+cr*kp*kp*r; J[5] = 0;\n // second row\n J[6] = 0; J[7] = cr; J[8] = -sr;\n J[9] = -sr*q-cr*r; J[10] = 0; J[11] = 0;\n // third row\n J[12] = 0; J[13] = sr*kp; J[14] = cr*kp;\n J[15] = cr*kp*q-sr*kp*r; J[16] = sr*kp*tp*q+cr*kp*tp*r; J[17] = 0;\n }\n}\n\n/*\n% function [pqr,J] = euler2body(rph_dot,rph)\n% converts euler rates to body frame angular rates\n%\n% if not null also returns the [3 x 6] Jacobian J\n% associated with the transformation where J = [rph_dot, J_rph].\n% see body2euler.m for cleaner notation\n*/\nstatic inline void\nso3_euler2body (const double rph_dot[3], const double rph[3],\n double pqr[3], double J[18]) {\n\n double rd = rph_dot[0];\n double pd = rph_dot[1];\n double hd = rph_dot[2];\n\n double sr, cr;\n fsincos (rph[0], &sr, &cr);\n double sp, cp;\n fsincos (rph[1], &sp, &cp);\n\n //body rates\n pqr[0] = -sp*hd + rd;\n pqr[1] = sr*cp*hd + cr*pd;\n pqr[2] = cr*cp*hd - sr*pd;\n\n if (J != NULL) {\n // Jacobian wrt\n // first row\n J[0] = 1; J[1] = 0; J[2] = -sp;\n J[3] = 0; J[4] = -cp*hd; J[5] = 0;\n // second row\n J[6] = 0; J[7] = cr; J[8] = sr*cp;\n J[9] = cr*cp*hd-sr*pd; J[10] = sr*-sp*hd; J[11] = 0;\n // third row\n J[12] = 0; J[13] = sr; J[14] = cr*cp;\n J[15] = -sr*cp*hd-cr*pd; J[16] = cr*+sp*hd; J[17] = 0;\n }\n}\n\nstatic inline void\nso3_body2euler_gsl (const gsl_vector *pqr, const gsl_vector *rph,\n gsl_vector *rph_dot, gsl_matrix *J) {\n\n assert (pqr->size==3 && rph->size==3 && rph_dot->size==3\n && J->size1==3 && J->size2==6 && J->tda==6);\n\n so3_body2euler (pqr->data, rph->data, rph_dot->data, J->data);\n\n}\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif // __MATH_SO3_H__\n", "meta": {"hexsha": "1a4b7ce787742c8d7ed2ffcb935d64b65e61cfb3", "size": 14293, "ext": "h", "lang": "C", "max_stars_repo_path": "botgui/vx/math/so3.h", "max_stars_repo_name": "gaomeitao/balance-gyrodometry-robot", "max_stars_repo_head_hexsha": "f7039adc78fbf89442c1881f9d9d2c2b28bf4c76", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1.0, "max_stars_repo_stars_event_min_datetime": "2022-03-27T19:09:46.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-27T19:09:46.000Z", "max_issues_repo_path": "src/vx/math/so3.h", "max_issues_repo_name": "tsnowak/rob550-botlab", "max_issues_repo_head_hexsha": "e8ce317fa3e0c089e30894fbb472669831eb0828", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/vx/math/so3.h", "max_forks_repo_name": "tsnowak/rob550-botlab", "max_forks_repo_head_hexsha": "e8ce317fa3e0c089e30894fbb472669831eb0828", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2.0, "max_forks_repo_forks_event_min_datetime": "2019-06-29T04:21:35.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-31T01:33:24.000Z", "avg_line_length": 29.2889344262, "max_line_length": 94, "alphanum_fraction": 0.5525781851, "num_tokens": 5165, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096204605946, "lm_q2_score": 0.8333245911726382, "lm_q1q2_score": 0.7634166749396458}} |
| {"text": "#include <stdio.h>\n#include <math.h>\n#include <gsl/gsl_integration.h>\n#include <gsl/gsl_sf_gamma.h>\n\ndouble\nf(double x, void * params)\n{\n int m = *(int *) params;\n double f = gsl_pow_int(x, m) + 1.0;\n return f;\n}\n\nint\nmain (int argc, char *argv[])\n{\n gsl_integration_fixed_workspace * w;\n const gsl_integration_fixed_type * T = gsl_integration_fixed_hermite;\n int m = 10;\n int n = 6;\n double expected, result;\n gsl_function F;\n\n if (argc > 1)\n m = atoi(argv[1]);\n\n if (argc > 2)\n n = atoi(argv[2]);\n\n w = gsl_integration_fixed_alloc(T, n, 0.0, 1.0, 0.0, 0.0);\n\n F.function = &f;\n F.params = &m;\n\n gsl_integration_fixed(&F, &result, w);\n\n if (m % 2 == 0)\n expected = M_SQRTPI + gsl_sf_gamma(0.5*(1.0 + m));\n else\n expected = M_SQRTPI;\n\n printf (\"m = %d\\n\", m);\n printf (\"intervals = %zu\\n\", gsl_integration_fixed_n(w));\n printf (\"result = % .18f\\n\", result);\n printf (\"exact result = % .18f\\n\", expected);\n printf (\"actual error = % .18f\\n\", result - expected);\n\n gsl_integration_fixed_free (w);\n\n return 0;\n}\n", "meta": {"hexsha": "7638a5b8381d417a1436e6c3ceddefd2c8012aa1", "size": 1080, "ext": "c", "lang": "C", "max_stars_repo_path": "gsl-2.6/doc/examples/integration2.c", "max_stars_repo_name": "ielomariala/Hex-Game", "max_stars_repo_head_hexsha": "2c2e7c85f8414cb0e654cb82e9686cce5e75c63a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1.0, "max_stars_repo_stars_event_min_datetime": "2021-06-14T11:51:37.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-14T11:51:37.000Z", "max_issues_repo_path": "Source/BaselineMethods/MNE/C++/gsl-2.4/doc/examples/integration2.c", "max_issues_repo_name": "Brian-ning/HMNE", "max_issues_repo_head_hexsha": "1b4ee4c146f526ea6e2f4f8607df7e9687204a9e", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 6.0, "max_issues_repo_issues_event_min_datetime": "2019-12-16T17:41:24.000Z", "max_issues_repo_issues_event_max_datetime": "2019-12-22T00:00:16.000Z", "max_forks_repo_path": "Source/BaselineMethods/MNE/C++/gsl-2.4/doc/examples/integration2.c", "max_forks_repo_name": "Brian-ning/HMNE", "max_forks_repo_head_hexsha": "1b4ee4c146f526ea6e2f4f8607df7e9687204a9e", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2.0, "max_forks_repo_forks_event_min_datetime": "2021-01-20T16:22:57.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-14T12:31:02.000Z", "avg_line_length": 20.7692307692, "max_line_length": 71, "alphanum_fraction": 0.6, "num_tokens": 356, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088064979618, "lm_q2_score": 0.8198933337131076, "lm_q1q2_score": 0.7611961914082213}} |
| {"text": "#include <math.h>\n#include <stdio.h>\n#include <gsl/gsl_matrix.h>\n#include <gsl/gsl_blas.h>\n#include <gsl/gsl_linalg.h>\n#include <gsl/gsl_cblas.h>\n\n#include \"motionControl.h\"\n\nvoid printMatrix(gsl_matrix* m, int row, int col) {\n for(int i = 0; i < row; i++) {\n for(int j = 0; j < col; j++) {\n printf(\"%g \", gsl_matrix_get(m, i, j));\n }\n printf(\"\\n\");\n }\n}\n\ngsl_matrix* measurementMatrix() {\n gsl_matrix *m = gsl_matrix_alloc (3, 3);\n\n gsl_matrix_set (m, 0, 0, -.5);\n gsl_matrix_set (m, 0, 1, .866);\n gsl_matrix_set (m, 0, 2, (.866*6.9282 - -.5*4));\n gsl_matrix_set (m, 1, 0, -.5);\n gsl_matrix_set (m, 1, 1, -.866);\n gsl_matrix_set (m, 1, 2, (.866*6.9282 - -.5*4));\n gsl_matrix_set (m, 2, 0, 1);\n gsl_matrix_set (m, 2, 1, 0);\n gsl_matrix_set (m, 2, 2, 8);\n\n return m;\n}\n\ngsl_matrix* rotationMatrix(float omegaWorld, float omegaBody) {\n gsl_matrix *m = gsl_matrix_alloc (3, 3);\n\n float theta = omegaWorld - omegaBody; // TODO check if radians or degrees\n\n gsl_matrix_set (m, 0, 0, cos(theta));\n gsl_matrix_set (m, 0, 1, sin(theta));\n gsl_matrix_set (m, 0, 2, 0);\n gsl_matrix_set (m, 1, 0, -sin(theta));\n gsl_matrix_set (m, 1, 1, cos(theta));\n gsl_matrix_set (m, 1, 2, 0);\n gsl_matrix_set (m, 2, 0, 0);\n gsl_matrix_set (m, 2, 1, 0);\n gsl_matrix_set (m, 2, 2, 1);\n\n return m;\n}\n\ngsl_matrix* pointToVelocity(float cX, float cY, float cOmega, float dX, float dY, float dOmega, float time) { //d stands for desired\n gsl_matrix *m = gsl_matrix_alloc (3, 1);\n\n float vX = (dX - cX) / time;\n float vY = (dY - cY) / time;\n float omega = (dOmega - cOmega) / time;\n\n gsl_matrix_set (m, 0, 0, vX);\n gsl_matrix_set (m, 1, 0, vY);\n gsl_matrix_set (m, 2, 0, omega);\n\n return m;\n}\n\ngsl_matrix* linearToAngular(gsl_matrix* R, gsl_matrix* M, gsl_matrix* V) {\n gsl_matrix_transpose(R);\n\n int signum;\n\n gsl_matrix * inverseR = gsl_matrix_alloc (3, 3);\n gsl_permutation * perm = gsl_permutation_alloc (3);\n\n gsl_linalg_LU_decomp (M, perm, &signum);\n gsl_linalg_LU_invert (M, perm, inverseR);\n\n gsl_matrix_mul_elements (inverseR, M);\n gsl_matrix* result = inverseR;\n\n float omega1 = rowSum(result, V, 0);\n float omega2 = rowSum(result, V, 1);\n float omega3 = rowSum(result, V, 2);\n\n gsl_matrix * final = gsl_matrix_alloc (3, 1);\n gsl_matrix_set (final, 0, 0, omega1);\n gsl_matrix_set (final, 1, 0, omega2);\n gsl_matrix_set (final, 2, 0, omega3);\n\n gsl_matrix_free(inverseR);\n gsl_permutation_free(perm);\n return final;\n}\n\nfloat rowSum(gsl_matrix* result, gsl_matrix* V, int row) {\n float sum = 0;\n for(int i = 0; i < 3; i++) {\n sum += gsl_matrix_get(result, row, i) * gsl_matrix_get(V, i, 0);\n }\n return sum;\n}\n\nint main (void) {\n gsl_matrix* M = measurementMatrix();\n gsl_matrix* R = rotationMatrix(1, 2);\n gsl_matrix* V = pointToVelocity(0, 0, 0, 1, 1, 0, 1);\n\n gsl_matrix* final = linearToAngular(R, M, V);\n\n printMatrix(final, 3, 1);\n gsl_matrix_free (M);\n gsl_matrix_free (R);\n gsl_matrix_free (V);\n gsl_matrix_free (final);\n\n return 0;\n}\n\n", "meta": {"hexsha": "2ee4cef488591f1c53305b995ff28db3136a9119", "size": 3154, "ext": "c", "lang": "C", "max_stars_repo_path": "motionControl/motionControl.c", "max_stars_repo_name": "nagneeve/ecen490", "max_stars_repo_head_hexsha": "260805b87f3d890cbcb892121261baa5038e65c8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "motionControl/motionControl.c", "max_issues_repo_name": "nagneeve/ecen490", "max_issues_repo_head_hexsha": "260805b87f3d890cbcb892121261baa5038e65c8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "motionControl/motionControl.c", "max_forks_repo_name": "nagneeve/ecen490", "max_forks_repo_head_hexsha": "260805b87f3d890cbcb892121261baa5038e65c8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.5042016807, "max_line_length": 132, "alphanum_fraction": 0.6122384274, "num_tokens": 1100, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947163538935, "lm_q2_score": 0.8006920020959544, "lm_q1q2_score": 0.7566497114074975}} |
| {"text": "#ifndef _INC_REGRESSION_\n#define _INC_REGRESSION_\n/**\n * contains the functions needed to handle the linear regression\n * this entails, creating hvectors (for given x vectors in the parameter space)\n * estimatingBeta, this needs the inverse covariance matrix and the training data\n * creating hmatrix, a done once kind of job, slap together hvectors for each of the design points\n */\n\n#include <gsl/gsl_vector.h>\n#include <gsl/gsl_matrix.h>\n#include <gsl/gsl_blas.h>\n#include <gsl/gsl_linalg.h> \n#include <gsl/gsl_sf.h> \n\n\n/**\n * \\brief creates a vector of regression coefficients at x_location\n * \n * create a h_vector evaluated at given x_location., \n * this currently only creates a set of linear basis fns, you could add another loop which \n * would add squares etc \n * \n * on calling h_vector should be initliased to a vector of length nregression_fns which \n * in the default case nregression_fns = nparams + 1 \n * \n * the value of options->nregression_fns is going to be very important for this\n * \n * this pointer is set to one of the fns in this file by optstruct.c:setup_regression\n */\n\nvoid (*makeHVector)(gsl_vector *h_vector, gsl_vector *x_location, int nparams);\n\n\n//void makeHVector(gsl_vector *h_vector, gsl_vector *x_location, int nparams);\n\nvoid makeHMatrix(gsl_matrix *h_matrix, gsl_matrix *xmodel, int nmodel_points, int nparams, int nregresion_fns);\n\nvoid makeHMatrix_fnptr(gsl_matrix *h_matrix, gsl_matrix *xmodel, int nmodel_points, int nparams, int nregression_fns,\n\t\t\t\t\t\t\t\t\t\t\t void (*makeHVector_ptr)(gsl_vector *h_vector, gsl_vector *x_location, int nparams));\n\nvoid estimateBeta(gsl_vector *beta_vector, gsl_matrix *h_matrix, gsl_matrix* cinverse, gsl_vector *trainingvector, int nmodel_points, int nregression_fns);\n\nvoid makeHVector_linear(\tgsl_vector *h_vector, gsl_vector *x_location, int nparams);\nvoid makeHVector_quadratic( gsl_vector *h_vector, gsl_vector *x_location, int nparams);\nvoid makeHVector_trivial(gsl_vector *h_vector, gsl_vector *x_location, int nparams);\nvoid makeHVector_cubic( gsl_vector *h_vector, gsl_vector *x_location, int nparams);\n#endif\n", "meta": {"hexsha": "e8f8f13481153d0ac7ec1b8a84d251c28c85e69a", "size": 2094, "ext": "h", "lang": "C", "max_stars_repo_path": "src/libEmu/regression.h", "max_stars_repo_name": "jackdawjackdaw/emulator", "max_stars_repo_head_hexsha": "1c11f69c535acef8159ef0e780cca343785ea004", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2.0, "max_stars_repo_stars_event_min_datetime": "2015-04-02T17:37:42.000Z", "max_stars_repo_stars_event_max_datetime": "2017-06-02T00:34:49.000Z", "max_issues_repo_path": "src/libEmu/regression.h", "max_issues_repo_name": "MADAI/MADAIEmulator", "max_issues_repo_head_hexsha": "7d926ad04a791c7694defd88db41c13f7ee4e6aa", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/libEmu/regression.h", "max_forks_repo_name": "MADAI/MADAIEmulator", "max_forks_repo_head_hexsha": "7d926ad04a791c7694defd88db41c13f7ee4e6aa", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1.0, "max_forks_repo_forks_event_min_datetime": "2021-01-30T16:43:33.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-30T16:43:33.000Z", "avg_line_length": 42.7346938776, "max_line_length": 155, "alphanum_fraction": 0.7788920726, "num_tokens": 544, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625012602593, "lm_q2_score": 0.8080672158638527, "lm_q1q2_score": 0.7526843100749581}} |
| {"text": "#pragma once\n\n#include <list>\n\n#include <gsl/gsl_math.h>\n#include <gsl/gsl_randist.h>\n#include <gsl/gsl_cdf.h>\n\n#include \"../../../Utils/Random.h\"\n#include \"../../Expression.h\"\n#include \"../RandomDistributionDirectory.h\"\n\ndouble rand_Gauss(const std::list<expression>& args, const Variables& vars){\n if (args.size() == 1){\n double sigma = args.front()->value(vars);\n return gsl_ran_gaussian(rng.get(), sigma);\n }\n return GSL_NAN;\n}\n\ndouble pdf_Gauss(double x, const std::list<expression>& args, const Variables& vars){\n if (args.size() == 1){\n double sigma = args.front()->value(vars);\n return gsl_ran_gaussian_pdf(x, sigma);\n }\n return GSL_NAN;\n}\n\ndouble cdf_P_Gauss(double x, const std::list<expression>& args, const Variables& vars){\n if (args.size() == 1){\n double sigma = args.front()->value(vars);\n return gsl_cdf_gaussian_P(x, sigma);\n }\n return GSL_NAN;\n}\n\ndouble cdf_Q_Gauss(double x, const std::list<expression>& args, const Variables& vars){\n if (args.size() == 1){\n double sigma = args.front()->value(vars);\n return gsl_cdf_gaussian_Q(x, sigma);\n }\n return GSL_NAN;\n}\n\n\ndouble cdf_Pinv_Gauss(double x, const std::list<expression>& args, const Variables& vars){\n if (args.size() == 1){\n double sigma = args.front()->value(vars);\n return gsl_cdf_gaussian_Pinv(x, sigma);\n }\n return GSL_NAN;\n}\n\ndouble cdf_Qinv_Gauss(double x, const std::list<expression>& args, const Variables& vars){\n if (args.size() == 1){\n double sigma = args.front()->value(vars);\n return gsl_cdf_gaussian_Qinv(x, sigma);\n }\n return GSL_NAN;\n}\n", "meta": {"hexsha": "cb12506585de1e57bdf3f6dc6e5b916cc61840c9", "size": 1663, "ext": "h", "lang": "C", "max_stars_repo_path": "MathEngine/Expressions/RandomDistributionExpressions/Distributions/Gauss.h", "max_stars_repo_name": "antoniojkim/CalcPlusPlus", "max_stars_repo_head_hexsha": "33cede17001e0a7038f99ea40dd6f9e433cf6454", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "MathEngine/Expressions/RandomDistributionExpressions/Distributions/Gauss.h", "max_issues_repo_name": "antoniojkim/CalcPlusPlus", "max_issues_repo_head_hexsha": "33cede17001e0a7038f99ea40dd6f9e433cf6454", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "MathEngine/Expressions/RandomDistributionExpressions/Distributions/Gauss.h", "max_forks_repo_name": "antoniojkim/CalcPlusPlus", "max_forks_repo_head_hexsha": "33cede17001e0a7038f99ea40dd6f9e433cf6454", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.262295082, "max_line_length": 90, "alphanum_fraction": 0.6404088996, "num_tokens": 436, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9715639677785088, "lm_q2_score": 0.7745833841649233, "lm_q1q2_score": 0.7525573060945779}} |
| {"text": "#ifndef __EMULATOR_INC_\n#define __EMULATOR_INC_\n#include <gsl/gsl_matrix.h>\n#include <gsl/gsl_blas.h>\n#include <gsl/gsl_linalg.h> \n#include <gsl/gsl_sf.h>\n\n\n/**\n * the fn ptr to the covariance function, this is the most called function in libEmu\n * you can change this when you setup the optstruct.\n */\ndouble (*covariance_fn)(gsl_vector*, gsl_vector*, gsl_vector*, int, int) ;\n\nvoid print_matrix(gsl_matrix* m, int nx, int ny);\n\ndouble covariance_fn_gaussian(gsl_vector *xm, gsl_vector* xn, gsl_vector* thetas, int nthetas, int nparams);\n\nvoid derivative_l_gauss(gsl_matrix *dCdTheta, gsl_matrix* xmodel, \n\t\t\t\t\t\t\t\t\t\t\t\tdouble thetaLength, int index, int nmodel_points, int nparams);\n\n// same as above but without clamping on small values\ndouble covariance_fn_gaussian_exact(gsl_vector *xm, gsl_vector* xn, gsl_vector* thetas, int nthetas, int nparams);\n\ndouble covariance_fn_matern_three(gsl_vector *xm, gsl_vector* xn, gsl_vector* thetas, int nthetas, int nparams);\n\nvoid derivative_l_matern_three(gsl_matrix *dCdTheta, gsl_matrix* xmodel, double thetaLength,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t int index, int nmodel_points, int nparams);\n\ndouble covariance_fn_matern_five(gsl_vector *xm, gsl_vector* xn, gsl_vector* thetas, int nthetas, int nparams);\n\nvoid derivative_l_matern_five(gsl_matrix *dCdTheta, gsl_matrix* xmodel, double thetaLength,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tint index, int nmodel_points, int nparams);\n\n\nvoid makeKVector(gsl_vector* kvector, gsl_matrix *xmodel, gsl_vector *xnew, gsl_vector* thetas, int nmodel_points, int nthetas, int nparams);\n\nvoid makeKVector_fnptr(gsl_vector* kvector, gsl_matrix *xmodel, gsl_vector *xnew, gsl_vector* thetas, int nmodel_points, int nthetas, int nparams,\n\t\t\t\t\t\t\t\t\t\t\t double (*covariance_fn_ptr)(gsl_vector*, gsl_vector*, gsl_vector*, int, int));\n\n\nvoid makeCovMatrix(gsl_matrix *cov_matrix, gsl_matrix *xmodel, gsl_vector* thetas, int nmodel_points, int nthetas, int nparams);\n\nvoid makeCovMatrix_fnptr(gsl_matrix *cov_matrix, gsl_matrix *xmodel, gsl_vector* thetas, int nmodel_points, int nthetas, int nparams, \n\t\t\t\t\t\t\t\t\t\t\t\t double (*covariance_fn_ptr)(gsl_vector*, gsl_vector*, gsl_vector*, int, int));\n\n\ndouble makeEmulatedMean(gsl_matrix *inverse_cov_matrix, gsl_vector *training_vector, gsl_vector *kplus_vector, gsl_vector* h_vector, gsl_matrix* h_matrix, gsl_vector* beta_vector, int nmodel_points);\n\ndouble makeEmulatedVariance(gsl_matrix *inverse_cov_matrix, gsl_vector *kplus_vector, gsl_vector *h_vector, gsl_matrix *h_matrix, double kappa, int nmodel_points, int nregression_fns);\n\n\n\nvoid initialise_new_x(gsl_matrix* new_x, int nparams, int nemulate_points, double emulate_min, double emulate_max);\n\n/* deprecated */\n/* double covariance_fn_gaussian_nondiag(gsl_vector* xm, gsl_vector*xn, gsl_vector*thetas, int nthetas, int nparams); */\n/* double covariance_fn_matern(gsl_vector *xm, gsl_vector* xn, gsl_vector* thetas, int nthetas, int nparams); */\n\n#endif\n", "meta": {"hexsha": "18c623e303a9d6dffc4dc437404c3eae19c11103", "size": 2897, "ext": "h", "lang": "C", "max_stars_repo_path": "src/libEmu/emulator.h", "max_stars_repo_name": "jackdawjackdaw/emulator", "max_stars_repo_head_hexsha": "1c11f69c535acef8159ef0e780cca343785ea004", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2.0, "max_stars_repo_stars_event_min_datetime": "2015-04-02T17:37:42.000Z", "max_stars_repo_stars_event_max_datetime": "2017-06-02T00:34:49.000Z", "max_issues_repo_path": "src/libEmu/emulator.h", "max_issues_repo_name": "MADAI/MADAIEmulator", "max_issues_repo_head_hexsha": "7d926ad04a791c7694defd88db41c13f7ee4e6aa", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/libEmu/emulator.h", "max_forks_repo_name": "MADAI/MADAIEmulator", "max_forks_repo_head_hexsha": "7d926ad04a791c7694defd88db41c13f7ee4e6aa", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1.0, "max_forks_repo_forks_event_min_datetime": "2021-01-30T16:43:33.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-30T16:43:33.000Z", "avg_line_length": 47.4918032787, "max_line_length": 200, "alphanum_fraction": 0.7759751467, "num_tokens": 774, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475762847495, "lm_q2_score": 0.7956580903722561, "lm_q1q2_score": 0.75058213110402}} |
| {"text": "#ifndef LOGSUMEXP_INCLUDED\n#define LOGSUMEXP_INCLUDED\n\n#include <limits>\n#include <gsl/gsl_vector.h>\n#include <gsl/gsl_matrix.h>\n#include <cmath>\n#include \"vguard.h\"\n\n/* uncomment to disable lookup table */\n/*\n#define LOG_SUM_EXP_SLOW\n*/\n\n/* uncomment to catch NaN errors */\n/*\n#define NAN_DEBUG\n*/\n\n#define LOG_SUM_EXP_LOOKUP_MAX 10\n#define LOG_SUM_EXP_LOOKUP_PRECISION .0001\n\n#define LOG_SUM_EXP_LOOKUP_ENTRIES (((int) (LOG_SUM_EXP_LOOKUP_MAX / LOG_SUM_EXP_LOOKUP_PRECISION)) + 1)\n\n/* comment to disable interpolation */\n#define LOG_SUM_EXP_INTERPOLATE\n\nnamespace MachineBoss {\n\nusing namespace std;\n\ntypedef double LogProb;\n\ndouble log_sum_exp_unary_slow (double x); /* does not use lookup table */\n\nstruct LogSumExpLookupTable {\n double *lookup;\n LogSumExpLookupTable();\n ~LogSumExpLookupTable();\n};\n\nextern LogSumExpLookupTable logSumExpLookupTable;\n\ninline double log_sum_exp_unary (double x) {\n /* returns log(1 + exp(-x)) for nonnegative x */\n#ifdef LOG_SUM_EXP_SLOW\n return log_sum_exp_unary_slow(x);\n#else /* LOG_SUM_EXP_SLOW */\n if (x >= LOG_SUM_EXP_LOOKUP_MAX || std::isnan(x) || std::isinf(x))\n return 0;\n if (x < 0) { /* really dumb approximation for x < 0. Should never be encountered, so issue a warning */\n cerr << \"Called log_sum_exp_unary(x) for negative x = \" << x << endl;\n return -x;\n }\n const int n = (int) (x / LOG_SUM_EXP_LOOKUP_PRECISION);\n const double f0 = logSumExpLookupTable.lookup[n];\n#ifdef LOG_SUM_EXP_INTERPOLATE\n const double dx = x - (n * LOG_SUM_EXP_LOOKUP_PRECISION);\n const double f1 = logSumExpLookupTable.lookup[n+1];\n const double df = f1 - f0;\n return f0 + df * (dx / LOG_SUM_EXP_LOOKUP_PRECISION);\n#else /* LOG_SUM_EXP_INTERPOLATE */\n return f0;\n#endif /* LOG_SUM_EXP_INTERPOLATE */\n#endif /* LOG_SUM_EXP_SLOW */\n}\n\ninline double log_sum_exp (double a, double b) {\n /* returns log(exp(a) + exp(b)) */\n double max, diff, ret;\n // Note: Infinity plus or minus a finite quantity is still Infinity,\n // but Infinity - Infinity = NaN.\n // Thus, we are susceptible to NaN errors when trying to add 0+0 in log-space.\n // To work around this, we explicitly test for a==b.\n if (a == b) { max = a; diff = 0; }\n else if (a < b) { max = b; diff = b - a; }\n else { max = a; diff = a - b; }\n ret = max + log_sum_exp_unary (diff);\n#if defined(NAN_DEBUG)\n if (std::isnan(ret)) {\n cerr << \"NaN error in log_sum_exp\" << endl;\n throw;\n }\n#endif\n return ret;\n}\n\ninline double log_sum_exp (double a, double b, double c) {\n return log_sum_exp (log_sum_exp (a, b), c);\n}\n\ninline double log_sum_exp (double a, double b, double c, double d) {\n return log_sum_exp (log_sum_exp (log_sum_exp (a, b), c), d);\n}\n\ninline double log_accum_exp (double& a, double b) {\n a = log_sum_exp (a, b);\n return a;\n}\n\ninline double log_sum_exp (double a, double b, double c, double d, double e) {\n return log_sum_exp (log_sum_exp (log_sum_exp (log_sum_exp (a, b), c), d), e);\n}\n\ninline double log_sum_exp (const vguard<double>& v) {\n double lpTot = -numeric_limits<double>::infinity();\n for (auto lp : v)\n (void) log_accum_exp (lpTot, lp);\n return lpTot;\n}\n\ninline double log_sum_exp (const vguard<vguard<double> >& v) {\n double lpTot = -numeric_limits<double>::infinity();\n for (auto lp : v)\n (void) log_accum_exp (lpTot, log_sum_exp (lp));\n return lpTot;\n}\n\ndouble log_sum_exp_slow (double a, double b); /* does not use lookup table */\ndouble log_sum_exp_slow (double a, double b, double c);\ndouble log_sum_exp_slow (double a, double b, double c, double d);\n\ndouble log_accum_exp_slow (double& a, double b);\n\ninline double log_subtract_exp (double a, double b) {\n if (a < b) {\n cerr << \"Sign error in log_subtract_exp\" << endl;\n throw;\n }\n return a + log (1. - exp(b-a));\n}\n\nvguard<LogProb> log_vector (const vguard<double>& v);\nvguard<vguard<LogProb> > log_matrix (const vguard<vguard<double> >& m);\n\nvguard<LogProb> log_gsl_vector (const gsl_vector* v);\nvguard<double> gsl_vector_to_stl (const gsl_vector* v);\n\nvguard<vguard<LogProb> > log_vector_gsl_vector (const vguard<const gsl_vector*>& v);\n\nvguard<vguard<double> > gsl_matrix_to_stl (const gsl_matrix* m);\ngsl_matrix* stl_to_gsl_matrix (const vguard<vguard<double> >& m);\n\ninline LogProb logInnerProduct (const vguard<LogProb>& v1, const vguard<LogProb>& v2) {\n LogProb lip = -numeric_limits<double>::infinity();\n for (vguard<LogProb>::const_iterator iter1 = v1.begin(), iter2 = v2.begin(); iter1 != v1.end(); ++iter1, ++iter2)\n lip = log_sum_exp (lip, *iter1 + *iter2);\n return lip;\n}\n\ninline LogProb logInnerProduct (const vguard<LogProb>& v1, const vguard<LogProb>& v2, const vguard<LogProb>& v3) {\n LogProb lip = -numeric_limits<double>::infinity();\n for (vguard<LogProb>::const_iterator iter1 = v1.begin(), iter2 = v2.begin(), iter3 = v3.begin(); iter1 != v1.end(); ++iter1, ++iter2, ++iter3)\n lip = log_sum_exp (lip, *iter1 + *iter2 + *iter3);\n return lip;\n}\n\ninline LogProb logInnerProduct (const vguard<vguard<LogProb> >& v1, const vguard<vguard<LogProb> >& v2) {\n LogProb lip = -numeric_limits<double>::infinity();\n for (vguard<vguard<LogProb> >::const_iterator iter1 = v1.begin(), iter2 = v2.begin(); iter1 != v1.end(); ++iter1, ++iter2)\n lip = log_sum_exp (lip, logInnerProduct (*iter1, *iter2));\n return lip;\n}\n\ndouble logBetaPdf (double prob, double yesCount, double noCount); // alpha = yesCount+1, beta = noCount+1\ndouble logGammaPdf (double rate, double eventCount, double waitTime); // alpha = shape = eventCount+1, beta = rate = 1/scale = 1/theta = waitTime\ndouble logDirichletPdf (const vguard<double>& prob, const vguard<double>& count); // alpha[n] = count[n] + 1\ndouble logGaussianPdf (double x, double mu, double sigma);\n\n} // end namespace\n\n#endif /* LOGSUMEXP_INCLUDED */\n", "meta": {"hexsha": "8b50bf0641ca8ddcacbf5b3458e8592ab8134e72", "size": 5758, "ext": "h", "lang": "C", "max_stars_repo_path": "src/logsumexp.h", "max_stars_repo_name": "ihh/acidbot", "max_stars_repo_head_hexsha": "4af653f38821f621a2cdf141dc27dc8d62841667", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 32.0, "max_stars_repo_stars_event_min_datetime": "2018-11-30T00:09:52.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-02T10:16:48.000Z", "max_issues_repo_path": "src/logsumexp.h", "max_issues_repo_name": "evoldoers/bossmachine", "max_issues_repo_head_hexsha": "4af653f38821f621a2cdf141dc27dc8d62841667", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 58.0, "max_issues_repo_issues_event_min_datetime": "2018-07-20T17:19:04.000Z", "max_issues_repo_issues_event_max_datetime": "2018-10-19T16:52:06.000Z", "max_forks_repo_path": "src/logsumexp.h", "max_forks_repo_name": "evoldoers/bossmachine", "max_forks_repo_head_hexsha": "4af653f38821f621a2cdf141dc27dc8d62841667", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 5.0, "max_forks_repo_forks_event_min_datetime": "2018-12-05T01:39:50.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-13T05:24:48.000Z", "avg_line_length": 33.2832369942, "max_line_length": 146, "alphanum_fraction": 0.698159083, "num_tokens": 1695, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133531922388, "lm_q2_score": 0.7981867849406659, "lm_q1q2_score": 0.7502264175073137}} |
| {"text": "/*\n * Created on: Oct. 19, 2019\n * Author: Govind\n */\n\n/*\n * standard includes */\n\t#include <stdio.h>\n\t#include <stdlib.h>\n\n/*\n * includes for GSL components\n * \t- use double precision\n */\n\t#include <gsl/gsl_vector_double.h>\n\t#include <gsl/gsl_matrix_double.h>\n\t#include <gsl/gsl_rng.h>\n\t#include <gsl/gsl_randist.h>\n\n/*\n * FUNCTIONS\n */\n\n/*\n * simple Fibonacci sequence generator function, using recursion\n * */\nsize_t fib(size_t k)\n{\n\tif (k==0)\n\t{\n\t\treturn 0;\n\t}\n\telse if (k==1)\n\t{\n\t\treturn 1;\n\t}\n\telse /* k >= 2 */\n\t{\n\t\treturn fib(k-1) + fib(k-2);\n\t}\n}\n\ngsl_matrix *embt_mm(const gsl_matrix *U, const gsl_matrix *V, size_t N)\n{\n\tgsl_matrix *W = gsl_matrix_alloc(N,N);\n\tdouble dp;\n\tdouble uk,vk;\n\n\tfor (size_t i=0; i != N; ++i)\n\t{\n\t\tfor (size_t j=0; j != N; ++j)\n\t\t{\n\t\t\t/* compute element (i,j) of W */\n\t\t\tdp = 0;\n\t\t\tfor (size_t k=0; k != N; ++k)\n\t\t\t{\n\t\t\t\tuk = gsl_matrix_get(U,i,k);\n\t\t\t\tvk = gsl_matrix_get(V,k,j);\n\t\t\t\tdp += uk*vk;\n\t\t\t}\n\t\t\tgsl_matrix_set(W,i,j,dp);\n\t\t}\n\t}\n\treturn W;\n}\n\ngsl_vector gsl_print_vector(const gsl_vector V, size_t N)\n{\n\t /* Print the vector*/\n\t for (size_t i = 0; i < N; i++)\n\t {\n\t printf (\"v_%d = %g\\n\", i, gsl_vector_get (V, i));\n\t }\n}\ngsl_matrix embt_print_matrix(const gsl_matrix V, size_t N)\n{\n\tprintf(\"Matrix m\\n\");\n\t for (size_t i=0;i!=N;i++)\n\t {\n\t for (size_t j=0;j!=N;j++)\n\t\t{\n\t\t printf(\"%f \",gsl_matrix_get(V,i,j));\n\t\t}\n\t printf(\"\\n\");\n\t }\n\t printf(\"\\n\");\n}\nint main()\n{\n\t/*\n\t * INITIALIZE PARAMETERS\n\t */\n\t\t/* vectors parameters */\n\t\tsize_t\t\tN=10; /* index type, vector sizes */\n\t\tgsl_vector *a = gsl_vector_alloc(N); /* allocate vector from heap of size N */\n\t\tgsl_vector *b = gsl_vector_alloc(N); /* allocate vector from heap of size N */\n\t\tgsl_vector *c = gsl_vector_calloc(N); /* allocate vector of size N but initialize entries to zero */\n\n\t\t/* random number generator parameters */\n\t\tconst gsl_rng_type *T;\n\t\tgsl_rng *r; /* handle for our random number generator */\n\n\t\t/* matrix parameters */\n\t\tgsl_matrix *A = gsl_matrix_alloc(N,N);\n\t\tgsl_matrix *B = gsl_matrix_alloc(N,N);\n\t\tgsl_matrix *C = gsl_matrix_calloc(N,N);\n\n\t/*\n\t * SET UP RANDOM NUMBER GENERATION\n\t */\n\t\tgsl_rng_env_setup();\n\t\tT = gsl_rng_default;\n\t\tr = gsl_rng_alloc(T);\n\n\t/*\n\t * VECTOR OPERATIONS\n\t */\n\t\t/* set the vector elements */\n\t\tfor (size_t i = 0; i != N; ++i)\n\t\t{\n\t\t\tgsl_vector_set(a, i, fib(i)); /* set element i of vector a to Fibonacci number i */\n\t\t\tgsl_vector_set(b, i, gsl_ran_flat(r,-1.0,+1.0)); /* set element of vector b to random number */\n\t\t}\n\n\t\t/* c = a + b */\n\t\tgsl_vector_add(c, a); /* c += a */\n\t\tgsl_vector_add(c, b); /* c += b */\n\n\t\t/* print results */\n\t\tfor (size_t i = 0; i != N; ++i)\n\t\t{\n\t\t\tprintf(\"i=%d, a(i)=%f, b(i)=%f, c(i)=%f\\n\", i,\n\t\t\tgsl_vector_get(a, i),\n\t\t\tgsl_vector_get(b, i),\n\t\t\tgsl_vector_get(c, i));\n\t\t}\n\n\t/*\n\t *\tMATRIX OPERATIONS - your homework!! :)\n\t */\n\t\t/* fill A with first N*N Fibonacci numbers, starting with row 1 (cols 1-10), then row 2, etc. */\n\t\tfor (size_t i=0; i != N; ++i)\n\t\t{\n\t\t\tfor (size_t j = 0; j != N; ++j)\n\t\t\t{\n\t\t\t\tgsl_matrix_set(A, i, j, (double) fib(j+i*N));\n\t\t\t}\n\t\t}\n\n\t\t/* fill B with N*N random numbers, uniformly distributed over the interval (-100, 100) */\n\t\tfor (size_t i=0; i != N; ++i)\n\t\t{\n\t\t\tfor (size_t j = 0; j != N; ++j)\n\t\t\t{\n\t\t\t\tgsl_matrix_set(B, i, j, gsl_ran_flat(r,-100.0,+100.0));\n\t\t\t}\n\t\t}\n\n\t\t/* make C the product of A and B */\n\t\tC = embt_mm(A,B,N);\n\n\n\t\t/* print the results */\n\t\tembt_print_vector(a,N);\n\t\tembt_print_vector(b,N);\n\t\tembt_print_vector(c,N);\n\t\tembt_print_matrix(A,N);\n\t\tembt_print_matrix(B,N);\n\t\tembt_print_matrix(C,N);\n\n\n\n\t/* de-allocate memory */\n\tgsl_vector_free(a);\n\tgsl_vector_free(b);\n\tgsl_vector_free(c);\n\tgsl_matrix_free(A);\n\tgsl_matrix_free(B);\n\tgsl_matrix_free(C);\n\treturn EXIT_SUCCESS;\n}\n\n", "meta": {"hexsha": "275db3fec01ca520dac1a65ad6c012bc7a97a825", "size": 3748, "ext": "c", "lang": "C", "max_stars_repo_path": "C program/DSP/GSL./Matrix_mul.c", "max_stars_repo_name": "gov466/Embedded-C", "max_stars_repo_head_hexsha": "febf81fbda55d38a587335057dd561fc486f5103", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1.0, "max_stars_repo_stars_event_min_datetime": "2021-11-02T15:42:58.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-02T15:42:58.000Z", "max_issues_repo_path": "C program/DSP/GSL./Matrix_mul.c", "max_issues_repo_name": "gov466/Embedded-C", "max_issues_repo_head_hexsha": "febf81fbda55d38a587335057dd561fc486f5103", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "C program/DSP/GSL./Matrix_mul.c", "max_forks_repo_name": "gov466/Embedded-C", "max_forks_repo_head_hexsha": "febf81fbda55d38a587335057dd561fc486f5103", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.4808743169, "max_line_length": 102, "alphanum_fraction": 0.5928495197, "num_tokens": 1267, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951025545426, "lm_q2_score": 0.8887587949656841, "lm_q1q2_score": 0.7500191944238177}} |
|
|