Skip to content

Instantly share code, notes, and snippets.

View ZJUGuoShuai's full-sized avatar

Guo Shuai ZJUGuoShuai

  • ByteDance
  • Hangzhou, China
  • 12:31 (UTC +08:00)
View GitHub Profile
@ZJUGuoShuai
ZJUGuoShuai / move_ctor_called_once.md
Created May 17, 2023 11:20
关于移动构造函数被调用次数的疑惑

关于移动构造函数被调用次数的疑惑

代码 1:

基本信息:

  • class A 具有拷贝构造和移动构造;
  • class B 支持从 A 构造。

main 中,尝试从一个 A 对象 a 构造一个 B 对象 b

@ZJUGuoShuai
ZJUGuoShuai / my_split.cc
Created May 17, 2023 08:40
C++ 实现类似 Python 字符串的 split 函数
#include <iostream>
#include <string>
#include <vector>
std::vector<std::string> split_naive(const std::string& s, char delim) {
std::vector<std::string> ret;
std::string token;
for (char ch : s) {
if (ch == delim) {
ret.push_back(token);
@ZJUGuoShuai
ZJUGuoShuai / nasa_aod.py
Last active September 2, 2022 07:00
用于处理 NASA AOD 数据/可视化的脚本
import time
import h5py
import matplotlib.pyplot as plt
import numpy as np
def timer(func):
"""给函数计时的装饰器"""

对 C/C++ 中 inline 的疑惑

我的疑惑开始于这篇文章,它说 C 语言中的 inline 函数是 static linkage,而 C++ 中的 inline 函数则是 external linkage。我第一次知道,原来 C 和 C++ 中的 inline 有如此的不同。于是,我尝试了这篇文章中的一个小实验。

有下面两个源文件:

// A.c
#include <stdio.h>
@ZJUGuoShuai
ZJUGuoShuai / .latexmkrc
Created March 22, 2022 12:53
我的 .latexmkrc 配置文件
# 使用 XeLaTeX 作为默认编译器,同时打开 nonstopmode 选项
$pdflatex = "xelatex -shell-escape -interaction=nonstopmode %O %S";
# 只生成 PDF 文件,不生成 DVI 和 PostScript 文件
$pdf_mode = 1;
$dvi_mode = 0;
$postscript_mode = 0;
#include "NexusCpp.hpp"
// 一些全局变量
constexpr int N = 16; // batch size
constexpr int C = 1; // channels 通道数
constexpr int H = 224; // 图像的高
constexpr int W = 224; // 图像的宽
constexpr int NCLASS = 10; // 分类的总类别数
auto DATASHAPE = TShape({N, C, H, W}); // 输入图像的形状
@ZJUGuoShuai
ZJUGuoShuai / Dockerfile
Created September 6, 2021 08:55
Nexus 镜像制作(服务镜像、在线编程镜像还没做)
# NexusNet 镜像(CUDA 11.4,要求 Nvidia 驱动版本 >=470.57.02)
# 作者:郭帅
# =====================================================================================
# [1] nexus-base :编译 NexusNet 源码所需的环境,包括 CUDA/cuDNN/OpenCV/Protobuf 以及其他软件
FROM nvidia/cuda:11.4.1-cudnn8-devel-ubuntu20.04 AS nexus-base
# 更改 APT 源为阿里镜像站
RUN echo "\
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse\n\
@ZJUGuoShuai
ZJUGuoShuai / convert.py
Created July 8, 2021 02:06
PyTorch 到 Nexus 转换脚本
import re
import sys
try:
from parse import parse
except ImportError:
print("You should install parse first.\n $ pip install --user parse")
sys.exit(1)
# PyTorch module 到 Nexus Symbol 的映射
@ZJUGuoShuai
ZJUGuoShuai / pg1.py
Created March 31, 2021 14:55
最基础的 Policy Gradient(PyTorch 实现)
import torch
import torch.nn as nn
from torch.distributions.categorical import Categorical
from torch.optim import Adam
import numpy as np
import gym
from gym.spaces import Discrete, Box
def mlp(sizes, activation=nn.Tanh, output_activation=nn.Identity):
# 构建一个前向神经网络