This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Iterable | |
import numpy as np | |
from ase.io import read | |
from ase.atoms import Atoms | |
from samos.trajectory import Trajectory | |
from samos.analysis.get_gaussian_density import get_gaussian_density | |
def calculate_gaussian_density( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stdio.h" | |
__global__ void cuda_hello() { | |
printf("Hello World from GPU!\n"); | |
} | |
#define N 1000000000 | |
__global__ void vector_add(float *out, float *a, float *b, int n) { | |
for (int i = 0; i < n; i++) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import xml.etree.ElementTree as ET | |
from io import StringIO | |
import numpy as np | |
from ase import units, Atoms | |
from ase.calculators.singlepoint import SinglePointCalculator | |
def parse_qe_xml(filename): | |
tree = ET.parse(filename) | |
root = tree.getroot() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from time import perf_counter | |
class TimeMonitor: | |
def __enter__(self): | |
self.report_times = [perf_counter()] | |
self.report_tags = ["Start"] | |
return self | |
def tick(self, tag): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MEM_INFO=`nvidia-smi --query-compute-apps=pid,used_memory --format=csv,noheader` | |
output='' | |
while read -r line | |
do | |
PID=`echo $line | awk -F, '{print $1}'` | |
MEM=`echo $line | awk -F, '{print $2}'` | |
ELAPSED=`ps -p $PID -o etime --no-headers` | |
UNAME=`ps -p $PID -o user --no-headers` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Disclaimer: this is just an ugly solution to monitoring layer activations | |
# when training a model in tf keras. | |
# this code is executed right after the model is created. | |
class Callback(tf.keras.callbacks.Callback): | |
def __init__(self, logging_data): | |
super().__init__() | |
# `logging_data` is a namedtuple of the follwoing type: | |
# LoggingData = namedtuple("LoggingData", ['get_val_dataset_fn', 'get_writer_fn', 'freq']) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import pydub | |
def audiosegment2array(segment): | |
return np.array(segment.get_array_of_samples()).reshape(-1, segment.channels) | |
def array2audiosegment(array, rate=44100): | |
assert array.ndim == 2 | |
num_channels = array.shape[1] | |
array = bytes(array.astype(np.int16).reshape(-1).data) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
import matplotlib.widgets as w | |
from scipy.signal import convolve2d | |
def check(state): | |
base = [1] * 5 | |
filters = [ | |
np.array(base).reshape(5, 1), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
n = 40 | |
d = 20 | |
sigma = .05 | |
sigma2 = sigma**2 | |
X = np.random.normal(size=(n, d)) | |
Y = X.sum(axis=1, keepdims=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import math | |
import random | |
# Auto-generated code below aims at helping you parse | |
# the standard input according to the problem statement. | |
import numpy as np | |
my = np.zeros(shape=(3, 3), dtype=bool) | |
his = np.zeros(shape=(3, 3), dtype=bool) |
NewerOlder