Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # shape: C x F/2
- # output = self.permutations: [num_copies x cell_size]
- permutations = []
- indices = numpy.arange(self._dim / 2) #[1 ,2 ,3 ...64]
- for i in range(self._num_copies):
- numpy.random.shuffle(indices) #[4, 48, 32, ...64]
- permutations.append(numpy.concatenate(
- [indices,
- [ind + self._dim / 2 for ind in indices]]))
- #you're appending a row with two columns -- a permutation in the first column, and the same permutation + dim/2 for imaginary
- # C x F (numpy)
- self.permutations = tf.constant(numpy.vstack(permutations), dtype = tf.int32) #This is a permutation tensor that has the stored permutations
- # output = self.permutations: [num_copies x cell_size]
- def permute(complex_tensor): #complex tensor is [batch_size x cell_size]
- gather_tensor = tf.gather_nd(complex_tensor, self.permutations)
- return gather_tensor
- def permute(self, complex_tensor):
- inputs_permuted = []
- for i in range(self.permutations.get_shape()[0].value):
- inputs_permuted.append(
- tf.gather(complex_tensor, self.permutations[i]))
- return tf.concat(0, inputs_permuted)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement