Skip to content

Instantly share code, notes, and snippets.

View LujunWeng's full-sized avatar

LujunW LujunWeng

  • Adelaide, SA, Australia
View GitHub Profile
@LujunWeng
LujunWeng / perm_swap_recursive.cpp
Created January 21, 2019 04:06
Permutation, swap, recursive
void doPerm(vector<int>& nums, int start,
vector<vector<int>>& collector) {
if (start == nums.size())
collector.push_back(nums);
else {
for (int i = start; i < nums.size(); ++i) {
std::swap(nums[start], nums[i]);
doPerm(nums, start+1, collector);
std::swap(nums[start], nums[i]);
}
@LujunWeng
LujunWeng / gist:59661cd2a3ed78be3ad2ed07a9c8acad
Created July 20, 2017 01:16 — forked from yaroslavvb/gist:b73ff35424dd7ab762234620cf583aac
Example of restricting part of graph to run on single core
# try running cpu intensive test on two devices
import tensorflow as tf
import time
def matmul_op():
"""Multiply two matrices together"""
n = 2000
a = tf.ones((n, n), dtype=tf.float32)
@LujunWeng
LujunWeng / get_available_gpus.py
Last active July 20, 2017 00:53 — forked from jovianlin/get_available_gpus.py
Get List of Devices in TensorFlow
from tensorflow.python.client import device_lib
def get_available_device():
local_device_protos = device_lib.list_local_devices()
return local_device_protos
print(get_available_device())
# Working example for my blog post at:
# https://danijar.github.io/structuring-your-tensorflow-models
import functools
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
def doublewrap(function):
"""
A decorator decorator, allowing to use the decorator to be used without