Skip to content

Instantly share code, notes, and snippets.

View MurageKibicho's full-sized avatar
🛼
Working from home

Murage Kibicho MurageKibicho

🛼
Working from home
  • Yale University
  • New Haven, Connnecticut
  • 07:15 (UTC -04:00)
View GitHub Profile
@MurageKibicho
MurageKibicho / GPT2_1.c
Created March 27, 2025 19:29
Got to attention, just before creating function at 6.14.13
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <math.h>
#include <sys/mman.h>
#include <stdbool.h>
#include "cJSON.h"
#define VOCABULARY_SIZE 50257
@MurageKibicho
MurageKibicho / gpt.c
Created March 27, 2025 13:08
GPT in C before cahing safe tensors loading
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <sys/mman.h>
#include "cJSON.h"
#define VOCABULARY_SIZE 50257
#define tf_d_vocab 50257
#define tf_d_seq 1024
@MurageKibicho
MurageKibicho / Diffusion.c
Created March 22, 2025 03:48
Forward step Diffusion
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <assert.h>
#define PI 3.14159265358979323846
#define MIN_BETA 0.0001
#define MAX_BETA 0.9999
float DiffusionInternalSigmoid(float x)
@MurageKibicho
MurageKibicho / gist:b6520c6f66325fe13f6de47cd35e3454
Created March 21, 2025 17:52
Noise Schedules for Diffusion Models in C
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <assert.h>
#define PI 3.14159265358979323846
#define MIN_BETA 0.0001
#define MAX_BETA 0.9999
float DiffusionInternalSigmoid(float x)
@MurageKibicho
MurageKibicho / Posit.c
Created March 20, 2025 12:20
Signed Residue number system
#ifndef _FFASM_H_
#define _FFASM_H_
#ifndef ff_BITS
#define ff_BITS 32
#endif
#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
@MurageKibicho
MurageKibicho / fp.c
Created March 19, 2025 12:11
FixedPoint
// Online C compiler to run C program online
#include <stdio.h>
#include <stdint.h>
typedef int64_t fixedpt;
#define FIXEDPT_BITS 32
#define FIXEDPT_WBITS 24
#define FIXEDPT_FBITS (FIXEDPT_BITS - FIXEDPT_WBITS)
#define FIXEDPT_ONE ((fixedpt)((fixedpt)1 << FIXEDPT_FBITS))
#define fixedpt_rconst(R) ((fixedpt)((R) * FIXEDPT_ONE + ((R) >= 0 ? 0.5 : -0.5)))
@MurageKibicho
MurageKibicho / Test2PrimitiveRoot.c
Last active March 3, 2025 08:32
Check if 2 is a primitive root in gf(p)
//Code from this Murage Kibicho answer on Stack Exchange : https://math.stackexchange.com/questions/3260673/primes-having-2-as-a-primitive-root/5041497#5041497
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define TRUE 1
#define FALSE 0
int ModularExponentiation(int base, int exp, int mod)
{
@MurageKibicho
MurageKibicho / Generator.c
Created March 2, 2025 16:43
Find Generators of a fiel mod a prime number in C
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
// Function to compute (base^exp) % mod using fast modular exponentiation
long long mod_exp(long long base, long long exp, long long mod) {
long long result = 1;
while (exp > 0) {
if (exp % 2 == 1) result = (result * base) % mod;
base = (base * base) % mod;
@MurageKibicho
MurageKibicho / Blankinship.c
Created February 14, 2025 18:07
Blankinship's algorothm for integers
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <assert.h>
typedef struct blankinship_row_struct *BlankinshipRow;
typedef BlankinshipRow* BlankinshipMatrix;
struct blankinship_row_struct
{
int leader;
int numberOfColumns;
@MurageKibicho
MurageKibicho / BlankinshipGMP.c
Created February 14, 2025 18:04
Blankinship's algorithm but for big integers in C
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <assert.h>
#include <gmp.h>
//Run command : clear && gcc BlankinshipGMP.c -lgmp -lm -o m.o && ./m.o
typedef struct blankinship_row_struct *BlankinshipRow;
typedef BlankinshipRow* BlankinshipMatrix;
struct blankinship_row_struct