Skip to content

Instantly share code, notes, and snippets.

View DoctorKey's full-sized avatar

Guo-Hua Wang DoctorKey

View GitHub Profile
@DoctorKey
DoctorKey / voc_ap.py
Created November 9, 2020 08:15
VOC2012 mAP
def VOCap(rec, prec):
length = len(rec)
mrec = np.zeros(length + 2)
mrec[-1] = 1
mpre = np.zeros(length + 2)
for i in range(length, 0, -1):
mpre[i] = max(prec[i-1], mpre[i+1])
mrec[i] = rec[i - 1]
mpre[0] = max(0, mpre[1])
i = np.where(mrec[1:] != mrec[:-1])[0] + 1
@DoctorKey
DoctorKey / deviceQuery.cu
Created October 10, 2017 07:57
print the gpu device. I use this to test CUDA_VISIBLE_DEVICES
#include <stdio.h>
int main()
{
int deviceCount;
cudaGetDeviceCount(&deviceCount);
int device;
for(device = 0; device < deviceCount; ++device) {
cudaDeviceProp deviceProp;
cudaGetDeviceProperties(&deviceProp, device);
/*
* How to compile (assume cuda is installed at /usr/local/cuda/)
* nvcc -c -I/usr/local/cuda/include svd_example.cpp
* g++ -fopenmp -o a.out svd_example.o -L/usr/local/cuda/lib64 -lcudart -lcublas -lcusolver
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@DoctorKey
DoctorKey / eigenvalue.cpp
Created October 10, 2017 01:44
this demo use Eigen to solve eigenvalue.
#include <Eigen/Eigenvalues>
#include <iostream>
using namespace std;
using namespace Eigen;
void test() {
MatrixXd A = MatrixXd::Random(6,6);
cout << "here is a random 6*6 matrix, A:" << endl << A << endl << endl;
EigenSolver<MatrixXd> es(A);
@DoctorKey
DoctorKey / eigenvalue.cpp
Created October 10, 2017 01:44
this demo use Eigen to solve eigenvalue.
#include <Eigen/Eigenvalues>
#include <iostream>
using namespace std;
using namespace Eigen;
void test() {
MatrixXd A = MatrixXd::Random(6,6);
cout << "here is a random 6*6 matrix, A:" << endl << A << endl << endl;
EigenSolver<MatrixXd> es(A);
Account = {
balance = 0
}
function Account:new(o)
o = o or {}
setmetatable(o, self)
self.__index = self
return o
end
Account = {
balance = 0,
withdraw = function(self, v)
self.balance = self.balance - v
end
}
function Account:deposit(v)
self.balance = self.balance + v
end
Account = {
balance = 0
}
function Account:withdraw (v)
self.balance = self.balance - v
end
Account.withdraw(Account, 100)
print(Account.balance)
function getlooplen(n)
local count = 1
while n ~= 1 do
count = count + 1
if n % 2 == 0 then
n = n / 2
else
n = 3 * n + 1
end
end
function require (name)
if not package.loaded[name] then
local loader = findloader(name)
if loader == nil then
error()
end
package.loaded[name] = true
local res = loader(name)
if res ~= nil then
package.loaded[name] = res