Skip to content
Merged
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
33 changes: 33 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Checked monthly, with at most one grouped pull request per ecosystem.
# For now only github-actions opens any: see the comment on the pip entry.
version: 2
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: monthly
commit-message:
prefix: ci
groups:
github-actions:
patterns: ["*"]

# pyproject.toml and docs/requirements.txt only set lower bounds, and there is
# no lockfile. increase-if-necessary leaves a requirement unchanged while it
# allows the new release, and a lower bound allows every release, so this
# entry opens no version-update pull requests for now. It takes effect once a
# pin or an upper bound is added, and such a pull request may raise the lower
# bound too: tensorflow>=2.15 must stay, because TensorFlow 2.15 is how
# Keras 2 users run this package.
- package-ecosystem: pip
directories:
- /
- /docs
schedule:
interval: monthly
versioning-strategy: increase-if-necessary
commit-message:
prefix: build
groups:
python:
patterns: ["*"]
63 changes: 63 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
Tests:
- changed-files:
- any-glob-to-any-file: [ "tests/**/*" ]

Dependencies:
- changed-files:
- any-glob-to-any-file:
- "requirements.txt"
- "setup.py"
- "pyproject.toml"
- "poetry.lock"
- "pixi.toml"
- "pixi.lock"
- "Pipfile"
- "Pipfile.lock"
- "requirements/*.txt"
- "requirements/*.in"

Build:
- changed-files:
- any-glob-to-any-file:
- "Dockerfile*"
- "docker-compose*.yml"
- "Makefile"

Documentation:
- changed-files:
- any-glob-to-any-file:
- "docs/**/*"
- "*.md"
- "*.rst"

Config:
- changed-files:
- any-glob-to-any-file:
- ".pre-commit-config.yaml"
- "config/**/*"
- "settings/**/*"
- "*.ini"
- "*.cfg"
- "*.conf"

CI/CD:
- changed-files:
- any-glob-to-any-file:
- ".github/**/*"
- "tox.ini"
- ".coveragerc"

# Add 'feature' label to any PR where the head branch name starts with `feature` or has a `feature` section in the name
feature:
- head-branch:
- '^feature'
- 'feature'

# Add 'bugfix' label to branches with bug/fix/hotfix prefixes
bugfix:
- head-branch: [ '^bug', '^fix', '^hotfix' ]

# Add 'breaking' label for major version bumps or breaking change commits
breaking:
- title: [ '^BREAKING CHANGE', 'BREAKING-CHANGE' ]
- body: [ 'BREAKING CHANGE:', 'BREAKING-CHANGE:' ]
12 changes: 12 additions & 0 deletions .github/workflows/labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: "Pull Request Labeler"
on:
- pull_request_target

jobs:
labeler:
permissions:
contents: read
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: actions/labeler@v7.0.0
14 changes: 12 additions & 2 deletions .github/workflows/test_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,18 @@ jobs:
- uses: astral-sh/setup-uv@v10.3.0
with:
python-version: "3.12"
# Stop on syntax errors and undefined names only.
- run: uvx flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# Run the ruff release that .pre-commit-config.yaml pins, so this job and the
# pre-commit hooks agree when pre-commit.ci updates the pin.
- name: Find the ruff version
id: ruff
run: |
version=$(grep -A1 "astral-sh/ruff-pre-commit" .pre-commit-config.yaml | sed -n "s/^ *rev: *v//p")
test -n "$version"
echo "version=$version" >> "$GITHUB_OUTPUT"
- name: ruff check
run: uvx "ruff@${{ steps.ruff.outputs.version }}" check --output-format=github .
- name: ruff format
run: uvx "ruff@${{ steps.ruff.outputs.version }}" format --check --diff .

# 0.2.3 shipped invalid metadata that pip 24.1 and later refuse to install.
# Build the package and install it the way users do before any release.
Expand Down
12 changes: 11 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Read-only checks for now; formatting and linting hooks come with the tooling update.
# Read-only checks first, then ruff lints (fixing what it safely can) and formats
# the Python files with the settings in pyproject.toml.
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0
Expand All @@ -7,3 +8,12 @@ repos:
- id: check-toml
- id: check-merge-conflict
- id: check-added-large-files
# The lint job in .github/workflows/test_python.yml reads this rev, so keep it
# on the line directly below the repo line.
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.17.0
hooks:
# Lint before formatting, as ruff recommends when fixes are on.
- id: ruff-check
args: [--fix]
- id: ruff-format
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ To turn a complex NumPy array into this format:
```python
import numpy as np

z = np.random.randn(8, 3, 3, 2) + 1j * np.random.randn(8, 3, 3, 2) # two complex channels
z = np.random.randn(8, 3, 3, 2) + 1j * np.random.randn(
8, 3, 3, 2
) # two complex channels
x = np.concatenate([z.real, z.imag], axis=-1) # shape (8, 3, 3, 4)
```

Expand Down
38 changes: 34 additions & 4 deletions complexnn/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from . import bn, conv, dense, init, norm, pool

# from . import fft
from . import bn, conv, conv_utils, dense, fft, init, norm, pool, utils
from .bn import ComplexBatchNormalization as ComplexBN
from .conv import (
ComplexConv,
Expand Down Expand Up @@ -31,3 +28,36 @@
get_realpart,
getpart_output_shape,
)

__all__ = [
"bn",
"conv",
"conv_utils",
"dense",
"fft",
"init",
"norm",
"pool",
"utils",
"ComplexBN",
"ComplexConv",
"ComplexConv1D",
"ComplexConv2D",
"ComplexConv3D",
"WeightNorm_Conv",
"ComplexDense",
"ComplexIndependentFilters",
"ComplexInit",
"IndependentFilters",
"SqrtInit",
"ComplexLayerNorm",
"LayerNormalization",
"SpectralPooling1D",
"SpectralPooling2D",
"GetAbs",
"GetImag",
"GetReal",
"get_imagpart",
"get_realpart",
"getpart_output_shape",
]
13 changes: 3 additions & 10 deletions complexnn/bn.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Note: The implementation of complex Batchnorm is based on
# the Keras implementation of batch Normalization
Expand All @@ -12,11 +11,7 @@
from tensorflow.keras.layers import InputSpec, Layer
from tensorflow.keras.utils import register_keras_serializable

from .utils import get_initializer

from .utils import _ignore_input_shape_warning

from .utils import _check_complex_axis
from .utils import _check_complex_axis, _ignore_input_shape_warning, get_initializer


def sqrt_init(shape, dtype=None):
Expand Down Expand Up @@ -336,7 +331,7 @@ def __init__(
**kwargs,
):
with _ignore_input_shape_warning(kwargs):
super(ComplexBatchNormalization, self).__init__(**kwargs)
super().__init__(**kwargs)
self.supports_masking = True
self.axis = axis
self.momentum = momentum
Expand All @@ -359,8 +354,6 @@ def __init__(
self.gamma_off_constraint = constraints.get(gamma_off_constraint)

def build(self, input_shape):
ndim = len(input_shape)

dim = input_shape[self.axis]
if dim is None:
raise ValueError(
Expand Down Expand Up @@ -583,5 +576,5 @@ def get_config(self):
"gamma_diag_constraint": constraints.serialize(self.gamma_diag_constraint),
"gamma_off_constraint": constraints.serialize(self.gamma_off_constraint),
}
base_config = super(ComplexBatchNormalization, self).get_config()
base_config = super().get_config()
return dict(list(base_config.items()) + list(config.items()))
25 changes: 12 additions & 13 deletions complexnn/conv.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import numpy as np
import tensorflow as tf
Expand Down Expand Up @@ -155,7 +154,7 @@ def conv_transpose_output_length(
):
"""Rearrange arguments for compatibility with conv_output_length."""
if dilation != 1:
msg = f"Dilation must be 1 for transposed convolution. "
msg = "Dilation must be 1 for transposed convolution. "
msg += f"Got dilation = {dilation}"
raise ValueError(msg)
# return conv_utils.deconv_length(
Expand Down Expand Up @@ -298,7 +297,7 @@ def __init__(
**kwargs,
):
with _ignore_input_shape_warning(kwargs):
super(ComplexConv, self).__init__(**kwargs)
super().__init__(**kwargs)
self.rank = rank
self.filters = filters
self.kernel_size = conv_utils.normalize_tuple(kernel_size, rank, "kernel_size")
Expand Down Expand Up @@ -647,7 +646,7 @@ def get_config(self):
"transposed": self.transposed,
"epsilon": self.epsilon,
}
base_config = super(ComplexConv, self).get_config()
base_config = super().get_config()
return dict(list(base_config.items()) + list(config.items()))


Expand Down Expand Up @@ -760,7 +759,7 @@ def __init__(
transposed=False,
**kwargs,
):
super(ComplexConv1D, self).__init__(
super().__init__(
rank=1,
filters=filters,
kernel_size=kernel_size,
Expand All @@ -784,7 +783,7 @@ def __init__(
)

def get_config(self):
config = super(ComplexConv1D, self).get_config()
config = super().get_config()
config.pop("rank")
# __init__ always passes data_format="channels_last" to ComplexConv.
config.pop("data_format")
Expand Down Expand Up @@ -916,7 +915,7 @@ def __init__(
transposed=False,
**kwargs,
):
super(ComplexConv2D, self).__init__(
super().__init__(
rank=2,
filters=filters,
kernel_size=kernel_size,
Expand All @@ -940,7 +939,7 @@ def __init__(
)

def get_config(self):
config = super(ComplexConv2D, self).get_config()
config = super().get_config()
config.pop("rank")
return config

Expand Down Expand Up @@ -1073,7 +1072,7 @@ def __init__(
transposed=False,
**kwargs,
):
super(ComplexConv3D, self).__init__(
super().__init__(
rank=3,
filters=filters,
kernel_size=kernel_size,
Expand All @@ -1097,7 +1096,7 @@ def __init__(
)

def get_config(self):
config = super(ComplexConv3D, self).get_config()
config = super().get_config()
config.pop("rank")
return config

Expand All @@ -1122,7 +1121,7 @@ def __init__(
epsilon=1e-07,
**kwargs,
):
super(WeightNorm_Conv, self).__init__(**kwargs)
super().__init__(**kwargs)
if self.rank == 1:
self.data_format = "channels_last"
self.gamma_initializer = sanitizedInitGet(gamma_initializer)
Expand All @@ -1132,7 +1131,7 @@ def __init__(
self.gamma = None

def build(self, input_shape):
super(WeightNorm_Conv, self).build(input_shape)
super().build(input_shape)
if self.data_format == "channels_first":
channel_axis = 1
else:
Expand Down Expand Up @@ -1201,7 +1200,7 @@ def get_config(self):
"gamma_constraint": constraints.serialize(self.gamma_constraint),
"epsilon": self.epsilon,
}
base_config = super(WeightNorm_Conv, self).get_config()
base_config = super().get_config()
return dict(list(base_config.items()) + list(config.items()))


Expand Down
1 change: 0 additions & 1 deletion complexnn/conv_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright 2015 The TensorFlow Authors. All Rights Reserved.
#
Expand Down
Loading
Loading