2026年第一篇博客
时隔4年,可以把这个博客网站复活了。
时隔4年,可以把这个博客网站复活了。
构建复数Complex类的思考路程:
#ifndef __COMPLEX__
#define __COMPLEX__
#include <iostream> //实际上include不一定要写在前面,只要在函数外面就行
using std::ostream;
class complex
{
public:
complex (double r = 0, double i = 0) : re(r), im(i){}
complex& operator += (const complex&);
double real() const {return re;}
double imag() const {return im;}
private:
double re, im;
friend complex& __doapl(complex*, const complex);
};
#endif
//do assignment-plus,函数中想直接取得re和im,所以声明成友元函数
complex& __doapl(complex* ths, const complex r){
ths->re += r.re;
ths->im += r.im;
return *ths;
}
inline complex& complex::operator += (const complex& r){
return __doapl(this, r);
}
//非成员函数
//把+不设计为成员函数是因为不只是复数加复数,还可以是实数加复数
inline complex operator + (const complex& x, const complex& y){
return complex(x.real() + y.real(), x.imag() + y.imag());
}
inline complex operator + (const complex& x, double y){
return complex(x.real() + y, x.imag());
}
//操作符重载只能用在左边的变量上
inline complex operator + (double x, const complex& y){
return complex(x + y.real(), y.imag());
}
//由于希望能够连用,如cout << c1 << endl; 所以有返回值
ostream& operator << (ostream& os, const complex& x){
return os << '(' << x.real() << x.imag() << ')';
}知识点
滑动窗口每次做完,过一段时间又忘了,所以还是需要在一起总结一下。
参考资料:https://leetcode-cn.com/problems/longest-substring-with-at-most-two-distinct-characters/solution/hua-dong-chuang-kou-zhen-di-jian-dan-yi-73bii/
不从算法层面讨论,而看看python实现上怎么写。
sorted(d.items(),key=lambda x:x[1])给一非空的单词列表,返回前 k 个出现次数最多的单词。
感觉最近训练模型的时候,GPU利用率经常是间断出现0%,试了很多方法比如dataloader的多个worker,prefetch,感觉速度没达到预期,而且依然会出现0%的情况,所以使用LMDB试试能不能提升效率。