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 boto3 | |
| class Session(boto3.Session): | |
| def __enter__(self): | |
| return self | |
| def __exit__(self, *args): | |
| del self | |
| with Session() as sess: | |
| # get names of regions |
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
| # dependencies | |
| import re | |
| import os | |
| import argparse | |
| import torch | |
| from tqdm import tqdm | |
| #import cv2 | |
| import numpy as np | |
| import torch.utils.data | |
| import torchnet as tnt |
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 torch | |
| if __name__ == '__main__': | |
| X = torch.randn(100) | |
| out_shape = (100,100) | |
| idxs = torch.randint(high=100, size=out_shape).long() | |
| assert torch.abs(X[idxs] - X.index_select(0, idxs.view(-1)).view(*out_shape)).max() < 1e-3 | |
| from timeit import timeit | |
| setup = 'import torch; X = torch.randn(100); out_shape=(100,100); idxs = torch.randint(high=100, size=out_shape).long()' | |
| print("X[idxs]: ", timeit("_ = X[idxs]", setup=setup, number=100)) |
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
| # implementation of https://arxiv.org/abs/1504.04788 | |
| import torch | |
| import torch.nn as nn | |
| import torch.nn.functional as F | |
| import xxhash | |
| class HashFunction(object): | |
| """Hash function as described in the paper, maps a key (i,j) to a natural number | |
| in {1,...,K_L}""" |
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 torch | |
| import torch.nn as nn | |
| import torch.optim as optim | |
| import torch.nn.functional as F | |
| import numpy as np | |
| from scipy import optimize | |
| from obj import PyTorchObjective |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 torch | |
| from functools import reduce | |
| import math | |
| def is_power(n): | |
| # https://stackoverflow.com/a/29480710/6937913 | |
| n = n/2 | |
| if n == 2: | |
| return True | |
| elif n > 2: |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 random | |
| from io import StringIO | |
| def write_bitstream(fname, bits): | |
| # bits are a string of ones and zeros, based on this | |
| # stackoverflow answer: https://stackoverflow.com/a/16888829/6938913 | |
| # was broken due to utf-8 encoding using up to 4 bytes: https://stackoverflow.com/a/33349765/6937913 | |
| sio = StringIO(bits) | |
| with open(fname, 'wb') as f: | |
| while 1: |