最近在做图卷积相关的实验,里面涉及到图采样,该过程可以抽象为:从一个包含n个节点,m条边的图中根据一定规则采样一个连通图。由于实验使用的是FB15k-237数据集,共包含14541个节点,272115条边,每次采样30000条边,采样一次需要8s,这对于深度学习实验来说是难以接受的,会导致GPU长时间空闲。因此我开始尝试使用C/C++优化代码,虽然最后优化效果不行,但是也是对python调用C代码的一次学习,因此在此纪录一下。Python原代码 de...
Problem:
Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.
If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is.
You may not alter the values in the nodes, only nodes itself may be changed.
Only constant memory is allowed.
For example,
Given this linked list: 1->2->3->4->5
For k = 2, you should return: 2...
题目: 输入一个矩阵,按照从外向里以顺时针的顺序依次打印出每一个数字。示例 1:输入:matrix = [[1,2,3],[4,5,6],[7,8,9]]输出:[1,2,3,6,9,8,7,4,5]示例 2:输入:matrix = [[1,2,3,4],[5,6,7,8],[9,10,11,12]]输出:[1,2,3,4,8,12,11,10,9,5,6,7]来源:力扣(LeetCode)链接:https://leetcode-cn.com/problems/shun-shi-zhen-da-yin-ju-zhen-lcof思路:A00 A01 A02 A03D10E11 E12B13D20G21F22 B23C30 ...
Extest.c文件:#include <stdio.h> #include <stdlib.h>#include <string.h>#include "Python.h"#define BUFSIZE 10int fac(int n) { if (n < 2) return 1; return n * fac(n - 1);}char *reverse(char *s) { register char t; char *p = s; char *q = (s + (strlen(s) - 1)); while (p < q) { t = *p; *p++ = *q; *q-- = t; } return s;}static PyObject *Extest_fac(PyObject...
import sysdef HandleCPlusPlusComment(lines,i):index = lines[i].find("//")if index !=-1:lines[i]=lines[i][0:index]lines[i]+="\r\n"def HandleCComment(lines,i):global bhasCCommentBeginwhile True:if not bhasCCommentBegin:index = lines[i].find("/*")if index != -1:bhasCCommentBegin = Trueindex2 = lines[i].find("*/",index+2)if index2 != -1:lines[i]=lines[i][0:index]+lines[i][index2+2:-1]bhasCCommentBegin...
之前一直觉得人脸检测是非常麻烦的,即使是用opencv,麻烦到我都不敢去碰。这两天仔细看了下,如果只是调用opencv自带的分类器和函数的话,简直是简单。这不,正好最近也在学习Python,索性就用C++和Python两种语言都实现一下。当然,我现在这个是最简单的版本。步骤:调用opencv训练好的分类器和自带的检测函数检测人脸人眼等的步骤简单直接:1.加载分类器,当然分类器事先要放在工程目录中去。分类器本来的位置是在*\opencv\sour...
首先,这是自我转载:YellowTree | STbioinf的文章「在Python中调用C++模块」 在Python中成功实现了对原来C++代码模块的复用!这个好处多多,Python写得快,C++跑得快,那就是既快又快了!方法很简单,以至于我能够用一张截图记录下整个过程(点击图片看大图)!其实,注意到,必须在原来的C++代码后面添加extern “C”来辅助(C则不需要,这也是与复用C代码时最大的不同点),不然Python在调用这个构建后的动态链接库时是找不到原...
Caffe图片特征提取(Python/C++)1.Caffe特征提取(C++实现)Caffe框架提供了相应的Tools(build/tools/extract_features.bin)工具extract features,官方教程,使用方法如下:extract_features.bin xxx.caffemodel xxxx.prototxt layer-name output-path mini-batches db-style xxx.caffemodel:已训练好的模型参数 xxxx.prototxt :模型定义(包括要提取的图片的路径,mean-file等) layer_name:要提取的特征的名字(eg. fc6 f...
package com.swift;import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;publicclass Collections {publicstaticvoid main(String[] args) {/** 完成以下需求:*创建一个存储字符串的集合list,向list中添加以下字符串:”C++”、”Java”、” Python”、”大数据与云计算”。*遍历集合,将长度小于5的字符串从集合中删除。*删除成功后,打印集合中的所有元素。*PS:控制台打印示例*/List<String> ...
File "C:\Python27\lib\site-packages\wx-3.0-msw\wx\_controls.py", line 6523, in __init___controls_.DatePickerCtrl_swiginit(self,_controls_.new_DatePickerCtrl(*args, **kwargs))
wx._core.PyAssertionError: C++ assertion "strcmp(setlocale(LC_ALL, NULL), "C") == 0" failed at ..\..\src\common\intl.cpp(1449) in wxLocale::GetInfo(): You probably called setlocale() directly instead of using wxLocale and now...
《python/c++接口库比较(SWIG,boost.python, pycxx, py++, sip, Weave, Pyrex )》http://blog.csdn.net/lainegates/article/details/19565823目前有很多开源的Python/c++ 绑定工具,搜了好多岾子,这里稍微总结下。SWIG支持 Python 2 and 3配置正确的话,可以全自动完成封装(*.i文件需要自己写)当不是全自动的时候,它大多会重复你的.h文件并给出提示除了Python外,还支持其他语言(Java, Ruby, Lua, 等)输出一个本地文件(这个...
共1000万条数据,每条数据key不到15字节,value不到500字节,共占硬盘空间4.3-5GBSSDB C++ 本机set/get/del:100us/条SSDB C++ 异机set/get/del:150us/条SSDB C++ 异机get+修改+set:150us+150us+15us/条TwemProxy C++ set/get/del:300us/条SSDB Python 异机set/get/del:220us/条SSDB Python 异机get+修改+set:220us+220us+44us/条 原文:http://www.cnblogs.com/jhc888007/p/7750600.html
题目: 计算 x 的 n 次幂函数。示例 1: 输入: 2.00000, 10 输出: 1024.00000示例 2: 输入: 2.10000, 3 输出: 9.26100示例 3: 输入: 2.00000, -2 输出: 0.25000解释: 2-2 = 1/22 = 1/4 = 0.25说明: -100.0 < x < 100.0,n 是 32 位有符号整数,其数值范围是 [?231, 231 ? 1] 。来源:力扣(LeetCode)链接:https://leetcode-cn.com/problems/powx-n思路: 如果直接让x连续相乘,那么时间复杂度是O(n)。通过观察...
在程序开发过程中,程序员经常用到的一个功能就是查找引用(Find Reference),Visual Studio里面的对应功能是“查找所有引用”(Find All References)。 我在使用notepad++写代码的时候一开始一直因为找不到类似的功能而苦恼。只好每次使用“在文件中查找”(Find in files)来找到所有引用。 但是这样每次查找都需要遍历目标目录的整个文件系统,文件多的话会耗费很长时间。 notepad++有插件可以实现查找引用的功能。相比于...
Problem:
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.
You may assume no duplicates in the array.
Here are few examples.[1,3,5,6], 5 → 2[1,3,5,6], 2 → 1[1,3,5,6], 7 → 4[1,3,5,6], 0 → 0Solution:二分查找,当找不到时l=r+1,所以根据最后一次l和r的变动来判定应该插入的位置,如果最后一次是l=mid+...