Skip to content

Instantly share code, notes, and snippets.

View chenzhaiyu's full-sized avatar
👨‍💻

Zhaiyu Chen chenzhaiyu

👨‍💻
View GitHub Profile
@chenzhaiyu
chenzhaiyu / inspect_gpus.py
Last active March 8, 2023 14:27
Inspect GPU usage by docker container and stop greedy containers if needed
import os
import re
if __name__ == '__main__':
# get GPUs status
processes = os.popen("nvidia-smi | grep -w 'C'").read().strip().split("\n")
# occupancy dict by GPU index
occupancy = {str(i): [] for i in range(8)}
@chenzhaiyu
chenzhaiyu / alpha_shape_3D.py
Last active July 2, 2020 15:29
3D Alpha Shape
from scipy.spatial import Delaunay
import numpy as np
from collections import defaultdict
def alpha_shape_3D(pos, alpha):
"""
Compute the alpha shape (concave hull) of a set of 3D points.
Parameters:
pos - np.array of shape (n,3) points.
alpha - alpha value.
@chenzhaiyu
chenzhaiyu / 3d_trans.py
Created December 3, 2019 20:47
3D Similarity Transformation
import numpy as np
def trans(coordinates_to_go, scale, ta, tb, tc, theta, phi, gamma):
"""
:param coordinates_to_go: [x, y, z].T
:param scale:
:param ta:
:param tb:
:param tc:
@chenzhaiyu
chenzhaiyu / point2line.py
Last active July 2, 2020 15:27
Calculate the shortest distance from a point to a line segment
import math
# 3D Case
def dot3d(v, w):
x, y, z = v
X, Y, Z = w
return x * X + y * Y + z * Z
def length3d(v):