Skip to content

Instantly share code, notes, and snippets.

@guodongxiaren
guodongxiaren / .gdbinit
Created June 11, 2023 04:29
GDB coredump调试美化输出
# 保存到 ~/.gdbinit
python
import sys
sys.path.insert(0, '/usr/share/gcc-4.8.2/python') # 这个路径以实际情况为准
from libstdcxx.v6.printers import register_libstdcxx_printers
register_libstdcxx_printers (None)
end
#
# STL GDB evaluators/views/utilities - 1.03
@nikola-j
nikola-j / atan2.py
Last active September 22, 2023 02:51
Atan2 pytorch onnx
def my_atan2(y, x):
pi = torch.from_numpy(np.array([np.pi])).to(y.device, y.dtype)
ans = torch.atan(y / (x + 1e-6))
ans += ((y > 0) & (x < 0)) * pi
ans -= ((y < 0) & (x < 0)) * pi
ans *= (1 - ((y > 0) & (x == 0)) * 1.0)
ans += ((y > 0) & (x == 0)) * (pi / 2)
ans *= (1 - ((y < 0) & (x == 0)) * 1.0)
ans += ((y < 0) & (x == 0)) * (-pi / 2)
return ans
@pcyin
pcyin / log_sum_exp.py
Created September 7, 2018 14:29
Pytorch masked `log_sum_exp`
def log_sum_exp(inputs, keepdim=False, mask=None):
"""Numerically stable logsumexp on the last dim of `inputs`.
reference: https://github.com/pytorch/pytorch/issues/2591
Args:
inputs: A Variable with any shape.
keepdim: A boolean.
mask: A mask variable of type float. It has the same shape as `inputs`.
**ATTENTION** invalid entries are masked to **ONE**, not ZERO
Returns:
Equivalent of log(sum(exp(inputs), keepdim=keepdim)).
@mbinna
mbinna / effective_modern_cmake.md
Last active May 21, 2024 08:25
Effective Modern CMake

Effective Modern CMake

Getting Started

For a brief user-level introduction to CMake, watch C++ Weekly, Episode 78, Intro to CMake by Jason Turner. LLVM’s CMake Primer provides a good high-level introduction to the CMake syntax. Go read it now.

After that, watch Mathieu Ropert’s CppCon 2017 talk Using Modern CMake Patterns to Enforce a Good Modular Design (slides). It provides a thorough explanation of what modern CMake is and why it is so much better than “old school” CMake. The modular design ideas in this talk are based on the book [Large-Scale C++ Software Design](https://www.amazon.de/Large-Scale-Soft

@gocarlos
gocarlos / Eigen Cheat sheet
Last active February 11, 2024 14:07
Cheat sheet for the linear algebra library Eigen: http://eigen.tuxfamily.org/
// A simple quickref for Eigen. Add anything that's missing.
// Main author: Keir Mierle
#include <Eigen/Dense>
Matrix<double, 3, 3> A; // Fixed rows and cols. Same as Matrix3d.
Matrix<double, 3, Dynamic> B; // Fixed rows, dynamic cols.
Matrix<double, Dynamic, Dynamic> C; // Full dynamic. Same as MatrixXd.
Matrix<double, 3, 3, RowMajor> E; // Row major; default is column-major.
Matrix3f P, Q, R; // 3x3 float matrix.
@UnaNancyOwen
UnaNancyOwen / main.cpp
Last active February 3, 2021 08:00
Draw Sine using cv::plot Module
#include <vector>
#include <cmath>
#include <opencv2/opencv.hpp>
#include <opencv2/plot.hpp>
int main( int argc, char* argv[] )
{
// Initialize Data
std::vector<double> sine;
for( int t = 0; t < 360; t++ ){
@morgangiraud
morgangiraud / nvidia-reinstall.sh
Last active December 11, 2020 15:48
Script to reinstall manually nvidia drivers,cuda 9.0 and cudnn 7.1 on Ubuntu 16.04
# Remove anything linked to nvidia
sudo apt-get remove --purge nvidia*
sudo apt-get autoremove
# Search for your driver
apt search nvidia
# Select one driver (the last one is a decent choice)
sudo apt install nvidia-370
@gnilchee
gnilchee / http_multithreaded.py
Last active March 12, 2024 13:54
Multi-threaded Python3 HTTP Server
#!/usr/bin/env python3
import sys, os, socket
from socketserver import ThreadingMixIn
from http.server import SimpleHTTPRequestHandler, HTTPServer
HOST = socket.gethostname()
class ThreadingSimpleServer(ThreadingMixIn, HTTPServer):
pass
@cdjhlee
cdjhlee / zeromq_install.sh
Last active August 24, 2021 19:37
install zeromq in ubuntu 14.04
#!/usr/bin/bash
##############################################
#from http://zeromq.org/intro:get-the-software
##############################################
#get zeromq
wget http://download.zeromq.org/zeromq-4.0.5.tar.gz
#unpack tarball package
@jstadler
jstadler / bhattacharyya
Created July 9, 2014 05:57
Implementation of the Bhattacharyya distance in Python
# bhattacharyya test
import numpy
import math
h1 = [ 1, 2, 3, 4, 5, 6, 7, 8 ];
h2 = [ 6, 5, 4, 3, 2, 1, 0, 0 ];
h3 = [ 8, 7, 6, 5, 4, 3, 2, 1 ];
h4 = [ 1, 2, 3, 4, 4, 3, 2, 1 ];
h5 = [ 8, 8, 8, 8, 8, 8, 8, 8 ];