pulsatrix
Loading...
Searching...
No Matches
negation_module.hpp
Go to the documentation of this file.
1
6#pragma once
7
8#include <optional>
10
11namespace pulsatrix {
12
21class NegationModule : public Module {
22public:
27 explicit NegationModule(DeviceBackend* backend);
28
38 [[nodiscard]] Tensor backward(const Tensor& grad_output) override;
39
41 [[nodiscard]] OpType op_type() const override { return OpType::Elementwise; }
42
55 [[nodiscard]] Tensor propagate_relevance(const Tensor& relevance_out, const LRPRuleConfig& config) override;
56
57
59 [[nodiscard]] std::optional<DeviceType> compute_device() const override { return backend_->device(); }
60
61protected:
62 [[nodiscard]] Tensor forward_impl(const Tensor& input) override;
63
64private:
65 DeviceBackend* backend_;
66 Tensor last_input_;
67 bool has_forwarded_ = false;
68};
69
70} // namespace pulsatrix
Vendor-agnostic compute/memory backend. CPUBackend, CUDABackend (Phase 1.5), and HIPBackend (Phase 1....
Definition device_backend.hpp:219
virtual DeviceType device() const noexcept=0
Which device this backend's buffers reside on.
Base class for every layer type (LinearModule, Conv2DModule, activations, ...).
Definition module.hpp:58
y = 1 - x, elementwise. No parameters, no parameter gradients.
Definition negation_module.hpp:21
OpType op_type() const override
Elementwise per this module's own single-input, weight-free operation.
Definition negation_module.hpp:41
Tensor forward_impl(const Tensor &input) override
The actual forward computation. Called by forward() after precondition checks.
NegationModule(DeviceBackend *backend)
Constructs a negation module.
Tensor backward(const Tensor &grad_output) override
Gradient w.r.t. this module's input: dy/dx = -1, so grad_x = -grad_output.
Tensor propagate_relevance(const Tensor &relevance_out, const LRPRuleConfig &config) override
LRP relevance propagation: pass-through, unchanged.
std::optional< DeviceType > compute_device() const override
Where this layer computes, so forward() rejects an input on another device (FND-8).
Definition negation_module.hpp:59
N-dimensional tensor. Owns its data buffer exclusively; a DeviceBackend* is injected (not owned) – th...
Definition tensor.hpp:29
Abstract base every layer subclasses – NVI forward(), pure-virtual LRP contract.
Definition acquisition_functions.hpp:16
OpType
The op-type tag a Node carries. Charter Part 2 §3: nodes are tagged by a small closed set of op types...
Definition op_type.hpp:19
Configuration for LRP relevance propagation: which rule a module applies and its hyperparameters....
Definition lrp_rule_config.hpp:57