Skip to content

Instantly share code, notes, and snippets.

@Dris101
Dris101 / tensorMmul_bp_tests.md
Last active July 21, 2020 09:13
Various test code for tensorMmul_bp

Python code to generate random tensors and calculate tensordot and gradients using TensorFlow

import tensorflow as tf
import numpy as np
from pathlib import Path

g = tf.random.Generator.from_seed(123456)
commonSize = 2
for aRank in range(2,7):
import scala.collection.JavaConverters._
Nd4j.getRandom().setSeed(1234L)
val wInit = Nd4j.rand(5, 7)
val testInit = Nd4j.rand(7, 3, 4, 5)
// Not permuted. Works
val sd1 = SameDiff.create()
var w1 = sd1.`var`("w", wInit)
val testInputNotPermuted = sd1.constant("test_input_not", testInit)