Skip to content

Instantly share code, notes, and snippets.

View yang-song's full-sized avatar

Yang Song yang-song

View GitHub Profile
@yang-song
yang-song / grad_lib.py
Last active August 8, 2022 19:38
L operator and R operator in Tensorflow
import tensorflow as tf
def gradients(f, x, grad_ys=None):
'''
An easier way of computing gradients in tensorflow. The difference from tf.gradients is
* If f is not connected with x in the graph, it will output 0s instead of Nones. This will be more meaningful
for computing higher-order gradients.
* The output will have the same shape and type as x. If x is a list, it will be a list. If x is a Tensor, it
@tylerneylon
tylerneylon / learn.lua
Last active May 16, 2024 05:47
Learn Lua quickly with this short yet comprehensive and friendly script. It's written as both an introduction and a quick reference. It's also a valid Lua script so you can verify that the code does what it says, and learn more by modifying and running this script in your Lua interpreter.
-- Two dashes start a one-line comment.
--[[
Adding two ['s and ]'s makes it a
multi-line comment.
--]]
----------------------------------------------------
-- 1. Variables and flow control.
----------------------------------------------------