Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Following [[C. Trabelsi et al., International Conference on Learning Representat
* Relu (ℂRelu)
* Sigmoid
* Tanh
* softmax
* Dropout2d
* BatchNorm1d (Naive and Covariance approach)
* BatchNorm2d (Naive and Covariance approach)
Expand Down
9 changes: 9 additions & 0 deletions complexPyTorch/complexFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
relu,
sigmoid,
tanh,
softmax,
)


Expand Down Expand Up @@ -209,3 +210,11 @@ def complex_dropout2d(inp, p=0.5, training=True):
mask = dropout2d(mask, p, training) * 1 / (1 - p)
mask.type(inp.dtype)
return mask * inp

def complex_softmax(inp, dim):
"""
Perform complex softmax.
"""
real_softmax = softmax(inp.real, dim=dim)
imag_softmax = softmax(inp.imag, dim=dim)
return real_softmax.type(torch.complex64) + 1j * imag_softmax.type(torch.complex64)