# Path: networks/blocks.py
# class PeriodicEmbed(nn.Module):
#     def __init__(self, max_freq=5, N_freq=4, linspace=True):
#         super().__init__()
#         self.embed_functions = [torch.cos, torch.sin]
#         if linspace:
#             self.freqs = torch.linspace(1, max_freq + 1, steps=N_freq)
#         else:
#             exps = torch.linspace(0, N_freq - 1, steps=N_freq)
#             self.freqs = 2**exps
# 
#     def forward(self, x):
#         output = [x]
#         for f in self.embed_functions:
#             for freq in self.freqs:
#                 output.append(f(freq * x))
#         return torch.cat(output, 1)


import torch
from torch import nn
from .blocks import PeriodicEmbed
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.



class EmbededMLP(nn.Module):
    def __init__(self, in_ch=3, out_ch=3, depth=3, width=64, N_freq=8, skip=3, act_fn=nn.functional.leaky_relu, output_act=None, norm=None, init_val=None):
        super().__init__()

# Path: networks/blocks.py
# class PeriodicEmbed(nn.Module):
#     def __init__(self, max_freq=5, N_freq=4, linspace=True):
#         super().__init__()
#         self.embed_functions = [torch.cos, torch.sin]
#         if linspace:
#             self.freqs = torch.linspace(1, max_freq + 1, steps=N_freq)
#         else:
#             exps = torch.linspace(0, N_freq - 1, steps=N_freq)
#             self.freqs = 2**exps
# 
#     def forward(self, x):
#         output = [x]
#         for f in self.embed_functions:
#             for freq in self.freqs:
#                 output.append(f(freq * x))
#         return torch.cat(output, 1)


# Path: networks/MLP.py
import torch
from torch import nn
from .blocks import PeriodicEmbed

# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.



class EmbededMLP(nn.Module):
    def __init__(self, in_ch=3, out_ch=3, depth=3, width=64, N_freq=8, skip=3, act_fn=nn.functional.leaky_relu, output_act=None, norm=None, init_val=None):
        super().__init__()

        self.embed = PeriodicEmbed(N_freq=N_freq, linspace=False)