Skip to content

Instantly share code, notes, and snippets.

@mu578
mu578 / gen.ml
Last active April 16, 2019 21:47 — forked from dbuenzli/gen.ml
OCaml simple generators
(*---------------------------------------------------------------------------
Copyright (c) 2015 Daniel C. Bünzli. All rights reserved.
Distributed under the BSD3 license, see license at the end of the file.
%%NAME%% release %%VERSION%%
---------------------------------------------------------------------------*)
(* Simple generators according to:
Kiselyov, Peyton-Jones, Sabry
Lazy v. Yield: Incremental, Linear Pretty-printing
@mu578
mu578 / btree.c
Last active November 7, 2019 20:29
btree.c
struct btree_node
{
struct btree_node * u_left;
struct btree_node * u_right;
int32_t u_data;
};
typedef struct btree_node btree_node;
typedef struct btree_node btree;
typedef struct btree_node * btree_forest;
@mu578
mu578 / pseudo_rdforest.c
Last active August 24, 2022 03:58
pseudo_rdforest represented as vector for very small dataset not recommended due to memory...
# define BINARYTREE_MAXDEPTH 1024
# define RDFOREST_MAXTREE 216
# define RDFOREST_MAXSELECTION 512
# define RDFOREST_MAXBAG 128
struct btree
{
int32_t u_data[BINARYTREE_MAXDEPTH];
int32_t u_length;
};
@mu578
mu578 / pthread_cond_timedwait_nanoseconds.h
Created December 10, 2020 19:25
pthread_cond_timedwait example
static inline
void timeval_to_timespec(const struct timeval * tv, struct timespec * ts)
{
ts->tv_sec = tv->tv_sec;
ts->tv_nsec = tv->tv_usec * 1000;
}
static inline
void timespec_to_timeval(const struct timespec * ts, struct timeval * tv)
{
template <class T
//cpp11 , typename std::enable_if<std::is_floating_point<T>::value>::type* = nullptr
>
T fma(const T& x, const T& y, const T& z)
{
const T cs = TwoProduct<T>::split_value;
T s = z, w = T(0), h, q, r, x1, x2, y1, y2;
// can be a loop where x and y are values at index and w, s are accumulators. fmav.
@mu578
mu578 / modern_depravity.c
Last active October 9, 2021 20:54
No comment.
// ML Reminder, educational.
static
float __linear_learner_gradient_descent(
const unsigned int n
, const float * x
, const float * y
, const float rate
, float * a
, float * b
@mu578
mu578 / rotate_forward.c
Last active February 12, 2023 19:25
rotate_forward.c
#include <stdio.h>
#include <stdlib.h>
# define stl_scope_begin do {
# define stl_scope_end break; } while (0)
# define stl_basic_swap(_Tp, __a, __b) \
stl_scope_begin \
_Tp __stl_c = (__a); \
(__a) = (__b); \
import numpy as np
class pca:
def __svd_thin(self, a):
u, s, vh = np.linalg.svd(a, full_matrices=False, compute_uv=True)
return ( u, s, vh.T )
def __eig_symmetric(self, a):
c = np.dot(a.T, a) / (a.shape[0] - 1)
e, v = np.linalg.eig(c)
#include <io.h>
#include <fileapi.h>
#include <string.h>
static int errno_table[] =
{
0
, EINVAL /* ERROR_INVALID_FUNCTION, 1 */
, ENOENT /* ERROR_FILE_NOT_FOUND, 2 */
, ENOENT /* ERROR_PATH_NOT_FOUND, 3 */
// flock_win32.h
# ifndef LOCK_SH
# define LOCK_SH 1
# define LOCK_EX 2
# define LOCK_NB 4
# define LOCK_UN 8
# endif
int __cdecl flock(int fd, int operation);