Skip to content

Instantly share code, notes, and snippets.

View sjhalayka's full-sized avatar

Shawn Halayka sjhalayka

View GitHub Profile
@sjhalayka
sjhalayka / makefile
Created March 26, 2025 15:47
LDAK makefile
# Makefile for LDAK 6.1
# Compiler and flags
CC = gcc
CFLAGS = -O3 -fopenmp
LDFLAGS = -lblas -llapack -lm -lz
# Source and output files
SRC = ldak_nomkl.c
TARGET = ldak6.1
@sjhalayka
sjhalayka / PGENLIB_test.cpp
Created February 28, 2025 01:48
Read code.
#include "pgenlib_read.h"
#include "pgenlib_write.h"
#ifdef __cplusplus
using namespace plink2;
#endif
int32_t main(int32_t argc, char** argv)
{
PglErr reterr = kPglRetSuccess;
Declaration count: 1697
Pointer declaration count: 640
Variables used: 477
Y:/home/sjhalayka/ldak_min\dataops.c::44aReRrHiwCUC3xI::indexer
Y:/home/sjhalayka/ldak_min\dataops.c
Y:/home/sjhalayka/ldak_min\dataops.c::44aReRrHiwCUC3xI::wantpreds
@sjhalayka
sjhalayka / code.cpp
Created February 22, 2025 01:31
pointer usage with vector<vector<type>> etc
int read_data_fly(char* datafile, int dtype, double* data, float** probs,
int num_samples_use, int* keepsamps, int start, int end,
int* keeppreds_use, gzFile inputgz, size_t current,
int num_samples, int num_preds, int genskip, int genheaders,
int genprobs, size_t* bgen_indexes, double missingvalue,
double threshold, double minprob, int nonsnp,
int maxthreads)
{
int thread;
@sjhalayka
sjhalayka / template_usage_examples.cpp
Created February 21, 2025 17:31
C++ template usage examples
#include <iostream>
#include <vector>
using namespace std;
// C way -- make one function for each type
double c_function(const double x)
{
return x;
}
@sjhalayka
sjhalayka / vector_to_pointer2.cpp
Created February 17, 2025 16:53
C++ vectors to pointers
#include <iostream>
#include <string>
#include <vector>
#include <memory>
using namespace std;
template<class T>
void test_function(T ***c, const size_t size_x, const size_t size_y, const size_t size_z)
{
@sjhalayka
sjhalayka / vector_to_pointer.cpp
Created February 17, 2025 16:51
c++ vectors to pointers
#include <iostream>
#include <string>
#include <vector>
#include <memory>
using namespace std;
template<class T>
void test_function(T ***c, const size_t size_x, const size_t size_y, const size_t size_z)
{
template <typename size_t N>
double determinant_nxn(const MatrixXd& m)
{
if (m.cols() != m.rows())
{
cout << "Matrix must be " << N << "x" << N << endl;
return 0;
}
Vector_nD<N> a_nd;
double determinant(const Matrix3d& m)
{
// https://textbooks.math.gatech.edu/ila/determinants-volumes.html
// https://copilot.microsoft.com/chats/qQxM5K1jer1Dc6pMtuDfD
Vector3d a;
a(0) = m(0, 0);
a(1) = m(0, 1);
a(2) = m(0, 2);
#include <iostream>
#include <vector>
#include <Eigen/Dense>
using namespace Eigen;
// Function to fit an ellipse using Gauss method
void fitEllipse(const std::vector<double>& x, const std::vector<double>& y) {
int n = x.size();
if (n < 5) {