include/tenzr/modules/nn/activations.h¶
Namespaces¶
| Name |
|---|
| tenzr |
| tenzr::nn |
Classes¶
| Name | |
|---|---|
| class | tenzr::nn::ReLU Rectified linear unit activation module. |
| class | tenzr::nn::Sigmoid Logistic sigmoid activation module. |
| class | tenzr::nn::Tanh Hyperbolic tangent activation module. |
| class | tenzr::nn::SiLU SiLU (swish) activation module. |
| class | tenzr::nn::GELU Gaussian error linear unit activation module. |
| class | tenzr::nn::Softmax Softmax module normalizing over a configurable axis. |
| class | tenzr::nn::LogSoftmax Log-softmax module normalizing over a configurable axis. |
Source code¶
// Copyright 2026 The Tenzr Project Authors
//
// SPDX-License-Identifier: Apache-2.0
//
// 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
//
// https://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.
#ifndef TENZR_MODULES_NN_ACTIVATIONS_H_
#define TENZR_MODULES_NN_ACTIVATIONS_H_
#include <string>
#include "tenzr/frontend/tensor.h"
#include "tenzr/modules/nn/module.h"
namespace tenzr::nn {
class ReLU : public Module {
public:
Tensor Forward(const Tensor& input) override { return input.Relu(); }
std::string Name() const override { return "ReLU"; }
};
class Sigmoid : public Module {
public:
Tensor Forward(const Tensor& input) override { return input.sigmoid(); }
std::string Name() const override { return "Sigmoid"; }
};
class Tanh : public Module {
public:
Tensor Forward(const Tensor& input) override { return input.tanh(); }
std::string Name() const override { return "Tanh"; }
};
class SiLU : public Module {
public:
Tensor Forward(const Tensor& input) override { return input.Silu(); }
std::string Name() const override { return "SiLU"; }
};
class GELU : public Module {
public:
Tensor Forward(const Tensor& input) override { return input.Gelu(); }
std::string Name() const override { return "GELU"; }
};
Array softmax(const Array& input, int64_t axis = -1);
Array log_softmax(const Array& input, int64_t axis = -1);
class Softmax : public Module {
public:
explicit Softmax(int64_t axis = -1) : axis_(axis) {}
Tensor Forward(const Tensor& input) override { return softmax(input, axis_); }
std::string Name() const override { return "Softmax"; }
private:
int64_t axis_;
};
class LogSoftmax : public Module {
public:
explicit LogSoftmax(int64_t axis = -1) : axis_(axis) {}
Tensor Forward(const Tensor& input) override { return log_softmax(input, axis_); }
std::string Name() const override { return "LogSoftmax"; }
private:
int64_t axis_;
};
} // namespace tenzr::nn
#endif // TENZR_MODULES_NN_ACTIVATIONS_H_