
编程语言
smartcat2010
这个作者很懒,什么都没留下…
展开
-
VSCode里的Python import解析不到
然后选择一个python解释器即可;转载 2022-10-31 17:09:46 · 1489 阅读 · 0 评论 -
Java中的HashMap、TreeMap、ConcurrentHashMap
HashMap:JDK1.8之前:数组挂接链表;JDK1.8之后:数组挂接(链表 or 红黑树)。引入红黑树大程度优化了HashMap的性能,这主要体现在hash算法不均匀时,即产生的链表非常长,这时把链表转为红黑树可以将复杂度从O(N)降到O(lgN)当负载大于0.75之后,数组扩容(增大一倍);当某个桶的链表过长之后(超过8),链表替换成红黑树;TreeMap:1棵红黑树;有序;HashTable: 线程安全;一把大锁,低效;ConcurrentHashMap: 线程原创 2022-05-22 10:39:01 · 347 阅读 · 0 评论 -
Python里Decorator的本质
Python的修饰器的英文名叫Decorator,当你看到这个英文名的时候,你可能会把其跟Design Pattern里的Decorator搞混了,其实这是完全不同的两个东西。在认识装饰器之前,我们先来点感性认识,看一个Python修饰器的Hello World的代码。 1 2 3 4 5 6 7 8 9 10 11 12 13 下面是代码:文件名:hello.py de转载 2021-11-29 22:22:47 · 137 阅读 · 0 评论 -
右值引用,移动语义,完美转发
[c++11]我理解的右值引用、移动语义和完美转发 - 简书转载 2021-11-25 00:31:59 · 79 阅读 · 0 评论 -
unittest和coverage
pytorch里面,test代码是用import torch等操作来使用被测module的,所以我们也可以效仿之;详细资料:Coverage.py (readthedocs.org)假设my_unittest.py是测试代码,对plugin.calculator这个module进行测试,则运行下面的得到coverage数据:coverage run --source plugin.calculator my_unittest.py展示coverage数据:(Missing那列是行号)co原创 2021-01-18 22:21:31 · 347 阅读 · 0 评论 -
python写wrapper时的循环引用问题
原始链接:https://stackoverflow.com/questions/26157952/why-set-a-bound-method-to-python-object-create-a-circular-referencePytorch案例:Bug; torch/optim/lr_scheduler.py in PR原始问题:循环引用:optimizer对象-->optimizer.step(是个wrapper) --> method of 真正的optimizer.step原创 2020-11-09 17:09:19 · 242 阅读 · 0 评论 -
function和bound method的区别
Python官方文档Method被调用时,self会自动加到函数列表首位;Method就是封装了一个func和一个class object;Function的__get__可以把自己和一个class object封装到一个bounded method里面去;Python’s object oriented features are built upon a function based environment. Using non-data descriptors, the two a.转载 2020-11-09 11:32:28 · 992 阅读 · 0 评论 -
Python中的GIL
Global Interpreter Lock博文GIL是CPython解释器的特性;不是Python的特性,和编程语言无关。In CPython, the global interpreter lock, or GIL, is a mutex that prevents multiple native threads from executing Python bytecodes at once. This lock is necessary mainly because CPython’s转载 2020-08-25 08:56:02 · 209 阅读 · 0 评论 -
编译链接
Windows下使用cmake:首先要有1个CMakeLists.txt,写清楚编译哪些文件,生成哪些模块,以及其他选项;运行命令:cmake .生成.sln和.vcxproj文件;(此时就可以在Visual Studio里打开项目并运行和Debug了)默认编译成32位的;如果是要编译为64位的,则要改为运行命令:cmake . -G"Visual Studio 15 Win64"(Visual Studio 15指Visual Studio 2017);在V...原创 2020-05-16 22:46:53 · 167 阅读 · 0 评论 -
python语法
创建一个新的类(不是类的对象):type(class_name, base_class_tuple, attribute_dict)原创 2020-05-01 11:53:01 · 336 阅读 · 0 评论 -
python和C的连接
Python/C API方式#include <Python.h>int add_one(int a){ return a + 1; }static PyObject * py_add_one(PyObject *self, PyObject *args){ int num; if (!PyArg_ParseTuple(args, "i...转载 2020-04-26 20:26:27 · 297 阅读 · 0 评论 -
C++11/14语法
Move Constructor(Move构造函数)和Move Assignment Operators(Move赋值运算符)转载 2020-04-22 20:42:48 · 311 阅读 · 0 评论