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
/* | |
# Released under MIT License | |
Copyright (c) 2017 insaneyilin. | |
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and | |
associated documentation files (the "Software"), to deal in the Software without restriction, | |
including without limitation the rights to use, copy, modify, merge, publish, distribute, | |
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is | |
furnished to do so, subject to the following conditions: |
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
# 保存到 ~/.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 |
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
def tile_along_axis(x, dim, n_tile): | |
init_dim = x.size(dim) | |
repeat_idx = [1] * x.dim() | |
repeat_idx[dim] = n_tile | |
x = x.repeat(*(repeat_idx)) | |
order_index = torch.tensor( | |
torch.cat([init_dim * torch.arange(n_tile, device=x.device) + i for i in range(init_dim)]), | |
dtype=torch.long, device=x.device) | |
return torch.index_select(x, dim, order_index) |
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
#!/bin/bash | |
while true | |
do | |
x=`xdotool getmouselocation | grep -oP '(?<=x:)\d+'` | |
y=`xdotool getmouselocation | grep -oP '(?<=y:)\d+'` | |
xdotool mousemove $x $y | |
xdotool click 1 | |
sleep 1 | |
done |
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
vector <string> Names {"Karl", "Martin", "Paul", "Jennie"}; | |
vector <int> Score{45, 5, 14, 24}; | |
std::vector<int> indices(Names.size()); | |
std::iota(indices.begin(), indices.end(), 0); | |
std::sort(indices.begin(), indices.end(), | |
[&](int A, int B) -> bool { | |
return Score[A] < Score[B]; | |
}); |
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
def masked_log_softmax(input, mask, dim=1): | |
masked_input = input * mask.float() | |
max_input = torch.max(masked_input, dim=dim, keepdim=True)[0] | |
exps = torch.exp(masked_input - max_input) | |
masked_exps = exps * mask.float() | |
masked_sums = masked_exps.sum(dim, keepdim=True) | |
zeros = (masked_sums == 0) | |
masked_sums += zeros.float() | |
masked_exps += 1e-6 # avoid zero input of log. | |
return torch.log(masked_exps / masked_sums) |
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
// reference: https://ddorobot.tistory.com/entry/OpenCV-Draw-DotDash-Line | |
#include <iostream> | |
#include <vector> | |
#include <string> | |
#include <algorithm> | |
#include "opencv2/opencv.hpp" | |
void DrawDashedLine(cv::Mat& img, cv::Point pt1, cv::Point pt2, |
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
# reference: https://github.com/rlabbe/Kalman-and-Bayesian-Filters-in-Python | |
import copy | |
import numpy as np | |
from scipy.linalg import block_diag | |
from filterpy.kalman import IMMEstimator | |
from filterpy.kalman import KalmanFilter | |
from filterpy.common import Q_discrete_white_noise | |
def make_cv_filter(dt): |
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
#pragma once | |
#include <cmath> | |
// https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Welford's_online_algorithm | |
template <typename T> | |
class WelfordMeanStddevCalculator { | |
public: | |
WelfordMeanStddevCalculator() = default; | |
virtual ~WelfordMeanStddevCalculator() = default; |
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
#define MODULE_NAME "MY_LIB" | |
// __VA_ARGS__ 对应宏定义中参数列表的最后一个参数为省略号(也就是三个点) | |
// 加上##的作用在于,当可变参数的个数为0时,这里的##起到把前面多余的","去掉的作用,否则会编译出错 | |
#define error_print(fmt, ...) printf("[ERROR]["MODULE_NAME"](%s|%d)" fmt, __func__, __LINE__, ##__VA_ARGS__) | |
// 单个 # 用来把参数转换成字符串 | |
// ## 是个粘合剂,将前后两部分粘合起来,也就是有“字符化”的意思。但是“##”不能随意粘合任意字符,必须是合法的C语言标示符。在单一的宏定义中,最多可以出现一次“#”或“##”预处理操作符。 |
NewerOlder