This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdint.h> | |
#include <float.h> | |
#include <math.h> | |
float q_pow(float x, float y) | |
{ | |
union { | |
float f; | |
uint32_t i; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//+++++++++++++++++++++++++++ PUBLIC-DOMAIN SOFTWARE ++++++++++++++++++++++++++ | |
// Functions: TransposetoAxes AxestoTranspose | |
// Purpose: Transform in-place between Hilbert transpose and geometrical axes | |
// Example: b=5 bits for each of n=3 coordinates. | |
// 15-bit Hilbert integer = A B C D E F G H I J K L M N O is stored | |
// as its Transpose | |
// X[0] = A D G J M X[2]| | |
// X[1] = B E H K N <-------> | /X[1] | |
// X[2] = C F I L O axes |/ | |
// high low 0------ X[0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef _OST_VEC_H_ | |
#define _OST_VEC_H_ | |
#include <cmath> | |
#include <string> | |
#include <algorithm> | |
#include <limits> | |
#include <tuple> | |
#include <cassert> | |
#include <iostream> | |
#include <typeinfo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Theorems: | |
1. Linear transform of a normal random variable (matrix cookbook, 8.1.4): | |
Assume: | |
X ~ N(x,Px), | |
f(v) = A*v | |
Then: | |
f(X) ~ N(A*x,A*Px*A') | |
2. Conditional Distribution (matrix cookbook, 8.1.3): | |
[X;Y]~N([x0;y_expected],[Pxx,Pxy;Pxy';Pyy]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<class MapPtr, class UnaryPredicate> | |
void stdmap_ptr_remove_if(MapPtr m, UnaryPredicate p) | |
{ | |
/* See https://stackoverflow.com/questions/800955/remove-if-equivalent-for-stdmap */ | |
for( auto it = m->begin(); it != m->end(); ) { | |
auto v=it->second; | |
if (!p(v)) { | |
++it; | |
} else { | |
delete v; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Parallel | |
T2 kdsearch (const T2 in, const T lower, const T upper) { | |
auto mid=lower+std::distance(lower,upper)/2; | |
if (lb<mid && mid<ub) { | |
auto handle=std::async(kdsearch<...>,std::get<1>(...),mid+1,upper); | |
return std::make_pair(check_and_push<check>(kdsearch<...>(std::get<0>(...),lower,mid),mid,mid+1),handle.get()); | |
} | |
return std::make_pair((lb<mid)?kdsearch<...>(std::get<0>(...),lower,mid) :std::get<0>(...), | |
(mid<ub)?kdsearch<...>(std::get<1>(...),mid+1,upper):std::get<1>(...)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//https://stackoverflow.com/questions/1797380/template-specialization-with-a-templatized-type | |
template <class T, class ForwardIterator> | |
ForwardIterator push_ordered_interval(const T first, const T last, ForwardIterator result) { | |
if (*it == first) { | |
*it=last; | |
} else { | |
*(++it)=first; | |
*(++it)=last; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Sample custom iterator. | |
// By perfectly.insane (http://www.dreamincode.net/forums/index.php?showuser=76558) | |
// From: http://www.dreamincode.net/forums/index.php?showtopic=58468 | |
#include <iostream> | |
#include <vector> | |
#include <algorithm> | |
#include <iterator> | |
#include <cassert> |