Skip to content

Instantly share code, notes, and snippets.

View octohedron's full-sized avatar

Gustavo A. Rodríguez Suárez octohedron

  • ♜♛♞
  • Valencia, Spain
  • 22:51 (UTC +01:00)
  • LinkedIn in/gstrod
View GitHub Profile
@octohedron
octohedron / femtogpt.py
Created February 22, 2023 03:52
Femto GPT
N, E, D =range,len,True; import numpy as A
def F(x):return 0.5*x*(1+A.tanh(A.sqrt(2/A.pi)*(x+0.044715*x**3)))
def G(x):B=A.exp(x-A.max(x,axis=-1,keepdims=D));return B/A.sum(B,axis=-1,keepdims=D)
def C(x,g,b,eps=1e-5):return g*(x-A.mean(x,axis=-1,keepdims=D))/A.sqrt(A.var(x,axis=-1,keepdims=D)+eps)+b
def B(x,w,b):return x@w+b
def H(x,c_fc,c_proj):return B(F(B(x,**c_fc)),**c_proj)
def I(x,c_attn,c_proj,n_head):x=B(x,**c_attn);return B(A.hstack([G([email protected]/A.sqrt(B.shape[-1])+(1-A.tri(x.shape[0],dtype=x.dtype))*-1e10)@D for(B,C,D)in zip(*list(map(lambda x:A.split(x,n_head,axis=-1),A.split(x,3,axis=-1))))]),**c_proj)
def J(x,mlp,attn,ln_1,ln_2,n_head):x=x+I(C(x,**ln_1),**attn,n_head=n_head);x=x+H(C(x,**ln_2),**mlp);return x
def K(i,wte,wpe,blocks,ln_f,n_head):
A=wte[i]+wpe[range(len(i))]
@octohedron
octohedron / SyntaxHighlighter Evolved.php
Created January 31, 2023 12:21
The fixed SyntaxHighlighter Evolved for Divi
<?php /*
**************************************************************************
Plugin Name: SyntaxHighlighter Evolved
Plugin URI: https://alex.blog/wordpress-plugins/syntaxhighlighter/
Version: 3.6.2
Description: Easily post syntax-highlighted code to your site without having to modify the code at all. Uses Alex Gorbatchev's <a href="http://alexgorbatchev.com/SyntaxHighlighter/">SyntaxHighlighter</a>. Includes a new editor block.
Author: Alex Mills (Viper007Bond)
Author URI: https://alex.blog/
@octohedron
octohedron / main.rs
Created August 17, 2022 22:05
strange transpose times
use std::time;
fn get_test_matrix() -> Vec<Vec<f64>> {
let mut x: Vec<Vec<f64>> = vec![vec![0.; 790]; 500000];
for i in 0..x.len() {
for j in 0..x[0].len() {
x[i][j] = fastrand::f64() * 500.;
}
}
x
name: Docker Image CI
env:
GIT_NAME: ${{ secrets.GIT_NAME }}
GIT_EMAIL: ${{ secrets.GIT_EMAIL }}
GIT_USER: ${{ secrets.GIT_USER }}
GIT_TOKEN: ${{ secrets.GIT_TOKEN }}
on:
push:
import pymongo
import numpy as np
from os import path
import os
from PIL import Image
import matplotlib.pyplot as plt
from collections import Counter
from wordcloud import WordCloud, STOPWORDS
d = path.dirname(__file__) if "__file__" in locals() else os.getcwd()
https://launchpad.net/~ubuntu-security/+archive/ubuntu/ppa/+build/11218704/+files/tar_1.28-2.1ubuntu0.1_arm64.deb
@octohedron
octohedron / simple_tensorflow_benchmark.py
Created February 10, 2019 20:39
Simple tensorflow GPU benchmark, prints the average time per step at the end.
# Copyright 2015 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
public class RoundedImageView extends ImageView {
public RoundedImageView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public RoundedImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public RoundedImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
# Clean the background noise, if color != black, then set to white.
for y in xrange(img.size[1]):
for x in xrange(img.size[0]):
if not(pixdata[x, y][0] &gt; threshold \
and pixdata[x, y][1] &gt; threshold \
and pixdata[x, y][2] &gt; threshold):
pixdata[x, y] = (0, 0, 0, 255)
else:
pixdata[x, y] = (255, 255, 255, 255)
#!/usr/bin/python
"""
tesseract
=========
A package for measuring the concentration of halos from Nbody simulations
non-parametrically using Voronoi tessellation.
Subpackages
-----------