IgANet
IGAnets - Isogeometric Analysis Networks
Loading...
Searching...
No Matches
activation.hpp
Go to the documentation of this file.
1
15#pragma once
16
17#include <iostream>
18#include <utility>
19
20#include <iganet/core/core.hpp>
21#include <iganet/utils/fqn.hpp>
22
23namespace iganet {
24
26enum class activation : short_t {
27 none = 0,
28 batch_norm = 1,
29 celu = 2,
30 elu = 3,
31 gelu = 4,
32 glu = 5,
33 group_norm = 6,
35 hardshrink = 9,
36 hardsigmoid = 8,
37 hardswish = 10,
38 hardtanh = 11,
39 instance_norm = 12,
40 layer_norm = 13,
41 leaky_relu = 14,
43 logsigmoid = 16,
44 logsoftmax = 17,
45 mish = 18,
46 normalize = 19,
47 prelu = 20,
48 relu = 21,
49 relu6 = 22,
50 rrelu = 23,
51 selu = 24,
52 sigmoid = 25,
53 silu = 26,
54 softmax = 27,
55 softmin = 28,
56 softplus = 29,
57 softshrink = 30,
58 softsign = 31,
59 tanh = 32,
60 tanhshrink = 33,
61 threshold = 34
62};
63
66public:
67 ~ActivationFunction() override = default;
68
72 virtual torch::Tensor apply(const torch::Tensor &input) const = 0;
73
76 void pretty_print(std::ostream &os) const noexcept override = 0;
77
83 virtual torch::serialize::OutputArchive &
84 write(torch::serialize::OutputArchive &archive,
85 const std::string &key) const = 0;
86
92 virtual torch::serialize::InputArchive &
93 read(torch::serialize::InputArchive &archive, const std::string &key) = 0;
94};
95
100inline std::ostream &operator<<(std::ostream &os,
101 const ActivationFunction &obj) {
102 obj.pretty_print(os);
103 return os;
104}
105
107class None : public ActivationFunction {
108public:
112 inline torch::Tensor apply(const torch::Tensor &input) const override {
113 return input;
114 }
115
118 inline void pretty_print(std::ostream &os) const noexcept override {
120 }
121
127 inline torch::serialize::OutputArchive &
128 write(torch::serialize::OutputArchive &archive,
129 const std::string &key = "none") const override {
130 archive.write(key + ".type",
131 torch::full({1}, static_cast<int64_t>(activation::none)));
132
133 return archive;
134 }
135
141 inline torch::serialize::InputArchive &
142 read(torch::serialize::InputArchive &archive,
143 const std::string &key = "none") override {
144 torch::Tensor tensor;
145
146 archive.read(key + ".type", tensor);
147 if (tensor.item<int64_t>() != static_cast<int64_t>(activation::none))
148 throw std::runtime_error("activation mismatch");
149
150 return archive;
151 }
152};
153
160public:
165 explicit BatchNorm(torch::Tensor running_mean, torch::Tensor running_var,
166 torch::nn::functional::BatchNormFuncOptions options = {})
168 running_var_(std::move(running_var)) {}
169
178 explicit BatchNorm(torch::Tensor running_mean, torch::Tensor running_var,
179 const torch::Tensor &weight, const torch::Tensor &bias,
180 double eps, double momentum, bool training = false)
181 : options_(torch::nn::functional::BatchNormFuncOptions()
182 .weight(weight)
183 .bias(bias)
184 .eps(eps)
185 .momentum(momentum)
186 .training(training)),
188 running_var_(std::move(running_var)) {}
189
190 ~BatchNorm() override = default;
191
195 inline torch::Tensor apply(const torch::Tensor &input) const override {
196 return torch::nn::functional::batch_norm(input, running_mean_, running_var_,
197 options_);
198 }
199
202 inline const torch::Tensor &running_mean() const { return running_mean_; }
203
206 inline torch::Tensor &running_mean() { return running_mean_; }
207
210 inline const torch::Tensor &running_var() const { return running_var_; }
211
214 inline torch::Tensor &running_var() { return running_var_; }
215
218 inline const torch::nn::functional::BatchNormFuncOptions &options() const {
219 return options_;
220 }
221
224 inline torch::nn::functional::BatchNormFuncOptions &options() {
225 return options_;
226 }
227
230 inline void pretty_print(std::ostream &os) const noexcept override {
231 os << utils::FullQualifiedName::name() << "(\n eps=" << options_.eps()
232 << ", momentum="
233 << options_
234 .momentum()
235#if TORCH_VERSION_MAJOR >= 2 && TORCH_VERSION_MINOR < 7
236 .value()
237#endif
238 << ", training=" << options_.training();
239
240 if (is_verbose(os)) {
241 os << "\n running_mean = " << running_mean()
242 << "\n running_var = " << running_var()
243 << "\n weight = " << options_.weight()
244 << "\n bias = " << options_.bias();
245 }
246
247 os << "\n)";
248 }
249
255 inline torch::serialize::OutputArchive &
256 write(torch::serialize::OutputArchive &archive,
257 const std::string &key = "batch_norm") const override {
258 archive.write(key + ".type", torch::full({1}, static_cast<int64_t>(
260 archive.write(key + ".running_mean", this->running_mean());
261 archive.write(key + ".running_var", this->running_var());
262 archive.write(key + ".weight", this->options_.weight());
263 archive.write(key + ".bias", this->options_.bias());
264 archive.write(key + ".eps", torch::full({1}, (double)this->options_.eps()));
265 archive.write(key + ".momentum", torch::full({1}, (double)this->options_
266 .momentum()
267#if TORCH_VERSION_MAJOR >= 2 && TORCH_VERSION_MINOR < 7
268 .value()
269#endif
270 ));
271 archive.write(key + ".training",
272 torch::full({1}, (bool)this->options_.training()));
273
274 return archive;
275 }
276
282 inline torch::serialize::InputArchive &
283 read(torch::serialize::InputArchive &archive,
284 const std::string &key = "batch_norm") override {
285 torch::Tensor tensor;
286
287 archive.read(key + ".type", tensor);
288 if (tensor.item<int64_t>() != static_cast<int64_t>(activation::batch_norm))
289 throw std::runtime_error("activation mismatch");
290
291 archive.read(key + ".running_mean", this->running_mean());
292 archive.read(key + ".running_var", this->running_var());
293 archive.read(key + ".weight", this->options_.weight());
294 archive.read(key + ".bias", this->options_.bias());
295 archive.read(key + ".eps", tensor);
296 this->options_.eps(tensor.item<double>());
297 archive.read(key + ".momentum", tensor);
298 this->options_.momentum(tensor.item<double>());
299 archive.read(key + ".training", tensor);
300 this->options_.training(tensor.item<bool>());
301
302 return archive;
303 }
304
305private:
306 torch::nn::functional::BatchNormFuncOptions options_;
308};
309
316class CELU : public ActivationFunction {
317public:
320 explicit CELU(torch::nn::functional::CELUFuncOptions options = {})
321 : options_(options) {}
322
326 explicit CELU(double alpha, bool inplace = false)
327 : options_(torch::nn::functional::CELUFuncOptions().alpha(alpha).inplace(
328 inplace)) {}
329
330 ~CELU() override = default;
331
335 inline torch::Tensor apply(const torch::Tensor &input) const override {
336 return torch::nn::functional::celu(input, options_);
337 }
338
341 inline const torch::nn::functional::CELUFuncOptions &options() const {
342 return options_;
343 }
344
347 inline torch::nn::functional::CELUFuncOptions &options() { return options_; }
348
351 inline void pretty_print(std::ostream &os) const noexcept override {
352 os << utils::FullQualifiedName::name() << "(\n alpha=" << options_.alpha()
353 << ", inplace=" << options_.inplace() << "\n)";
354 }
355
361 inline torch::serialize::OutputArchive &
362 write(torch::serialize::OutputArchive &archive,
363 const std::string &key = "celu") const override {
364 archive.write(key + ".type",
365 torch::full({1}, static_cast<int64_t>(activation::celu)));
366 archive.write(key + ".alpha",
367 torch::full({1}, (double)this->options_.alpha()));
368 archive.write(key + ".inplace",
369 torch::full({1}, (bool)this->options_.inplace()));
370
371 return archive;
372 }
373
379 inline torch::serialize::InputArchive &
380 read(torch::serialize::InputArchive &archive,
381 const std::string &key = "celu") override {
382 torch::Tensor tensor;
383
384 archive.read(key + ".type", tensor);
385 if (tensor.item<int64_t>() != static_cast<int64_t>(activation::celu))
386 throw std::runtime_error("activation mismatch");
387
388 archive.read(key + ".alpha", tensor);
389 this->options_.alpha(tensor.item<double>());
390 archive.read(key + ".inplace", tensor);
391 this->options_.inplace(tensor.item<bool>());
392
393 return archive;
394 }
395
396private:
397 torch::nn::functional::CELUFuncOptions options_;
398};
399
409class ELU : public ActivationFunction {
410public:
413 explicit ELU(torch::nn::functional::ELUFuncOptions options = {})
414 : options_(options) {}
415
419 explicit ELU(double alpha, bool inplace = false)
420 : options_(torch::nn::functional::ELUFuncOptions().alpha(alpha).inplace(
421 inplace)) {}
422
423 ~ELU() override = default;
424
428 inline torch::Tensor apply(const torch::Tensor &input) const override {
429 return torch::nn::functional::elu(input, options_);
430 }
431
434 inline const torch::nn::functional::ELUFuncOptions &options() const {
435 return options_;
436 }
437
440 inline torch::nn::functional::ELUFuncOptions &options() { return options_; }
441
444 inline void
445 pretty_print(std::ostream &os = Log(log::info)) const noexcept override {
446 os << utils::FullQualifiedName::name() << "(\n alpha=" << options_.alpha()
447 << ", inplace=" << options_.inplace() << "\n)";
448 }
449
455 inline torch::serialize::OutputArchive &
456 write(torch::serialize::OutputArchive &archive,
457 const std::string &key = "elu") const override {
458 archive.write(key + ".type",
459 torch::full({1}, static_cast<int64_t>(activation::elu)));
460 archive.write(key + ".alpha",
461 torch::full({1}, (double)this->options_.alpha()));
462 archive.write(key + ".inplace",
463 torch::full({1}, (bool)this->options_.inplace()));
464
465 return archive;
466 }
467
473 inline torch::serialize::InputArchive &
474 read(torch::serialize::InputArchive &archive,
475 const std::string &key = "elu") override {
476 torch::Tensor tensor;
477
478 archive.read(key + ".type", tensor);
479 if (tensor.item<int64_t>() != static_cast<int64_t>(activation::elu))
480 throw std::runtime_error("activation mismatch");
481
482 archive.read(key + ".alpha", tensor);
483 this->options_.alpha(tensor.item<double>());
484 archive.read(key + ".inplace", tensor);
485 this->options_.inplace(tensor.item<bool>());
486
487 return archive;
488 }
489
490private:
491 torch::nn::functional::ELUFuncOptions options_;
492};
493
502class GELU : public ActivationFunction {
503public:
504 explicit GELU() = default;
505
506 ~GELU() override = default;
507
511 inline torch::Tensor apply(const torch::Tensor &input) const override {
512 return torch::gelu(input);
513 }
514
517 inline void pretty_print(std::ostream &os) const noexcept override {
519 }
520
526 inline torch::serialize::OutputArchive &
527 write(torch::serialize::OutputArchive &archive,
528 const std::string &key = "gelu") const override {
529 archive.write(key + ".type",
530 torch::full({1}, static_cast<int64_t>(activation::gelu)));
531
532 return archive;
533 }
534
540 inline torch::serialize::InputArchive &
541 read(torch::serialize::InputArchive &archive,
542 const std::string &key = "gelu") override {
543 torch::Tensor tensor;
544
545 archive.read(key + ".type", tensor);
546 if (tensor.item<int64_t>() != static_cast<int64_t>(activation::gelu))
547 throw std::runtime_error("activation mismatch");
548
549 return archive;
550 }
551};
552
562class GLU : public ActivationFunction {
563public:
566 explicit GLU(torch::nn::functional::GLUFuncOptions options = {})
567 : options_(options) {}
568
571 explicit GLU(int64_t dim)
572 : options_(torch::nn::functional::GLUFuncOptions().dim(dim)) {}
573
574 ~GLU() override = default;
575
579 inline torch::Tensor apply(const torch::Tensor &input) const override {
580 return torch::nn::functional::glu(input, options_);
581 }
582
585 inline const torch::nn::functional::GLUFuncOptions &options() const {
586 return options_;
587 }
588
591 inline torch::nn::functional::GLUFuncOptions &options() { return options_; }
592
595 inline void pretty_print(std::ostream &os) const noexcept override {
596 os << utils::FullQualifiedName::name() << "(\n dim=" << options_.dim()
597 << "\n)";
598 }
599
605 inline torch::serialize::OutputArchive &
606 write(torch::serialize::OutputArchive &archive,
607 const std::string &key = "glu") const override {
608 archive.write(key + ".type",
609 torch::full({1}, static_cast<int64_t>(activation::glu)));
610 archive.write(key + ".dim",
611 torch::full({1}, static_cast<int>(this->options_.dim())));
612
613 return archive;
614 }
615
621 inline torch::serialize::InputArchive &
622 read(torch::serialize::InputArchive &archive,
623 const std::string &key = "glu") override {
624 torch::Tensor tensor;
625
626 archive.read(key + ".type", tensor);
627 if (tensor.item<int64_t>() != static_cast<int64_t>(activation::glu))
628 throw std::runtime_error("activation mismatch");
629
630 archive.read(key + ".dim", tensor);
631 this->options_.dim(tensor.item<int>());
632
633 return archive;
634 }
635
636private:
637 torch::nn::functional::GLUFuncOptions options_;
638};
639
643public:
646 explicit GroupNorm(int64_t num_groups)
647 : options_(torch::nn::functional::GroupNormFuncOptions(num_groups)) {}
648
651 explicit GroupNorm(torch::nn::functional::GroupNormFuncOptions options)
652 : options_(std::move(options)) {}
653
659 explicit GroupNorm(int64_t num_groups, const torch::Tensor &weight,
660 const torch::Tensor &bias, double eps)
661 : options_(torch::nn::functional::GroupNormFuncOptions(num_groups)
662 .weight(weight)
663 .bias(bias)
664 .eps(eps)) {}
665
666 ~GroupNorm() override = default;
667
671 inline torch::Tensor apply(const torch::Tensor &input) const override {
672 return torch::nn::functional::group_norm(input, options_);
673 }
674
677 inline const torch::nn::functional::GroupNormFuncOptions &options() const {
678 return options_;
679 }
680
683 inline torch::nn::functional::GroupNormFuncOptions &options() {
684 return options_;
685 }
686
689 inline void
690 pretty_print(std::ostream &os = Log(log::info)) const noexcept override {
691 os << utils::FullQualifiedName::name() << "(\n eps=" << options_.eps();
692
693 if (is_verbose(os)) {
694 os << "\n weight = " << options_.weight()
695 << "\n bias = " << options_.bias();
696 }
697
698 os << "\n)";
699 }
700
706 inline torch::serialize::OutputArchive &
707 write(torch::serialize::OutputArchive &archive,
708 const std::string &key = "group_norm") const override {
709 archive.write(key + ".type", torch::full({1}, static_cast<int64_t>(
711 archive.write(key + ".weight", this->options_.weight());
712 archive.write(key + ".bias", this->options_.bias());
713 archive.write(key + ".eps", torch::full({1}, (double)this->options_.eps()));
714
715 return archive;
716 }
717
723 inline torch::serialize::InputArchive &
724 read(torch::serialize::InputArchive &archive,
725 const std::string &key = "group_norm") override {
726 torch::Tensor tensor;
727
728 archive.read(key + ".type", tensor);
729 if (tensor.item<int64_t>() != static_cast<int64_t>(activation::group_norm))
730 throw std::runtime_error("activation mismatch");
731
732 archive.read(key + ".weight", this->options_.weight());
733 archive.read(key + ".bias", this->options_.bias());
734 archive.read(key + ".eps", tensor);
735 this->options_.eps(tensor.item<double>());
736
737 return archive;
738 }
739
740private:
741 torch::nn::functional::GroupNormFuncOptions options_;
742};
743
746public:
750 torch::nn::functional::GumbelSoftmaxFuncOptions options = {})
751 : options_(options) {}
752
757 explicit GumbelSoftmax(double tau, int dim, bool hard)
758 : options_(torch::nn::functional::GumbelSoftmaxFuncOptions()
759 .tau(tau)
760 .dim(dim)
761 .hard(hard)) {}
762
763 ~GumbelSoftmax() override = default;
764
768 inline torch::Tensor apply(const torch::Tensor &input) const override {
769 return torch::nn::functional::gumbel_softmax(input, options_);
770 }
771
774 inline const torch::nn::functional::GumbelSoftmaxFuncOptions &
775 options() const {
776 return options_;
777 }
778
781 inline torch::nn::functional::GumbelSoftmaxFuncOptions &options() {
782 return options_;
783 }
784
787 inline void
788 pretty_print(std::ostream &os = Log(log::info)) const noexcept override {
789 os << utils::FullQualifiedName::name() << "(\n tau=" << options_.tau()
790 << ", dim=" << options_.dim() << ", hard=" << options_.hard() << "\n)";
791 }
792
798 inline torch::serialize::OutputArchive &
799 write(torch::serialize::OutputArchive &archive,
800 const std::string &key = "gumbel_softmax") const override {
801 archive.write(
802 key + ".type",
803 torch::full({1}, static_cast<int64_t>(activation::gumbel_softmax)));
804 archive.write(key + ".tau", torch::full({1}, (double)this->options_.tau()));
805 archive.write(key + ".dim", torch::full({1}, (int)this->options_.dim()));
806 archive.write(key + ".hard", torch::full({1}, (bool)this->options_.hard()));
807
808 return archive;
809 }
810
816 inline torch::serialize::InputArchive &
817 read(torch::serialize::InputArchive &archive,
818 const std::string &key = "gumbel_softmax") override {
819 torch::Tensor tensor;
820
821 archive.read(key + ".type", tensor);
822 if (tensor.item<int64_t>() !=
823 static_cast<int64_t>(activation::gumbel_softmax))
824 throw std::runtime_error("activation mismatch");
825
826 archive.read(key + ".tau", tensor);
827 this->options_.tau(tensor.item<double>());
828 archive.read(key + ".dim", tensor);
829 this->options_.dim(tensor.item<int>());
830 archive.read(key + ".hard", tensor);
831 this->options_.hard(tensor.item<bool>());
832
833 return archive;
834 }
835
836private:
837 torch::nn::functional::GumbelSoftmaxFuncOptions options_;
838};
839
842public:
845 explicit Hardshrink(torch::nn::functional::HardshrinkFuncOptions options = {})
846 : options_(options) {}
847
850 explicit Hardshrink(double lambda)
851 : options_(
852 torch::nn::functional::HardshrinkFuncOptions().lambda(lambda)) {}
853
854 ~Hardshrink() override = default;
855
859 inline torch::Tensor apply(const torch::Tensor &input) const override {
860 return torch::nn::functional::hardshrink(input, options_);
861 }
862
865 inline const torch::nn::functional::HardshrinkFuncOptions &options() const {
866 return options_;
867 }
868
871 inline torch::nn::functional::HardshrinkFuncOptions &options() {
872 return options_;
873 }
874
877 inline void
878 pretty_print(std::ostream &os = Log(log::info)) const noexcept override {
880 << "(\n lambda=" << options_.lambda() << "\n)";
881 }
882
888 inline torch::serialize::OutputArchive &
889 write(torch::serialize::OutputArchive &archive,
890 const std::string &key = "hardshrink") const override {
891 archive.write(key + ".type", torch::full({1}, static_cast<int64_t>(
893 archive.write(key + ".lambda",
894 torch::full({1}, (double)this->options_.lambda()));
895
896 return archive;
897 }
898
904 inline torch::serialize::InputArchive &
905 read(torch::serialize::InputArchive &archive,
906 const std::string &key = "hardshrink") override {
907 torch::Tensor tensor;
908
909 archive.read(key + ".type", tensor);
910 if (tensor.item<int64_t>() != static_cast<int64_t>(activation::hardshrink))
911 throw std::runtime_error("activation mismatch");
912
913 archive.read(key + ".lambda", tensor);
914 this->options_.lambda(tensor.item<double>());
915
916 return archive;
917 }
918
919private:
920 torch::nn::functional::HardshrinkFuncOptions options_;
921};
922
934public:
935 explicit Hardsigmoid() = default;
936
937 ~Hardsigmoid() override = default;
938
942 inline torch::Tensor apply(const torch::Tensor &input) const override {
943 return torch::hardsigmoid(input);
944 }
945
948 inline void
949 pretty_print(std::ostream &os = Log(log::info)) const noexcept override {
951 }
952
958 inline torch::serialize::OutputArchive &
959 write(torch::serialize::OutputArchive &archive,
960 const std::string &key = "hardsigmoid") const override {
961 archive.write(
962 key + ".type",
963 torch::full({1}, static_cast<int64_t>(activation::hardsigmoid)));
964
965 return archive;
966 }
967
973 inline torch::serialize::InputArchive &
974 read(torch::serialize::InputArchive &archive,
975 const std::string &key = "hardsigmoid") override {
976 torch::Tensor tensor;
977
978 archive.read(key + ".type", tensor);
979 if (tensor.item<int64_t>() != static_cast<int64_t>(activation::hardsigmoid))
980 throw std::runtime_error("activation mismatch");
981
982 return archive;
983 }
984};
985
997public:
998 explicit Hardswish() = default;
999
1000 ~Hardswish() override = default;
1001
1005 inline torch::Tensor apply(const torch::Tensor &input) const override {
1006 return torch::hardswish(input);
1007 }
1008
1011 inline void
1012 pretty_print(std::ostream &os = Log(log::info)) const noexcept override {
1014 }
1015
1021 inline torch::serialize::OutputArchive &
1022 write(torch::serialize::OutputArchive &archive,
1023 const std::string &key = "hardswish") const override {
1024 archive.write(key + ".type", torch::full({1}, static_cast<int64_t>(
1026
1027 return archive;
1028 }
1029
1035 inline torch::serialize::InputArchive &
1036 read(torch::serialize::InputArchive &archive,
1037 const std::string &key = "hardswish") override {
1038 torch::Tensor tensor;
1039
1040 archive.read(key + ".type", tensor);
1041 if (tensor.item<int64_t>() != static_cast<int64_t>(activation::hardswish))
1042 throw std::runtime_error("activation mismatch");
1043
1044 return archive;
1045 }
1046};
1047
1059public:
1062 explicit Hardtanh(
1063 const torch::nn::functional::HardtanhFuncOptions &options = {})
1064 : options_(options) {}
1065
1070 explicit Hardtanh(double min_val, double max_val, bool inplace = false)
1071 : options_(torch::nn::functional::HardtanhFuncOptions()
1072 .min_val(min_val)
1073 .max_val(max_val)
1074 .inplace(inplace)) {}
1075
1076 ~Hardtanh() override = default;
1077
1081 inline torch::Tensor apply(const torch::Tensor &input) const override {
1082 return torch::nn::functional::hardtanh(input, options_);
1083 }
1084
1087 inline const torch::nn::functional::HardtanhFuncOptions &options() const {
1088 return options_;
1089 }
1090
1093 inline torch::nn::functional::HardtanhFuncOptions &options() {
1094 return options_;
1095 }
1096
1099 inline void
1100 pretty_print(std::ostream &os = Log(log::info)) const noexcept override {
1102 << "(\n min_val=" << options_.min_val()
1103 << ", max_val=" << options_.max_val()
1104 << ", inplace=" << options_.inplace() << "\n)";
1105 }
1106
1112 inline torch::serialize::OutputArchive &
1113 write(torch::serialize::OutputArchive &archive,
1114 const std::string &key = "hardtanh") const override {
1115 archive.write(key + ".type",
1116 torch::full({1}, static_cast<int64_t>(activation::hardtanh)));
1117 archive.write(key + ".min_val",
1118 torch::full({1}, (double)this->options_.min_val()));
1119 archive.write(key + ".max_val",
1120 torch::full({1}, (double)this->options_.max_val()));
1121 archive.write(key + ".inplace",
1122 torch::full({1}, (bool)this->options_.inplace()));
1123
1124 return archive;
1125 }
1126
1132 inline torch::serialize::InputArchive &
1133 read(torch::serialize::InputArchive &archive,
1134 const std::string &key = "hardtanh") override {
1135 torch::Tensor tensor;
1136
1137 archive.read(key + ".type", tensor);
1138 if (tensor.item<int64_t>() != static_cast<int64_t>(activation::hardtanh))
1139 throw std::runtime_error("activation mismatch");
1140
1141 archive.read(key + ".min_val", tensor);
1142 this->options_.min_val(tensor.item<double>());
1143 archive.read(key + ".max_val", tensor);
1144 this->options_.max_val(tensor.item<double>());
1145 archive.read(key + ".inplace", tensor);
1146 this->options_.inplace(tensor.item<bool>());
1147
1148 return archive;
1149 }
1150
1151private:
1152 torch::nn::functional::HardtanhFuncOptions options_;
1153};
1154
1160public:
1164 torch::nn::functional::InstanceNormFuncOptions options = {})
1165 : options_(std::move(options)) {}
1166
1175 explicit InstanceNorm(const torch::Tensor &running_mean,
1176 const torch::Tensor &running_var,
1177 const torch::Tensor &weight, const torch::Tensor &bias,
1178 double eps, double momentum,
1179 bool use_input_stats = true)
1180 : options_(torch::nn::functional::InstanceNormFuncOptions()
1181 .running_mean(running_mean)
1182 .running_var(running_var)
1183 .weight(weight)
1184 .bias(bias)
1185 .eps(eps)
1186 .momentum(momentum)
1187 .use_input_stats(use_input_stats)) {}
1188
1189 ~InstanceNorm() override = default;
1190
1194 inline torch::Tensor apply(const torch::Tensor &input) const override {
1195 return torch::nn::functional::instance_norm(input, options_);
1196 }
1197
1200 inline const torch::nn::functional::InstanceNormFuncOptions &options() const {
1201 return options_;
1202 }
1203
1206 inline torch::nn::functional::InstanceNormFuncOptions &options() {
1207 return options_;
1208 }
1209
1212 inline void
1213 pretty_print(std::ostream &os = Log(log::info)) const noexcept override {
1214 os << utils::FullQualifiedName::name() << "(\n eps=" << options_.eps()
1215 << ", momentum=" << options_.momentum()
1216 << ", use_input_stats=" << options_.use_input_stats();
1217
1218 if (is_verbose(os)) {
1219 os << "\n running_mean = " << options_.running_mean()
1220 << "\n running_var = " << options_.running_var()
1221 << "\n weight = " << options_.weight()
1222 << "\n bias = " << options_.bias();
1223 }
1224
1225 os << "\n)";
1226 }
1227
1233 inline torch::serialize::OutputArchive &
1234 write(torch::serialize::OutputArchive &archive,
1235 const std::string &key = "instance_norm") const override {
1236 archive.write(
1237 key + ".type",
1238 torch::full({1}, static_cast<int64_t>(activation::instance_norm)));
1239 archive.write(key + ".running_mean", this->options_.running_mean());
1240 archive.write(key + ".var", this->options_.running_var());
1241 archive.write(key + ".weight", this->options_.weight());
1242 archive.write(key + ".bias", this->options_.bias());
1243 archive.write(key + ".eps", torch::full({1}, (double)this->options_.eps()));
1244 archive.write(key + ".momentum",
1245 torch::full({1}, (double)this->options_.momentum()));
1246 archive.write(key + ".use_input_stats",
1247 torch::full({1}, (bool)this->options_.use_input_stats()));
1248
1249 return archive;
1250 }
1251
1257 inline torch::serialize::InputArchive &
1258 read(torch::serialize::InputArchive &archive,
1259 const std::string &key = "instance_norm") override {
1260 torch::Tensor tensor;
1261
1262 archive.read(key + ".type", tensor);
1263 if (tensor.item<int64_t>() !=
1264 static_cast<int64_t>(activation::instance_norm))
1265 throw std::runtime_error("activation mismatch");
1266
1267 archive.read(key + ".running_mean", this->options_.running_mean());
1268 archive.read(key + ".running_var", this->options_.running_var());
1269 archive.read(key + ".weight", this->options_.weight());
1270 archive.read(key + ".bias", this->options_.bias());
1271 archive.read(key + ".eps", tensor);
1272 this->options_.eps(tensor.item<double>());
1273 archive.read(key + ".momentum", tensor);
1274 this->options_.momentum(tensor.item<double>());
1275 archive.read(key + ".use_input_stats", tensor);
1276 this->options_.use_input_stats(tensor.item<bool>());
1277
1278 return archive;
1279 }
1280
1281private:
1282 torch::nn::functional::InstanceNormFuncOptions options_;
1283};
1284
1289public:
1292 explicit LayerNorm(std::vector<int64_t> normalized_shape)
1293 : options_(torch::nn::functional::LayerNormFuncOptions(
1294 std::move(normalized_shape))) {}
1295
1298 explicit LayerNorm(torch::nn::functional::LayerNormFuncOptions options)
1299 : options_(std::move(options)) {}
1300
1306 explicit LayerNorm(std::vector<int64_t> normalized_shape,
1307 const torch::Tensor &weight, const torch::Tensor &bias,
1308 double eps)
1309 : options_(torch::nn::functional::LayerNormFuncOptions(
1310 std::move(normalized_shape))
1311 .weight(weight)
1312 .bias(bias)
1313 .eps(eps)) {}
1314
1315 ~LayerNorm() override = default;
1316
1320 inline torch::Tensor apply(const torch::Tensor &input) const override {
1321 return torch::nn::functional::layer_norm(input, options_);
1322 }
1323
1326 inline const torch::nn::functional::LayerNormFuncOptions &options() const {
1327 return options_;
1328 }
1329
1332 inline torch::nn::functional::LayerNormFuncOptions &options() {
1333 return options_;
1334 }
1335
1338 inline void pretty_print(std::ostream &os) const noexcept override {
1339 os << utils::FullQualifiedName::name() << "(\n eps=" << options_.eps();
1340
1341 if (is_verbose(os)) {
1342 os << "\n normalized_shape = " << options_.normalized_shape()
1343 << "\n weight = " << options_.weight()
1344 << "\n bias = " << options_.bias();
1345 }
1346
1347 os << "\n)";
1348 }
1349
1355 inline torch::serialize::OutputArchive &
1356 write(torch::serialize::OutputArchive &archive,
1357 const std::string &key = "layer_norm") const override {
1358 archive.write(key + ".type", torch::full({1}, static_cast<int64_t>(
1360 archive.write(key + ".weight", this->options_.weight());
1361 archive.write(key + ".bias", this->options_.bias());
1362 archive.write(key + ".eps", torch::full({1}, (double)this->options_.eps()));
1363
1364 return archive;
1365 }
1366
1372 inline torch::serialize::InputArchive &
1373 read(torch::serialize::InputArchive &archive,
1374 const std::string &key = "layer_norm") override {
1375 torch::Tensor tensor;
1376
1377 archive.read(key + ".type", tensor);
1378 if (tensor.item<int64_t>() != static_cast<int64_t>(activation::layer_norm))
1379 throw std::runtime_error("activation mismatch");
1380
1381 archive.read(key + ".weight", this->options_.weight());
1382 archive.read(key + ".bias", this->options_.bias());
1383 archive.read(key + ".eps", tensor);
1384 this->options_.eps(tensor.item<double>());
1385
1386 return archive;
1387 }
1388
1389private:
1390 torch::nn::functional::LayerNormFuncOptions options_;
1391};
1392
1403public:
1406 explicit LeakyReLU(torch::nn::functional::LeakyReLUFuncOptions options = {})
1407 : options_(options) {}
1408
1412 explicit LeakyReLU(double negative_slope, bool inplace = false)
1413 : options_(torch::nn::functional::LeakyReLUFuncOptions()
1414 .negative_slope(negative_slope)
1415 .inplace(inplace)) {}
1416
1417 ~LeakyReLU() override = default;
1418
1422 inline torch::Tensor apply(const torch::Tensor &input) const override {
1423 return torch::nn::functional::leaky_relu(input, options_);
1424 }
1425
1428 inline const torch::nn::functional::LeakyReLUFuncOptions &options() const {
1429 return options_;
1430 }
1431
1434 inline torch::nn::functional::LeakyReLUFuncOptions &options() {
1435 return options_;
1436 }
1437
1440 inline void pretty_print(std::ostream &os) const noexcept override {
1442 << "(\n negative_slope=" << options_.negative_slope()
1443 << ", inplace=" << options_.inplace() << "\n)";
1444 }
1445
1451 inline torch::serialize::OutputArchive &
1452 write(torch::serialize::OutputArchive &archive,
1453 const std::string &key = "leaky_relu") const override {
1454 archive.write(key + ".type", torch::full({1}, static_cast<int64_t>(
1456
1457 archive.write(key + ".negative_slope",
1458 torch::full({1}, (double)this->options_.negative_slope()));
1459 archive.write(key + ".inplace",
1460 torch::full({1}, (bool)this->options_.inplace()));
1461
1462 return archive;
1463 }
1464
1470 inline torch::serialize::InputArchive &
1471 read(torch::serialize::InputArchive &archive,
1472 const std::string &key = "leaky_relu") override {
1473 torch::Tensor tensor;
1474
1475 archive.read(key + ".type", tensor);
1476 if (tensor.item<int64_t>() != static_cast<int64_t>(activation::leaky_relu))
1477 throw std::runtime_error("activation mismatch");
1478
1479 archive.read(key + ".negative_slope", tensor);
1480 this->options_.negative_slope(tensor.item<double>());
1481 archive.read(key + ".inplace", tensor);
1482 this->options_.inplace(tensor.item<bool>());
1483
1484 return archive;
1485 }
1486
1487private:
1488 torch::nn::functional::LeakyReLUFuncOptions options_;
1489};
1490
1493public:
1496 explicit LocalResponseNorm(int64_t size)
1497 : options_(torch::nn::functional::LocalResponseNormFuncOptions(size)) {}
1498
1502 const torch::nn::functional::LocalResponseNormFuncOptions &options)
1503 : options_(options) {}
1504
1510 explicit LocalResponseNorm(int64_t size, double alpha, double beta, double k)
1511 : options_(torch::nn::functional::LocalResponseNormFuncOptions(size)
1512 .alpha(alpha)
1513 .beta(beta)
1514 .k(k)) {}
1515
1516 ~LocalResponseNorm() override = default;
1517
1521 inline torch::Tensor apply(const torch::Tensor &input) const override {
1522 return torch::nn::functional::local_response_norm(input, options_);
1523 }
1524
1527 inline const torch::nn::functional::LocalResponseNormFuncOptions &
1528 options() const {
1529 return options_;
1530 }
1531
1534 inline torch::nn::functional::LocalResponseNormFuncOptions &options() {
1535 return options_;
1536 }
1537
1540 inline void pretty_print(std::ostream &os) const noexcept override {
1541 os << utils::FullQualifiedName::name() << "(\n size=" << options_.size()
1542 << ", alpha=" << options_.alpha() << ", beta=" << options_.beta()
1543 << ", k=" << options_.k() << "\n)";
1544 }
1545
1551 inline torch::serialize::OutputArchive &
1552 write(torch::serialize::OutputArchive &archive,
1553 const std::string &key = "local_response_norm") const override {
1554 archive.write(key + ".type",
1555 torch::full({1}, static_cast<int64_t>(
1557
1558 archive.write(key + ".size",
1559 torch::full({1}, (int64_t)this->options_.size()));
1560 archive.write(key + ".alpha",
1561 torch::full({1}, (double)this->options_.alpha()));
1562 archive.write(key + ".beta",
1563 torch::full({1}, (double)this->options_.beta()));
1564 archive.write(key + ".k", torch::full({1}, (double)this->options_.k()));
1565
1566 return archive;
1567 }
1568
1574 inline torch::serialize::InputArchive &
1575 read(torch::serialize::InputArchive &archive,
1576 const std::string &key = "local_response_norm") override {
1577 torch::Tensor tensor;
1578
1579 archive.read(key + ".type", tensor);
1580 if (tensor.item<int64_t>() !=
1581 static_cast<int64_t>(activation::local_response_norm))
1582 throw std::runtime_error("activation mismatch");
1583
1584 archive.read(key + ".size", tensor);
1585 this->options_.size(tensor.item<int64_t>());
1586 archive.read(key + ".alpha", tensor);
1587 this->options_.alpha(tensor.item<double>());
1588 archive.read(key + ".beta", tensor);
1589 this->options_.beta(tensor.item<double>());
1590 archive.read(key + ".k", tensor);
1591 this->options_.k(tensor.item<double>());
1592
1593 return archive;
1594 }
1595
1596private:
1597 torch::nn::functional::LocalResponseNormFuncOptions options_;
1598};
1599
1606public:
1607 explicit LogSigmoid() = default;
1608
1609 ~LogSigmoid() override = default;
1610
1614 inline torch::Tensor apply(const torch::Tensor &input) const override {
1615 return torch::log_sigmoid(input);
1616 }
1617
1620 inline void pretty_print(std::ostream &os) const noexcept override {
1622 }
1623
1629 inline torch::serialize::OutputArchive &
1630 write(torch::serialize::OutputArchive &archive,
1631 const std::string &key = "logsigmoid") const override {
1632 archive.write(key + ".type", torch::full({1}, static_cast<int64_t>(
1634
1635 return archive;
1636 }
1637
1643 inline torch::serialize::InputArchive &
1644 read(torch::serialize::InputArchive &archive,
1645 const std::string &key = "logsigmoid") override {
1646 torch::Tensor tensor;
1647
1648 archive.read(key + ".type", tensor);
1649 if (tensor.item<int64_t>() != static_cast<int64_t>(activation::logsigmoid))
1650 throw std::runtime_error("activation mismatch");
1651
1652 return archive;
1653 }
1654};
1655
1665public:
1668 explicit LogSoftmax(int64_t dim)
1669 : options_(torch::nn::functional::LogSoftmaxFuncOptions(dim)) {}
1670
1673 explicit LogSoftmax(
1674 const torch::nn::functional::LogSoftmaxFuncOptions &options)
1675 : options_(options) {}
1676
1677 ~LogSoftmax() override = default;
1678
1682 inline torch::Tensor apply(const torch::Tensor &input) const override {
1683 return torch::nn::functional::log_softmax(input, options_);
1684 }
1685
1688 inline const torch::nn::functional::LogSoftmaxFuncOptions &options() const {
1689 return options_;
1690 }
1691
1694 inline torch::nn::functional::LogSoftmaxFuncOptions &options() {
1695 return options_;
1696 }
1697
1700 inline void pretty_print(std::ostream &os) const noexcept override {
1701 os << utils::FullQualifiedName::name() << "(\n dim=" << options_.dim()
1702 << "\n)";
1703 }
1704
1710 inline torch::serialize::OutputArchive &
1711 write(torch::serialize::OutputArchive &archive,
1712 const std::string &key = "logsoftmax") const override {
1713 archive.write(key + ".type", torch::full({1}, static_cast<int64_t>(
1715
1716 return archive;
1717 }
1718
1724 inline torch::serialize::InputArchive &
1725 read(torch::serialize::InputArchive &archive,
1726 const std::string &key = "logsoftmax") override {
1727 torch::Tensor tensor;
1728
1729 archive.read(key + ".type", tensor);
1730 if (tensor.item<int64_t>() != static_cast<int64_t>(activation::logsoftmax))
1731 throw std::runtime_error("activation mismatch");
1732
1733 return archive;
1734 }
1735
1736private:
1737 torch::nn::functional::LogSoftmaxFuncOptions options_;
1738};
1739
1745class Mish : public ActivationFunction {
1746public:
1747 explicit Mish() = default;
1748
1749 ~Mish() override = default;
1750
1754 inline torch::Tensor apply(const torch::Tensor &input) const override {
1755 return torch::mish(input);
1756 }
1757
1760 inline void pretty_print(std::ostream &os) const noexcept override {
1762 }
1763
1769 inline torch::serialize::OutputArchive &
1770 write(torch::serialize::OutputArchive &archive,
1771 const std::string &key = "mish") const override {
1772 archive.write(key + ".type",
1773 torch::full({1}, static_cast<int64_t>(activation::mish)));
1774
1775 return archive;
1776 }
1777
1783 inline torch::serialize::InputArchive &
1784 read(torch::serialize::InputArchive &archive,
1785 const std::string &key = "mish") override {
1786 torch::Tensor tensor;
1787
1788 archive.read(key + ".type", tensor);
1789 if (tensor.item<int64_t>() != static_cast<int64_t>(activation::mish))
1790 throw std::runtime_error("activation mismatch");
1791
1792 return archive;
1793 }
1794};
1795
1798public:
1801 explicit Normalize(torch::nn::functional::NormalizeFuncOptions options = {})
1802 : options_(std::move(options)) {}
1803
1808 explicit Normalize(double p, double eps, int64_t dim)
1809 : options_(
1810 torch::nn::functional::NormalizeFuncOptions().p(p).eps(eps).dim(
1811 dim)) {}
1812
1813 ~Normalize() override = default;
1814
1818 inline torch::Tensor apply(const torch::Tensor &input) const override {
1819 return torch::nn::functional::normalize(input, options_);
1820 }
1821
1824 inline const torch::nn::functional::NormalizeFuncOptions &options() const {
1825 return options_;
1826 }
1827
1830 inline torch::nn::functional::NormalizeFuncOptions &options() {
1831 return options_;
1832 }
1833
1836 inline void pretty_print(std::ostream &os) const noexcept override {
1837 os << utils::FullQualifiedName::name() << "(\n eps=" << options_.eps()
1838 << "(\n p=" << options_.p() << "(\n dim=" << options_.dim() << "\n)";
1839 }
1840
1846 inline torch::serialize::OutputArchive &
1847 write(torch::serialize::OutputArchive &archive,
1848 const std::string &key = "normalize") const override {
1849 archive.write(key + ".type", torch::full({1}, static_cast<int64_t>(
1851 archive.write(key + ".p", torch::full({1}, (double)this->options_.p()));
1852 archive.write(key + ".eps", torch::full({1}, (double)this->options_.eps()));
1853 archive.write(key + ".dim",
1854 torch::full({1}, (int64_t)this->options_.dim()));
1855
1856 return archive;
1857 }
1858
1864 inline torch::serialize::InputArchive &
1865 read(torch::serialize::InputArchive &archive,
1866 const std::string &key = "normalize") override {
1867 torch::Tensor tensor;
1868
1869 archive.read(key + ".type", tensor);
1870 if (tensor.item<int64_t>() != static_cast<int64_t>(activation::normalize))
1871 throw std::runtime_error("activation mismatch");
1872
1873 archive.read(key + ".p", tensor);
1874 this->options_.p(tensor.item<double>());
1875 archive.read(key + ".eps", tensor);
1876 this->options_.eps(tensor.item<double>());
1877 archive.read(key + ".dim", tensor);
1878 this->options_.dim(tensor.item<int64_t>());
1879
1880 return archive;
1881 }
1882
1883private:
1884 torch::nn::functional::NormalizeFuncOptions options_;
1885};
1886
1889public:
1892 explicit PReLU(torch::Tensor weight) : weight_(std::move(weight)) {}
1893
1894 ~PReLU() override = default;
1895
1898 const torch::Tensor &weight() const { return weight_; }
1899
1902 torch::Tensor &weight() { return weight_; }
1903
1907 inline torch::Tensor apply(const torch::Tensor &input) const override {
1908 return torch::nn::functional::prelu(input, weight());
1909 }
1910
1913 inline void pretty_print(std::ostream &os) const noexcept override {
1915
1916 if (is_verbose(os))
1917 os << "(\n weight = " << weight() << "\n)";
1918 }
1919
1925 inline torch::serialize::OutputArchive &
1926 write(torch::serialize::OutputArchive &archive,
1927 const std::string &key = "prelu") const override {
1928 archive.write(key + ".type",
1929 torch::full({1}, static_cast<int64_t>(activation::prelu)));
1930 archive.write(key + ".weight", this->weight());
1931
1932 return archive;
1933 }
1934
1940 inline torch::serialize::InputArchive &
1941 read(torch::serialize::InputArchive &archive,
1942 const std::string &key = "prelu") override {
1943 torch::Tensor tensor;
1944
1945 archive.read(key + ".type", tensor);
1946 if (tensor.item<int64_t>() != static_cast<int64_t>(activation::prelu))
1947 throw std::runtime_error("activation mismatch");
1948
1949 archive.read(key + ".weight", this->weight());
1950
1951 return archive;
1952 }
1953
1954private:
1955 torch::Tensor weight_;
1956};
1957
1963class ReLU : public ActivationFunction {
1964public:
1967 explicit ReLU(torch::nn::functional::ReLUFuncOptions options = {})
1968 : options_(options) {}
1969
1972 explicit ReLU(bool inplace)
1973 : options_(torch::nn::functional::ReLUFuncOptions().inplace(inplace)) {}
1974
1975 ~ReLU() override = default;
1976
1980 inline torch::Tensor apply(const torch::Tensor &input) const override {
1981 return torch::nn::functional::relu(input, options_);
1982 }
1983
1986 inline const torch::nn::functional::ReLUFuncOptions &options() const {
1987 return options_;
1988 }
1989
1992 inline torch::nn::functional::ReLUFuncOptions &options() { return options_; }
1993
1996 inline void pretty_print(std::ostream &os) const noexcept override {
1998 << "(\n inplace=" << options_.inplace() << "\n)";
1999 }
2000
2006 inline torch::serialize::OutputArchive &
2007 write(torch::serialize::OutputArchive &archive,
2008 const std::string &key = "relu") const override {
2009 archive.write(key + ".type",
2010 torch::full({1}, static_cast<int64_t>(activation::relu)));
2011 archive.write(key + ".inplace",
2012 torch::full({1}, (bool)this->options_.inplace()));
2013
2014 return archive;
2015 }
2016
2022 inline torch::serialize::InputArchive &
2023 read(torch::serialize::InputArchive &archive,
2024 const std::string &key = "relu") override {
2025 torch::Tensor tensor;
2026
2027 archive.read(key + ".type", tensor);
2028 if (tensor.item<int64_t>() != static_cast<int64_t>(activation::relu))
2029 throw std::runtime_error("activation mismatch");
2030
2031 archive.read(key + ".inplace", tensor);
2032 this->options_.inplace(tensor.item<bool>());
2033
2034 return archive;
2035 }
2036
2037private:
2038 torch::nn::functional::ReLUFuncOptions options_;
2039};
2040
2047public:
2050 explicit ReLU6(torch::nn::functional::ReLU6FuncOptions options = {})
2051 : options_(options) {}
2052
2055 explicit ReLU6(bool inplace)
2056 : options_(torch::nn::functional::ReLU6FuncOptions().inplace(inplace)) {}
2057
2058 ~ReLU6() override = default;
2059
2063 inline torch::Tensor apply(const torch::Tensor &input) const override {
2064 return torch::nn::functional::relu6(input, options_);
2065 }
2066
2069 inline const torch::nn::functional::ReLU6FuncOptions &options() const {
2070 return options_;
2071 }
2072
2075 inline torch::nn::functional::ReLU6FuncOptions &options() { return options_; }
2076
2079 inline void pretty_print(std::ostream &os) const noexcept override {
2081 << "(\n inplace=" << options_.inplace() << "\n)";
2082 }
2083
2089 inline torch::serialize::OutputArchive &
2090 write(torch::serialize::OutputArchive &archive,
2091 const std::string &key = "relu6") const override {
2092 archive.write(key + ".type",
2093 torch::full({1}, static_cast<int64_t>(activation::relu6)));
2094 archive.write(key + ".inplace",
2095 torch::full({1}, (bool)this->options_.inplace()));
2096
2097 return archive;
2098 }
2099
2105 inline torch::serialize::InputArchive &
2106 read(torch::serialize::InputArchive &archive,
2107 const std::string &key = "relu6") override {
2108 torch::Tensor tensor;
2109
2110 archive.read(key + ".type", tensor);
2111 if (tensor.item<int64_t>() != static_cast<int64_t>(activation::relu6))
2112 throw std::runtime_error("activation mismatch");
2113
2114 archive.read(key + ".inplace", tensor);
2115 this->options_.inplace(tensor.item<bool>());
2116
2117 return archive;
2118 }
2119
2120private:
2121 torch::nn::functional::ReLU6FuncOptions options_;
2122};
2123
2134public:
2137 explicit RReLU(const torch::nn::functional::RReLUFuncOptions &options = {})
2138 : options_(options) {}
2139
2144 explicit RReLU(double lower, double upper, bool inplace = false)
2145 : options_(torch::nn::functional::RReLUFuncOptions()
2146 .lower(lower)
2147 .upper(upper)
2148 .inplace(inplace)) {}
2149
2150 ~RReLU() override = default;
2151
2155 inline torch::Tensor apply(const torch::Tensor &input) const override {
2156 return torch::nn::functional::rrelu(input, options_);
2157 }
2158
2161 inline const torch::nn::functional::RReLUFuncOptions &options() const {
2162 return options_;
2163 }
2164
2167 inline torch::nn::functional::RReLUFuncOptions &options() { return options_; }
2168
2171 inline void pretty_print(std::ostream &os) const noexcept override {
2172 os << utils::FullQualifiedName::name() << "(\n lower=" << options_.lower()
2173 << ", upper=" << options_.upper() << ", inplace=" << options_.inplace()
2174 << "\n)";
2175 }
2176
2182 inline torch::serialize::OutputArchive &
2183 write(torch::serialize::OutputArchive &archive,
2184 const std::string &key = "rrelu") const override {
2185 archive.write(key + ".type",
2186 torch::full({1}, static_cast<int64_t>(activation::rrelu)));
2187 archive.write(key + ".lower",
2188 torch::full({1}, (double)this->options_.lower()));
2189 archive.write(key + ".upper",
2190 torch::full({1}, (double)this->options_.upper()));
2191 archive.write(key + ".inplace",
2192 torch::full({1}, (bool)this->options_.inplace()));
2193
2194 return archive;
2195 }
2196
2202 inline torch::serialize::InputArchive &
2203 read(torch::serialize::InputArchive &archive,
2204 const std::string &key = "rrelu") override {
2205 torch::Tensor tensor;
2206
2207 archive.read(key + ".type", tensor);
2208 if (tensor.item<int64_t>() != static_cast<int64_t>(activation::rrelu))
2209 throw std::runtime_error("activation mismatch");
2210
2211 archive.read(key + ".lower", tensor);
2212 this->options_.lower(tensor.item<double>());
2213 archive.read(key + ".upper", tensor);
2214 this->options_.upper(tensor.item<double>());
2215 archive.read(key + ".inplace", tensor);
2216 this->options_.inplace(tensor.item<bool>());
2217
2218 return archive;
2219 }
2220
2221private:
2222 torch::nn::functional::RReLUFuncOptions options_;
2223};
2224
2233class SELU : public ActivationFunction {
2234public:
2237 explicit SELU(torch::nn::functional::SELUFuncOptions options = {})
2238 : options_(options) {}
2239
2242 explicit SELU(bool inplace)
2243 : options_(torch::nn::functional::SELUFuncOptions().inplace(inplace)) {}
2244
2245 ~SELU() override = default;
2246
2250 inline torch::Tensor apply(const torch::Tensor &input) const override {
2251 return torch::nn::functional::selu(input, options_);
2252 }
2253
2256 inline const torch::nn::functional::SELUFuncOptions &options() const {
2257 return options_;
2258 }
2259
2262 inline torch::nn::functional::SELUFuncOptions &options() { return options_; }
2263
2266 inline void pretty_print(std::ostream &os) const noexcept override {
2268 << "(\n inplace=" << options_.inplace() << "\n)";
2269 }
2270
2276 inline torch::serialize::OutputArchive &
2277 write(torch::serialize::OutputArchive &archive,
2278 const std::string &key = "selu") const override {
2279 archive.write(key + ".type",
2280 torch::full({1}, static_cast<int64_t>(activation::selu)));
2281 archive.write(key + ".inplace",
2282 torch::full({1}, (bool)this->options_.inplace()));
2283
2284 return archive;
2285 }
2286
2292 inline torch::serialize::InputArchive &
2293 read(torch::serialize::InputArchive &archive,
2294 const std::string &key = "selu") override {
2295 torch::Tensor tensor;
2296
2297 archive.read(key + ".type", tensor);
2298 if (tensor.item<int64_t>() != static_cast<int64_t>(activation::selu))
2299 throw std::runtime_error("activation mismatch");
2300
2301 archive.read(key + ".inplace", tensor);
2302 this->options_.inplace(tensor.item<bool>());
2303
2304 return archive;
2305 }
2306
2307private:
2308 torch::nn::functional::SELUFuncOptions options_;
2309};
2310
2317public:
2321 inline torch::Tensor apply(const torch::Tensor &input) const override {
2322 return torch::sigmoid(input);
2323 }
2324
2327 inline void pretty_print(std::ostream &os) const noexcept override {
2329 }
2330
2336 inline torch::serialize::OutputArchive &
2337 write(torch::serialize::OutputArchive &archive,
2338 const std::string &key = "sigmoid") const override {
2339 archive.write(key + ".type",
2340 torch::full({1}, static_cast<int64_t>(activation::sigmoid)));
2341
2342 return archive;
2343 }
2344
2350 inline torch::serialize::InputArchive &
2351 read(torch::serialize::InputArchive &archive,
2352 const std::string &key = "sigmoid") override {
2353 torch::Tensor tensor;
2354
2355 archive.read(key + ".type", tensor);
2356 if (tensor.item<int64_t>() != static_cast<int64_t>(activation::sigmoid))
2357 throw std::runtime_error("activation mismatch");
2358
2359 return archive;
2360 }
2361};
2362
2368class SiLU : public ActivationFunction {
2369public:
2373 inline torch::Tensor apply(const torch::Tensor &input) const override {
2374 return torch::silu(input);
2375 }
2376
2379 inline void pretty_print(std::ostream &os) const noexcept override {
2381 }
2382
2388 inline torch::serialize::OutputArchive &
2389 write(torch::serialize::OutputArchive &archive,
2390 const std::string &key = "silu") const override {
2391 archive.write(key + ".type",
2392 torch::full({1}, static_cast<int64_t>(activation::silu)));
2393
2394 return archive;
2395 }
2396
2402 inline torch::serialize::InputArchive &
2403 read(torch::serialize::InputArchive &archive,
2404 const std::string &key = "silu") override {
2405 torch::Tensor tensor;
2406
2407 archive.read(key + ".type", tensor);
2408 if (tensor.item<int64_t>() != static_cast<int64_t>(activation::silu))
2409 throw std::runtime_error("activation mismatch");
2410
2411 return archive;
2412 }
2413};
2414
2423public:
2426 explicit Softmax(int64_t dim)
2427 : options_(torch::nn::functional::SoftmaxFuncOptions(dim)) {}
2428
2431 explicit Softmax(const torch::nn::functional::SoftmaxFuncOptions &options)
2432 : options_(options) {}
2433
2434 ~Softmax() override = default;
2435
2439 inline torch::Tensor apply(const torch::Tensor &input) const override {
2440 return torch::nn::functional::softmax(input, options_);
2441 }
2442
2445 inline const torch::nn::functional::SoftmaxFuncOptions &options() const {
2446 return options_;
2447 }
2448
2451 inline torch::nn::functional::SoftmaxFuncOptions &options() {
2452 return options_;
2453 }
2454
2457 inline void pretty_print(std::ostream &os) const noexcept override {
2458 os << utils::FullQualifiedName::name() << "(\n dim=" << options_.dim()
2459 << "\n)";
2460 }
2461
2467 inline torch::serialize::OutputArchive &
2468 write(torch::serialize::OutputArchive &archive,
2469 const std::string &key = "softmax") const override {
2470 archive.write(key + ".type",
2471 torch::full({1}, static_cast<int64_t>(activation::softmax)));
2472 archive.write(key + ".dim",
2473 torch::full({1}, (int64_t)this->options_.dim()));
2474
2475 return archive;
2476 }
2477
2483 inline torch::serialize::InputArchive &
2484 read(torch::serialize::InputArchive &archive,
2485 const std::string &key = "softmax") override {
2486 torch::Tensor tensor;
2487
2488 archive.read(key + ".type", tensor);
2489 if (tensor.item<int64_t>() != static_cast<int64_t>(activation::softmax))
2490 throw std::runtime_error("activation mismatch");
2491
2492 archive.read(key + ".dim", tensor);
2493 this->options_.dim(tensor.item<int64_t>());
2494
2495 return archive;
2496 }
2497
2498private:
2499 torch::nn::functional::SoftmaxFuncOptions options_;
2500};
2501
2508public:
2511 explicit Softmin(int64_t dim)
2512 : options_(torch::nn::functional::SoftminFuncOptions(dim)) {}
2513
2516 explicit Softmin(const torch::nn::functional::SoftminFuncOptions &options)
2517 : options_(options) {}
2518
2519 ~Softmin() override = default;
2520
2524 inline torch::Tensor apply(const torch::Tensor &input) const override {
2525 return torch::nn::functional::softmin(input, options_);
2526 }
2527
2530 inline const torch::nn::functional::SoftminFuncOptions &options() const {
2531 return options_;
2532 }
2533
2536 inline torch::nn::functional::SoftminFuncOptions &options() {
2537 return options_;
2538 }
2539
2542 inline void pretty_print(std::ostream &os) const noexcept override {
2543 os << utils::FullQualifiedName::name() << "(\n dim=" << options_.dim()
2544 << "\n)";
2545 }
2546
2552 inline torch::serialize::OutputArchive &
2553 write(torch::serialize::OutputArchive &archive,
2554 const std::string &key = "softmin") const override {
2555 archive.write(key + ".type",
2556 torch::full({1}, static_cast<int64_t>(activation::softmin)));
2557 archive.write(key + ".dim",
2558 torch::full({1}, (int64_t)this->options_.dim()));
2559
2560 return archive;
2561 }
2562
2568 inline torch::serialize::InputArchive &
2569 read(torch::serialize::InputArchive &archive,
2570 const std::string &key = "softmin") override {
2571 torch::Tensor tensor;
2572
2573 archive.read(key + ".type", tensor);
2574 if (tensor.item<int64_t>() != static_cast<int64_t>(activation::softmin))
2575 throw std::runtime_error("activation mismatch");
2576
2577 archive.read(key + ".dim", tensor);
2578 this->options_.dim(tensor.item<int64_t>());
2579
2580 return archive;
2581 }
2582
2583private:
2584 torch::nn::functional::SoftminFuncOptions options_;
2585};
2586
2593public:
2596 explicit Softplus(torch::nn::functional::SoftplusFuncOptions options = {})
2597 : options_(options) {}
2598
2602 explicit Softplus(double beta, double threshold)
2603 : options_(
2604 torch::nn::functional::SoftplusFuncOptions().beta(beta).threshold(
2605 threshold)) {}
2606
2607 ~Softplus() override = default;
2608
2612 inline torch::Tensor apply(const torch::Tensor &input) const override {
2613 return torch::nn::functional::softplus(input, options_);
2614 }
2615
2618 inline const torch::nn::functional::SoftplusFuncOptions &options() const {
2619 return options_;
2620 }
2621
2624 inline torch::nn::functional::SoftplusFuncOptions &options() {
2625 return options_;
2626 }
2627
2630 inline void pretty_print(std::ostream &os) const noexcept override {
2631 os << utils::FullQualifiedName::name() << "(\n beta=" << options_.beta()
2632 << ", theshold=" << options_.threshold() << "\n)";
2633 }
2634
2640 inline torch::serialize::OutputArchive &
2641 write(torch::serialize::OutputArchive &archive,
2642 const std::string &key = "softplus") const override {
2643 archive.write(key + ".type",
2644 torch::full({1}, static_cast<int64_t>(activation::softplus)));
2645 archive.write(key + ".beta",
2646 torch::full({1}, (double)this->options_.beta()));
2647 archive.write(key + ".threshold",
2648 torch::full({1}, (double)this->options_.threshold()));
2649
2650 return archive;
2651 }
2652
2658 inline torch::serialize::InputArchive &
2659 read(torch::serialize::InputArchive &archive,
2660 const std::string &key = "softplus") override {
2661 torch::Tensor tensor;
2662
2663 archive.read(key + ".type", tensor);
2664 if (tensor.item<int64_t>() != static_cast<int64_t>(activation::softplus))
2665 throw std::runtime_error("activation mismatch");
2666
2667 archive.read(key + ".beta", tensor);
2668 this->options_.beta(tensor.item<double>());
2669 archive.read(key + ".threshold", tensor);
2670 this->options_.threshold(tensor.item<double>());
2671
2672 return archive;
2673 }
2674
2675private:
2676 torch::nn::functional::SoftplusFuncOptions options_;
2677};
2678
2690public:
2693 explicit Softshrink(torch::nn::functional::SoftshrinkFuncOptions options = {})
2694 : options_(options) {}
2695
2698 explicit Softshrink(double lambda)
2699 : options_(
2700 torch::nn::functional::SoftshrinkFuncOptions().lambda(lambda)) {}
2701
2702 ~Softshrink() override = default;
2703
2707 inline torch::Tensor apply(const torch::Tensor &input) const override {
2708 return torch::nn::functional::softshrink(input, options_);
2709 }
2710
2713 inline const torch::nn::functional::SoftshrinkFuncOptions &options() const {
2714 return options_;
2715 }
2716
2719 inline torch::nn::functional::SoftshrinkFuncOptions &options() {
2720 return options_;
2721 }
2722
2725 inline void pretty_print(std::ostream &os) const noexcept override {
2727 << "(\n lambda=" << options_.lambda() << "\n)";
2728 }
2729
2735 inline torch::serialize::OutputArchive &
2736 write(torch::serialize::OutputArchive &archive,
2737 const std::string &key = "softshrink") const override {
2738 archive.write(key + ".type", torch::full({1}, static_cast<int64_t>(
2740 archive.write(key + ".lambda",
2741 torch::full({1}, (double)this->options_.lambda()));
2742
2743 return archive;
2744 }
2745
2751 inline torch::serialize::InputArchive &
2752 read(torch::serialize::InputArchive &archive,
2753 const std::string &key = "softshrink") override {
2754 torch::Tensor tensor;
2755
2756 archive.read(key + ".type", tensor);
2757 if (tensor.item<int64_t>() != static_cast<int64_t>(activation::softshrink))
2758 throw std::runtime_error("activation mismatch");
2759
2760 archive.read(key + ".lambda", tensor);
2761 this->options_.lambda(tensor.item<double>());
2762
2763 return archive;
2764 }
2765
2766private:
2767 torch::nn::functional::SoftshrinkFuncOptions options_;
2768};
2769
2776public:
2780 inline torch::Tensor apply(const torch::Tensor &input) const override {
2781 return torch::nn::functional::softsign(input);
2782 }
2783
2786 inline void pretty_print(std::ostream &os) const noexcept override {
2788 }
2789
2795 inline torch::serialize::OutputArchive &
2796 write(torch::serialize::OutputArchive &archive,
2797 const std::string &key = "softsign") const override {
2798 archive.write(key + ".type",
2799 torch::full({1}, static_cast<int64_t>(activation::softsign)));
2800
2801 return archive;
2802 }
2803
2809 inline torch::serialize::InputArchive &
2810 read(torch::serialize::InputArchive &archive,
2811 const std::string &key = "softsign") override {
2812 torch::Tensor tensor;
2813
2814 archive.read(key + ".type", tensor);
2815 if (tensor.item<int64_t>() != static_cast<int64_t>(activation::softsign))
2816 throw std::runtime_error("activation mismatch");
2817
2818 return archive;
2819 }
2820};
2821
2827class Tanh : public ActivationFunction {
2828public:
2832 inline torch::Tensor apply(const torch::Tensor &input) const override {
2833 return torch::tanh(input);
2834 }
2835
2838 inline void pretty_print(std::ostream &os) const noexcept override {
2840 }
2841
2847 inline torch::serialize::OutputArchive &
2848 write(torch::serialize::OutputArchive &archive,
2849 const std::string &key = "tanh") const override {
2850 archive.write(key + ".type",
2851 torch::full({1}, static_cast<int64_t>(activation::tanh)));
2852
2853 return archive;
2854 }
2855
2861 inline torch::serialize::InputArchive &
2862 read(torch::serialize::InputArchive &archive,
2863 const std::string &key = "tanh") override {
2864 torch::Tensor tensor;
2865
2866 archive.read(key + ".type", tensor);
2867 if (tensor.item<int64_t>() != static_cast<int64_t>(activation::tanh))
2868 throw std::runtime_error("activation mismatch");
2869
2870 return archive;
2871 }
2872};
2873
2880public:
2884 inline torch::Tensor apply(const torch::Tensor &input) const override {
2885 return torch::nn::functional::tanhshrink(input);
2886 }
2887
2890 inline void pretty_print(std::ostream &os) const noexcept override {
2892 }
2893
2899 inline torch::serialize::OutputArchive &
2900 write(torch::serialize::OutputArchive &archive,
2901 const std::string &key = "tanhshrink") const override {
2902 archive.write(key + ".type", torch::full({1}, static_cast<int64_t>(
2904
2905 return archive;
2906 }
2907
2913 inline torch::serialize::InputArchive &
2914 read(torch::serialize::InputArchive &archive,
2915 const std::string &key = "tanhshrink") override {
2916 torch::Tensor tensor;
2917
2918 archive.read(key + ".type", tensor);
2919 if (tensor.item<int64_t>() != static_cast<int64_t>(activation::tanhshrink))
2920 throw std::runtime_error("activation mismatch");
2921
2922 return archive;
2923 }
2924};
2925
2936public:
2939 explicit Threshold(const torch::nn::functional::ThresholdFuncOptions &options)
2940 : options_(options) {}
2941
2946 explicit Threshold(double threshold, double value, bool inplace = false)
2947 : options_(torch::nn::functional::ThresholdFuncOptions(threshold, value)
2948 .inplace(inplace)) {}
2949
2950 ~Threshold() override = default;
2951
2955 inline torch::Tensor apply(const torch::Tensor &input) const override {
2956 return torch::nn::functional::threshold(input, options_);
2957 }
2958
2961 inline const torch::nn::functional::ThresholdFuncOptions &options() const {
2962 return options_;
2963 }
2964
2967 inline torch::nn::functional::ThresholdFuncOptions &options() {
2968 return options_;
2969 }
2970
2973 inline void pretty_print(std::ostream &os) const noexcept override {
2975 << "(\n threshold=" << options_.threshold()
2976 << ", value=" << options_.value() << ", inplace=" << options_.inplace()
2977 << "\n)";
2978 }
2979
2985 inline torch::serialize::OutputArchive &
2986 write(torch::serialize::OutputArchive &archive,
2987 const std::string &key = "threshold") const override {
2988 archive.write(key + ".type", torch::full({1}, static_cast<int64_t>(
2990 archive.write(key + ".threshold",
2991 torch::full({1}, this->options_.threshold()));
2992 archive.write(key + ".value", torch::full({1}, this->options_.value()));
2993 archive.write(key + ".inplace", torch::full({1}, this->options_.inplace()));
2994
2995 return archive;
2996 }
2997
3003 inline torch::serialize::InputArchive &
3004 read(torch::serialize::InputArchive &archive,
3005 const std::string &key = "threshold") override {
3006 torch::Tensor tensor;
3007
3008 archive.read(key + ".type", tensor);
3009 if (tensor.item<int64_t>() != static_cast<int64_t>(activation::threshold))
3010 throw std::runtime_error("activation mismatch");
3011
3012 archive.read(key + ".threshold", tensor);
3013 this->options_.threshold(tensor.item<double>());
3014 archive.read(key + ".value", tensor);
3015 this->options_.value(tensor.item<double>());
3016 archive.read(key + ".inplace", tensor);
3017 this->options_.inplace(tensor.item<bool>());
3018
3019 return archive;
3020 }
3021
3022private:
3023 torch::nn::functional::ThresholdFuncOptions options_;
3024};
3025
3026} // namespace iganet
Abstract activation function structure.
Definition activation.hpp:65
~ActivationFunction() override=default
void pretty_print(std::ostream &os) const noexcept override=0
Returns a string representation of the activation function.
virtual torch::serialize::OutputArchive & write(torch::serialize::OutputArchive &archive, const std::string &key) const =0
Writes the activation function into a torch::serialize::OutputArchive object.
virtual torch::serialize::InputArchive & read(torch::serialize::InputArchive &archive, const std::string &key)=0
Reads the activation function from a torch::serialize::InputArchive object.
virtual torch::Tensor apply(const torch::Tensor &input) const =0
Applies the activation function to the given input.
Batch Normalization as described in the paper.
Definition activation.hpp:159
void pretty_print(std::ostream &os) const noexcept override
Returns a string representation of the activation function.
Definition activation.hpp:230
torch::Tensor & running_mean()
Returns non-constant reference to running mean.
Definition activation.hpp:206
torch::Tensor running_var_
Definition activation.hpp:307
const torch::Tensor & running_mean() const
Returns constant reference to running mean.
Definition activation.hpp:202
torch::serialize::OutputArchive & write(torch::serialize::OutputArchive &archive, const std::string &key="batch_norm") const override
Writes the activation function into a torch::serialize::OutputArchive object.
Definition activation.hpp:256
const torch::Tensor & running_var() const
Returns constant reference to running variance.
Definition activation.hpp:210
torch::Tensor running_mean_
Definition activation.hpp:307
const torch::nn::functional::BatchNormFuncOptions & options() const
Returns constant reference to options.
Definition activation.hpp:218
~BatchNorm() override=default
BatchNorm(torch::Tensor running_mean, torch::Tensor running_var, const torch::Tensor &weight, const torch::Tensor &bias, double eps, double momentum, bool training=false)
Provides the BatchNorm operation.
Definition activation.hpp:178
torch::nn::functional::BatchNormFuncOptions & options()
Returns non-constant reference to options.
Definition activation.hpp:224
torch::Tensor & running_var()
Returns non-constant reference to running var.
Definition activation.hpp:214
torch::nn::functional::BatchNormFuncOptions options_
Definition activation.hpp:306
torch::serialize::InputArchive & read(torch::serialize::InputArchive &archive, const std::string &key="batch_norm") override
Reads the activation function from a torch::serialize::InputArchive object.
Definition activation.hpp:283
BatchNorm(torch::Tensor running_mean, torch::Tensor running_var, torch::nn::functional::BatchNormFuncOptions options={})
Provides the BatchNorm operation.
Definition activation.hpp:165
torch::Tensor apply(const torch::Tensor &input) const override
Applies the activation function to the given input.
Definition activation.hpp:195
Continuously Differentiable Exponential Linear Units activation function.
Definition activation.hpp:316
torch::nn::functional::CELUFuncOptions & options()
Returns non-constant reference to options.
Definition activation.hpp:347
CELU(torch::nn::functional::CELUFuncOptions options={})
Provides the CELU operation.
Definition activation.hpp:320
torch::nn::functional::CELUFuncOptions options_
Definition activation.hpp:397
const torch::nn::functional::CELUFuncOptions & options() const
Returns constant reference to options.
Definition activation.hpp:341
torch::serialize::InputArchive & read(torch::serialize::InputArchive &archive, const std::string &key="celu") override
Reads the activation function from a torch::serialize::InputArchive object.
Definition activation.hpp:380
CELU(double alpha, bool inplace=false)
Provides the CELU operation.
Definition activation.hpp:326
void pretty_print(std::ostream &os) const noexcept override
Returns a string representation of the activation function.
Definition activation.hpp:351
~CELU() override=default
torch::Tensor apply(const torch::Tensor &input) const override
Applies the activation function to the given input.
Definition activation.hpp:335
torch::serialize::OutputArchive & write(torch::serialize::OutputArchive &archive, const std::string &key="celu") const override
Writes the activation function into a torch::serialize::OutputArchive object.
Definition activation.hpp:362
Exponential Linear Units activation function.
Definition activation.hpp:409
const torch::nn::functional::ELUFuncOptions & options() const
Returns constant reference to options.
Definition activation.hpp:434
~ELU() override=default
torch::nn::functional::ELUFuncOptions & options()
Returns non-constant reference to options.
Definition activation.hpp:440
torch::serialize::OutputArchive & write(torch::serialize::OutputArchive &archive, const std::string &key="elu") const override
Writes the activation function into a torch::serialize::OutputArchive object.
Definition activation.hpp:456
ELU(double alpha, bool inplace=false)
Provides the ELU operation.
Definition activation.hpp:419
void pretty_print(std::ostream &os=Log(log::info)) const noexcept override
Returns a string representation of the activation function.
Definition activation.hpp:445
torch::Tensor apply(const torch::Tensor &input) const override
Applies the activation function to the given input.
Definition activation.hpp:428
torch::nn::functional::ELUFuncOptions options_
Definition activation.hpp:491
ELU(torch::nn::functional::ELUFuncOptions options={})
Provides the ELU operation.
Definition activation.hpp:413
torch::serialize::InputArchive & read(torch::serialize::InputArchive &archive, const std::string &key="elu") override
Reads the activation function from a torch::serialize::InputArchive object.
Definition activation.hpp:474
Gaussian Error Linear Units activation function.
Definition activation.hpp:502
torch::serialize::OutputArchive & write(torch::serialize::OutputArchive &archive, const std::string &key="gelu") const override
Writes the activation function into a torch::serialize::OutputArchive object.
Definition activation.hpp:527
GELU()=default
void pretty_print(std::ostream &os) const noexcept override
Returns a string representation of the activation function.
Definition activation.hpp:517
~GELU() override=default
torch::Tensor apply(const torch::Tensor &input) const override
Applies the activation function to the given input.
Definition activation.hpp:511
torch::serialize::InputArchive & read(torch::serialize::InputArchive &archive, const std::string &key="gelu") override
Reads the activation function from a torch::serialize::InputArchive object.
Definition activation.hpp:541
Grated Linear Units activation function.
Definition activation.hpp:562
~GLU() override=default
torch::serialize::InputArchive & read(torch::serialize::InputArchive &archive, const std::string &key="glu") override
Reads the activation function from a torch::serialize::InputArchive object.
Definition activation.hpp:622
const torch::nn::functional::GLUFuncOptions & options() const
Returns constant reference to options.
Definition activation.hpp:585
torch::Tensor apply(const torch::Tensor &input) const override
Applies the activation function to the given input.
Definition activation.hpp:579
torch::serialize::OutputArchive & write(torch::serialize::OutputArchive &archive, const std::string &key="glu") const override
Writes the activation function into a torch::serialize::OutputArchive object.
Definition activation.hpp:606
torch::nn::functional::GLUFuncOptions & options()
Returns non-constant reference to options.
Definition activation.hpp:591
torch::nn::functional::GLUFuncOptions options_
Definition activation.hpp:637
void pretty_print(std::ostream &os) const noexcept override
Returns a string representation of the activation function.
Definition activation.hpp:595
GLU(torch::nn::functional::GLUFuncOptions options={})
Provides the GLU operation.
Definition activation.hpp:566
GLU(int64_t dim)
Provides the GLU operation.
Definition activation.hpp:571
Group Normalization over a mini-batch of inputs as described in the paper Group Normalization,...
Definition activation.hpp:642
torch::Tensor apply(const torch::Tensor &input) const override
Applies the activation function to the given input.
Definition activation.hpp:671
torch::serialize::InputArchive & read(torch::serialize::InputArchive &archive, const std::string &key="group_norm") override
Reads the activation function from a torch::serialize::InputArchive object.
Definition activation.hpp:724
torch::nn::functional::GroupNormFuncOptions & options()
Returns non-constant reference to options.
Definition activation.hpp:683
const torch::nn::functional::GroupNormFuncOptions & options() const
Returns constant reference to options.
Definition activation.hpp:677
~GroupNorm() override=default
GroupNorm(int64_t num_groups, const torch::Tensor &weight, const torch::Tensor &bias, double eps)
Provides the GroupNorm operation.
Definition activation.hpp:659
GroupNorm(int64_t num_groups)
Provides the GroupNorm operation.
Definition activation.hpp:646
void pretty_print(std::ostream &os=Log(log::info)) const noexcept override
Returns a string representation of the activation function.
Definition activation.hpp:690
torch::serialize::OutputArchive & write(torch::serialize::OutputArchive &archive, const std::string &key="group_norm") const override
Writes the activation function into a torch::serialize::OutputArchive object.
Definition activation.hpp:707
torch::nn::functional::GroupNormFuncOptions options_
Definition activation.hpp:741
GroupNorm(torch::nn::functional::GroupNormFuncOptions options)
Provides the GroupNorm operation.
Definition activation.hpp:651
Gumbel-Softmax distribution activation function.
Definition activation.hpp:745
const torch::nn::functional::GumbelSoftmaxFuncOptions & options() const
Returns constant reference to options.
Definition activation.hpp:775
GumbelSoftmax(torch::nn::functional::GumbelSoftmaxFuncOptions options={})
Provides the GumbelSoftmax operation.
Definition activation.hpp:749
~GumbelSoftmax() override=default
torch::Tensor apply(const torch::Tensor &input) const override
Applies the activation function to the given input.
Definition activation.hpp:768
torch::nn::functional::GumbelSoftmaxFuncOptions & options()
Returns non-constant reference to options.
Definition activation.hpp:781
void pretty_print(std::ostream &os=Log(log::info)) const noexcept override
Returns a string representation of the activation function.
Definition activation.hpp:788
GumbelSoftmax(double tau, int dim, bool hard)
Provides the GumbelSoftmax operation.
Definition activation.hpp:757
torch::nn::functional::GumbelSoftmaxFuncOptions options_
Definition activation.hpp:837
torch::serialize::OutputArchive & write(torch::serialize::OutputArchive &archive, const std::string &key="gumbel_softmax") const override
Writes the activation function into a torch::serialize::OutputArchive object.
Definition activation.hpp:799
torch::serialize::InputArchive & read(torch::serialize::InputArchive &archive, const std::string &key="gumbel_softmax") override
Reads the activation function from a torch::serialize::InputArchive object.
Definition activation.hpp:817
Hard shrinkish activation function.
Definition activation.hpp:841
torch::serialize::InputArchive & read(torch::serialize::InputArchive &archive, const std::string &key="hardshrink") override
Reads the activation function from a torch::serialize::InputArchive object.
Definition activation.hpp:905
void pretty_print(std::ostream &os=Log(log::info)) const noexcept override
Returns a string representation of the activation function.
Definition activation.hpp:878
~Hardshrink() override=default
torch::nn::functional::HardshrinkFuncOptions & options()
Returns non-constant reference to options.
Definition activation.hpp:871
torch::serialize::OutputArchive & write(torch::serialize::OutputArchive &archive, const std::string &key="hardshrink") const override
Writes the activation function into a torch::serialize::OutputArchive object.
Definition activation.hpp:889
Hardshrink(double lambda)
Provides the Hardshrink operation.
Definition activation.hpp:850
torch::nn::functional::HardshrinkFuncOptions options_
Definition activation.hpp:920
torch::Tensor apply(const torch::Tensor &input) const override
Applies the activation function to the given input.
Definition activation.hpp:859
Hardshrink(torch::nn::functional::HardshrinkFuncOptions options={})
Provides the Hardshrink operation.
Definition activation.hpp:845
const torch::nn::functional::HardshrinkFuncOptions & options() const
Returns constant reference to options.
Definition activation.hpp:865
Hardsigmoid activation function.
Definition activation.hpp:933
torch::Tensor apply(const torch::Tensor &input) const override
Applies the activation function to the given input.
Definition activation.hpp:942
torch::serialize::InputArchive & read(torch::serialize::InputArchive &archive, const std::string &key="hardsigmoid") override
Reads the activation function from a torch::serialize::InputArchive object.
Definition activation.hpp:974
torch::serialize::OutputArchive & write(torch::serialize::OutputArchive &archive, const std::string &key="hardsigmoid") const override
Writes the activation function into a torch::serialize::OutputArchive object.
Definition activation.hpp:959
void pretty_print(std::ostream &os=Log(log::info)) const noexcept override
Returns a string representation of the activation function.
Definition activation.hpp:949
~Hardsigmoid() override=default
Hardswish activation function.
Definition activation.hpp:996
~Hardswish() override=default
Hardswish()=default
torch::serialize::OutputArchive & write(torch::serialize::OutputArchive &archive, const std::string &key="hardswish") const override
Writes the activation function into a torch::serialize::OutputArchive object.
Definition activation.hpp:1022
torch::Tensor apply(const torch::Tensor &input) const override
Applies the activation function to the given input.
Definition activation.hpp:1005
torch::serialize::InputArchive & read(torch::serialize::InputArchive &archive, const std::string &key="hardswish") override
Reads the activation function from a torch::serialize::InputArchive object.
Definition activation.hpp:1036
void pretty_print(std::ostream &os=Log(log::info)) const noexcept override
Returns a string representation of the activation function.
Definition activation.hpp:1012
Hardtanh activation function.
Definition activation.hpp:1058
const torch::nn::functional::HardtanhFuncOptions & options() const
Returns constant reference to options.
Definition activation.hpp:1087
torch::serialize::InputArchive & read(torch::serialize::InputArchive &archive, const std::string &key="hardtanh") override
Reads the activation function from a torch::serialize::InputArchive object.
Definition activation.hpp:1133
torch::Tensor apply(const torch::Tensor &input) const override
Applies the activation function to the given input.
Definition activation.hpp:1081
Hardtanh(const torch::nn::functional::HardtanhFuncOptions &options={})
Provides the Hardtanh operation.
Definition activation.hpp:1062
torch::nn::functional::HardtanhFuncOptions & options()
Returns non-constant reference to options.
Definition activation.hpp:1093
~Hardtanh() override=default
Hardtanh(double min_val, double max_val, bool inplace=false)
Provides the Hardtanh operation.
Definition activation.hpp:1070
torch::nn::functional::HardtanhFuncOptions options_
Definition activation.hpp:1152
torch::serialize::OutputArchive & write(torch::serialize::OutputArchive &archive, const std::string &key="hardtanh") const override
Writes the activation function into a torch::serialize::OutputArchive object.
Definition activation.hpp:1113
void pretty_print(std::ostream &os=Log(log::info)) const noexcept override
Returns a string representation of the activation function.
Definition activation.hpp:1100
Instance Normalization as described in the paper.
Definition activation.hpp:1159
void pretty_print(std::ostream &os=Log(log::info)) const noexcept override
Returns a string representation of the activation function.
Definition activation.hpp:1213
torch::nn::functional::InstanceNormFuncOptions options_
Definition activation.hpp:1282
torch::nn::functional::InstanceNormFuncOptions & options()
Returns non-constant reference to options.
Definition activation.hpp:1206
torch::Tensor apply(const torch::Tensor &input) const override
Applies the activation function to the given input.
Definition activation.hpp:1194
torch::serialize::OutputArchive & write(torch::serialize::OutputArchive &archive, const std::string &key="instance_norm") const override
Writes the activation function into a torch::serialize::OutputArchive object.
Definition activation.hpp:1234
const torch::nn::functional::InstanceNormFuncOptions & options() const
Returns constant reference to options.
Definition activation.hpp:1200
InstanceNorm(torch::nn::functional::InstanceNormFuncOptions options={})
Provides the InstanceNorm operation.
Definition activation.hpp:1163
InstanceNorm(const torch::Tensor &running_mean, const torch::Tensor &running_var, const torch::Tensor &weight, const torch::Tensor &bias, double eps, double momentum, bool use_input_stats=true)
Provides the InstanceNorm operation.
Definition activation.hpp:1175
~InstanceNorm() override=default
torch::serialize::InputArchive & read(torch::serialize::InputArchive &archive, const std::string &key="instance_norm") override
Reads the activation function from a torch::serialize::InputArchive object.
Definition activation.hpp:1258
Layer Normalization as described in the paper.
Definition activation.hpp:1288
const torch::nn::functional::LayerNormFuncOptions & options() const
Returns constant reference to options.
Definition activation.hpp:1326
torch::serialize::OutputArchive & write(torch::serialize::OutputArchive &archive, const std::string &key="layer_norm") const override
Writes the activation function into a torch::serialize::OutputArchive object.
Definition activation.hpp:1356
LayerNorm(std::vector< int64_t > normalized_shape, const torch::Tensor &weight, const torch::Tensor &bias, double eps)
Provides the LayerNorm operation.
Definition activation.hpp:1306
LayerNorm(std::vector< int64_t > normalized_shape)
Provides the LayerNorm operation.
Definition activation.hpp:1292
~LayerNorm() override=default
torch::nn::functional::LayerNormFuncOptions & options()
Returns non-constant reference to options.
Definition activation.hpp:1332
void pretty_print(std::ostream &os) const noexcept override
Returns a string representation of the activation function.
Definition activation.hpp:1338
LayerNorm(torch::nn::functional::LayerNormFuncOptions options)
Provides the LayerNorm operation.
Definition activation.hpp:1298
torch::nn::functional::LayerNormFuncOptions options_
Definition activation.hpp:1390
torch::Tensor apply(const torch::Tensor &input) const override
Applies the activation function to the given input.
Definition activation.hpp:1320
torch::serialize::InputArchive & read(torch::serialize::InputArchive &archive, const std::string &key="layer_norm") override
Reads the activation function from a torch::serialize::InputArchive object.
Definition activation.hpp:1373
Leaky ReLU activation function.
Definition activation.hpp:1402
~LeakyReLU() override=default
const torch::nn::functional::LeakyReLUFuncOptions & options() const
Returns constant reference to options.
Definition activation.hpp:1428
LeakyReLU(torch::nn::functional::LeakyReLUFuncOptions options={})
Provides the LeakyReLU operation.
Definition activation.hpp:1406
torch::serialize::OutputArchive & write(torch::serialize::OutputArchive &archive, const std::string &key="leaky_relu") const override
Writes the activation function into a torch::serialize::OutputArchive object.
Definition activation.hpp:1452
torch::nn::functional::LeakyReLUFuncOptions options_
Definition activation.hpp:1488
torch::Tensor apply(const torch::Tensor &input) const override
Applies the activation function to the given input.
Definition activation.hpp:1422
torch::nn::functional::LeakyReLUFuncOptions & options()
Returns non-constant reference to options.
Definition activation.hpp:1434
torch::serialize::InputArchive & read(torch::serialize::InputArchive &archive, const std::string &key="leaky_relu") override
Reads the activation function from a torch::serialize::InputArchive object.
Definition activation.hpp:1471
void pretty_print(std::ostream &os) const noexcept override
Returns a string representation of the activation function.
Definition activation.hpp:1440
LeakyReLU(double negative_slope, bool inplace=false)
Provides the LeakyReLU operation.
Definition activation.hpp:1412
Local response Normalization.
Definition activation.hpp:1492
torch::nn::functional::LocalResponseNormFuncOptions & options()
Returns non-constant reference to options.
Definition activation.hpp:1534
LocalResponseNorm(const torch::nn::functional::LocalResponseNormFuncOptions &options)
Provides the LocalResponseNorm operation.
Definition activation.hpp:1501
torch::nn::functional::LocalResponseNormFuncOptions options_
Definition activation.hpp:1597
LocalResponseNorm(int64_t size, double alpha, double beta, double k)
Provides the LocalResponseNorm operation.
Definition activation.hpp:1510
LocalResponseNorm(int64_t size)
Provides the LocalResponseNorm operation.
Definition activation.hpp:1496
torch::serialize::OutputArchive & write(torch::serialize::OutputArchive &archive, const std::string &key="local_response_norm") const override
Writes the activation function into a torch::serialize::OutputArchive object.
Definition activation.hpp:1552
~LocalResponseNorm() override=default
torch::Tensor apply(const torch::Tensor &input) const override
Applies the activation function to the given input.
Definition activation.hpp:1521
const torch::nn::functional::LocalResponseNormFuncOptions & options() const
Returns constant reference to options.
Definition activation.hpp:1528
void pretty_print(std::ostream &os) const noexcept override
Returns a string representation of the activation function.
Definition activation.hpp:1540
torch::serialize::InputArchive & read(torch::serialize::InputArchive &archive, const std::string &key="local_response_norm") override
Reads the activation function from a torch::serialize::InputArchive object.
Definition activation.hpp:1575
LogSigmoid activation function.
Definition activation.hpp:1605
~LogSigmoid() override=default
torch::serialize::InputArchive & read(torch::serialize::InputArchive &archive, const std::string &key="logsigmoid") override
Reads the activation function from a torch::serialize::InputArchive object.
Definition activation.hpp:1644
void pretty_print(std::ostream &os) const noexcept override
Returns a string representation of the activation function.
Definition activation.hpp:1620
torch::serialize::OutputArchive & write(torch::serialize::OutputArchive &archive, const std::string &key="logsigmoid") const override
Writes the activation function into a torch::serialize::OutputArchive object.
Definition activation.hpp:1630
torch::Tensor apply(const torch::Tensor &input) const override
Applies the activation function to the given input.
Definition activation.hpp:1614
LogSigmoid()=default
LogSoftmax activation function.
Definition activation.hpp:1664
torch::Tensor apply(const torch::Tensor &input) const override
Applies the activation function to the given input.
Definition activation.hpp:1682
torch::nn::functional::LogSoftmaxFuncOptions & options()
Returns non-constant reference to options.
Definition activation.hpp:1694
torch::serialize::OutputArchive & write(torch::serialize::OutputArchive &archive, const std::string &key="logsoftmax") const override
Writes the activation function into a torch::serialize::OutputArchive object.
Definition activation.hpp:1711
LogSoftmax(int64_t dim)
Provides the LogSoftmax operation.
Definition activation.hpp:1668
void pretty_print(std::ostream &os) const noexcept override
Returns a string representation of the activation function.
Definition activation.hpp:1700
LogSoftmax(const torch::nn::functional::LogSoftmaxFuncOptions &options)
Provides the LogSoftmax operation.
Definition activation.hpp:1673
torch::serialize::InputArchive & read(torch::serialize::InputArchive &archive, const std::string &key="logsoftmax") override
Reads the activation function from a torch::serialize::InputArchive object.
Definition activation.hpp:1725
torch::nn::functional::LogSoftmaxFuncOptions options_
Definition activation.hpp:1737
~LogSoftmax() override=default
const torch::nn::functional::LogSoftmaxFuncOptions & options() const
Returns constant reference to options.
Definition activation.hpp:1688
Mish activation function.
Definition activation.hpp:1745
torch::Tensor apply(const torch::Tensor &input) const override
Applies the activation function to the given input.
Definition activation.hpp:1754
void pretty_print(std::ostream &os) const noexcept override
Returns a string representation of the activation function.
Definition activation.hpp:1760
torch::serialize::InputArchive & read(torch::serialize::InputArchive &archive, const std::string &key="mish") override
Reads the activation function from a torch::serialize::InputArchive object.
Definition activation.hpp:1784
~Mish() override=default
Mish()=default
torch::serialize::OutputArchive & write(torch::serialize::OutputArchive &archive, const std::string &key="mish") const override
Writes the activation function into a torch::serialize::OutputArchive object.
Definition activation.hpp:1770
No-op activation function.
Definition activation.hpp:107
torch::serialize::OutputArchive & write(torch::serialize::OutputArchive &archive, const std::string &key="none") const override
Writes the activation function into a torch::serialize::OutputArchive object.
Definition activation.hpp:128
void pretty_print(std::ostream &os) const noexcept override
Returns a string representation of the activation function.
Definition activation.hpp:118
torch::Tensor apply(const torch::Tensor &input) const override
Applies the activation function to the given input.
Definition activation.hpp:112
torch::serialize::InputArchive & read(torch::serialize::InputArchive &archive, const std::string &key="none") override
Reads the activation function from a torch::serialize::InputArchive object.
Definition activation.hpp:142
Lp Normalization.
Definition activation.hpp:1797
~Normalize() override=default
torch::serialize::OutputArchive & write(torch::serialize::OutputArchive &archive, const std::string &key="normalize") const override
Writes the activation function into a torch::serialize::OutputArchive object.
Definition activation.hpp:1847
torch::serialize::InputArchive & read(torch::serialize::InputArchive &archive, const std::string &key="normalize") override
Reads the activation function from a torch::serialize::InputArchive object.
Definition activation.hpp:1865
torch::nn::functional::NormalizeFuncOptions & options()
Returns non-constant reference to options.
Definition activation.hpp:1830
Normalize(double p, double eps, int64_t dim)
Provides the Normalize operation.
Definition activation.hpp:1808
Normalize(torch::nn::functional::NormalizeFuncOptions options={})
Provides the Normalize operation.
Definition activation.hpp:1801
torch::nn::functional::NormalizeFuncOptions options_
Definition activation.hpp:1884
const torch::nn::functional::NormalizeFuncOptions & options() const
Returns constant reference to options.
Definition activation.hpp:1824
torch::Tensor apply(const torch::Tensor &input) const override
Applies the activation function to the given input.
Definition activation.hpp:1818
void pretty_print(std::ostream &os) const noexcept override
Returns a string representation of the activation function.
Definition activation.hpp:1836
PReLU activation function.
Definition activation.hpp:1888
torch::Tensor apply(const torch::Tensor &input) const override
Applies the activation function to the given input.
Definition activation.hpp:1907
void pretty_print(std::ostream &os) const noexcept override
Returns a string representation of the activation function.
Definition activation.hpp:1913
PReLU(torch::Tensor weight)
Provides the PReLU operation.
Definition activation.hpp:1892
torch::Tensor weight_
Definition activation.hpp:1955
~PReLU() override=default
torch::serialize::OutputArchive & write(torch::serialize::OutputArchive &archive, const std::string &key="prelu") const override
Writes the activation function into a torch::serialize::OutputArchive object.
Definition activation.hpp:1926
torch::serialize::InputArchive & read(torch::serialize::InputArchive &archive, const std::string &key="prelu") override
Reads the activation function from a torch::serialize::InputArchive object.
Definition activation.hpp:1941
const torch::Tensor & weight() const
Returns constant reference to weights.
Definition activation.hpp:1898
torch::Tensor & weight()
Returns non-constant reference to weights.
Definition activation.hpp:1902
Randomized ReLU activation function.
Definition activation.hpp:2133
RReLU(double lower, double upper, bool inplace=false)
Provides the RReLU operation.
Definition activation.hpp:2144
RReLU(const torch::nn::functional::RReLUFuncOptions &options={})
Provides the RReLU operation.
Definition activation.hpp:2137
const torch::nn::functional::RReLUFuncOptions & options() const
Returns constant reference to options.
Definition activation.hpp:2161
torch::Tensor apply(const torch::Tensor &input) const override
Applies the activation function to the given input.
Definition activation.hpp:2155
torch::nn::functional::RReLUFuncOptions options_
Definition activation.hpp:2222
~RReLU() override=default
torch::serialize::InputArchive & read(torch::serialize::InputArchive &archive, const std::string &key="rrelu") override
Reads the activation function from a torch::serialize::InputArchive object.
Definition activation.hpp:2203
torch::nn::functional::RReLUFuncOptions & options()
Returns non-constant reference to options.
Definition activation.hpp:2167
void pretty_print(std::ostream &os) const noexcept override
Returns a string representation of the activation function.
Definition activation.hpp:2171
torch::serialize::OutputArchive & write(torch::serialize::OutputArchive &archive, const std::string &key="rrelu") const override
Writes the activation function into a torch::serialize::OutputArchive object.
Definition activation.hpp:2183
ReLU6 activation function.
Definition activation.hpp:2046
~ReLU6() override=default
ReLU6(torch::nn::functional::ReLU6FuncOptions options={})
Provides the ReLU6 operation.
Definition activation.hpp:2050
torch::nn::functional::ReLU6FuncOptions & options()
Returns non-constant reference to options.
Definition activation.hpp:2075
torch::Tensor apply(const torch::Tensor &input) const override
Applies the activation function to the given input.
Definition activation.hpp:2063
const torch::nn::functional::ReLU6FuncOptions & options() const
Returns constant reference to options.
Definition activation.hpp:2069
torch::serialize::OutputArchive & write(torch::serialize::OutputArchive &archive, const std::string &key="relu6") const override
Writes the activation function into a torch::serialize::OutputArchive object.
Definition activation.hpp:2090
ReLU6(bool inplace)
Provides the ReLU6 operation.
Definition activation.hpp:2055
void pretty_print(std::ostream &os) const noexcept override
Returns a string representation of the activation function.
Definition activation.hpp:2079
torch::nn::functional::ReLU6FuncOptions options_
Definition activation.hpp:2121
torch::serialize::InputArchive & read(torch::serialize::InputArchive &archive, const std::string &key="relu6") override
Reads the activation function from a torch::serialize::InputArchive object.
Definition activation.hpp:2106
ReLU activation function.
Definition activation.hpp:1963
torch::nn::functional::ReLUFuncOptions options_
Definition activation.hpp:2038
~ReLU() override=default
torch::Tensor apply(const torch::Tensor &input) const override
Applies the activation function to the given input.
Definition activation.hpp:1980
ReLU(bool inplace)
Provides the ReLU operation.
Definition activation.hpp:1972
torch::serialize::OutputArchive & write(torch::serialize::OutputArchive &archive, const std::string &key="relu") const override
Writes the activation function into a torch::serialize::OutputArchive object.
Definition activation.hpp:2007
torch::nn::functional::ReLUFuncOptions & options()
Returns non-constant reference to options.
Definition activation.hpp:1992
ReLU(torch::nn::functional::ReLUFuncOptions options={})
Provides the ReLU operation.
Definition activation.hpp:1967
const torch::nn::functional::ReLUFuncOptions & options() const
Returns constant reference to options.
Definition activation.hpp:1986
void pretty_print(std::ostream &os) const noexcept override
Returns a string representation of the activation function.
Definition activation.hpp:1996
torch::serialize::InputArchive & read(torch::serialize::InputArchive &archive, const std::string &key="relu") override
Reads the activation function from a torch::serialize::InputArchive object.
Definition activation.hpp:2023
SELU activation function.
Definition activation.hpp:2233
void pretty_print(std::ostream &os) const noexcept override
Returns a string representation of the activation function.
Definition activation.hpp:2266
~SELU() override=default
torch::serialize::InputArchive & read(torch::serialize::InputArchive &archive, const std::string &key="selu") override
Reads the activation function from a torch::serialize::InputArchive object.
Definition activation.hpp:2293
torch::nn::functional::SELUFuncOptions & options()
Returns non-constant reference to options.
Definition activation.hpp:2262
torch::Tensor apply(const torch::Tensor &input) const override
Applies the activation function to the given input.
Definition activation.hpp:2250
torch::serialize::OutputArchive & write(torch::serialize::OutputArchive &archive, const std::string &key="selu") const override
Writes the activation function into a torch::serialize::OutputArchive object.
Definition activation.hpp:2277
const torch::nn::functional::SELUFuncOptions & options() const
Returns constant reference to options.
Definition activation.hpp:2256
SELU(bool inplace)
Provides the SELU operation.
Definition activation.hpp:2242
SELU(torch::nn::functional::SELUFuncOptions options={})
Provides the SELU operation.
Definition activation.hpp:2237
torch::nn::functional::SELUFuncOptions options_
Definition activation.hpp:2308
Sigmoid Linear Unit activation function.
Definition activation.hpp:2368
torch::serialize::OutputArchive & write(torch::serialize::OutputArchive &archive, const std::string &key="silu") const override
Writes the activation function into a torch::serialize::OutputArchive object.
Definition activation.hpp:2389
void pretty_print(std::ostream &os) const noexcept override
Returns a string representation of the activation function.
Definition activation.hpp:2379
torch::Tensor apply(const torch::Tensor &input) const override
Applies the activation function to the given input.
Definition activation.hpp:2373
torch::serialize::InputArchive & read(torch::serialize::InputArchive &archive, const std::string &key="silu") override
Reads the activation function from a torch::serialize::InputArchive object.
Definition activation.hpp:2403
Sigmoid activation function.
Definition activation.hpp:2316
void pretty_print(std::ostream &os) const noexcept override
Returns a string representation of the activation function.
Definition activation.hpp:2327
torch::Tensor apply(const torch::Tensor &input) const override
Applies the activation function to the given input.
Definition activation.hpp:2321
torch::serialize::InputArchive & read(torch::serialize::InputArchive &archive, const std::string &key="sigmoid") override
Reads the activation function from a torch::serialize::InputArchive object.
Definition activation.hpp:2351
torch::serialize::OutputArchive & write(torch::serialize::OutputArchive &archive, const std::string &key="sigmoid") const override
Writes the activation function into a torch::serialize::OutputArchive object.
Definition activation.hpp:2337
Softmax activation function.
Definition activation.hpp:2422
torch::nn::functional::SoftmaxFuncOptions & options()
Returns non-constant reference to options.
Definition activation.hpp:2451
Softmax(const torch::nn::functional::SoftmaxFuncOptions &options)
Provides the Softmax operation.
Definition activation.hpp:2431
torch::serialize::OutputArchive & write(torch::serialize::OutputArchive &archive, const std::string &key="softmax") const override
Writes the activation function into a torch::serialize::OutputArchive object.
Definition activation.hpp:2468
const torch::nn::functional::SoftmaxFuncOptions & options() const
Returns constant reference to options.
Definition activation.hpp:2445
void pretty_print(std::ostream &os) const noexcept override
Returns a string representation of the activation function.
Definition activation.hpp:2457
~Softmax() override=default
torch::Tensor apply(const torch::Tensor &input) const override
Applies the activation function to the given input.
Definition activation.hpp:2439
Softmax(int64_t dim)
Provides the Softmax operation.
Definition activation.hpp:2426
torch::nn::functional::SoftmaxFuncOptions options_
Definition activation.hpp:2499
torch::serialize::InputArchive & read(torch::serialize::InputArchive &archive, const std::string &key="softmax") override
Reads the activation function from a torch::serialize::InputArchive object.
Definition activation.hpp:2484
Softmin activation function.
Definition activation.hpp:2507
torch::serialize::OutputArchive & write(torch::serialize::OutputArchive &archive, const std::string &key="softmin") const override
Writes the activation function into a torch::serialize::OutputArchive object.
Definition activation.hpp:2553
Softmin(int64_t dim)
Provides the Softmin operation.
Definition activation.hpp:2511
torch::Tensor apply(const torch::Tensor &input) const override
Applies the activation function to the given input.
Definition activation.hpp:2524
torch::nn::functional::SoftminFuncOptions options_
Definition activation.hpp:2584
const torch::nn::functional::SoftminFuncOptions & options() const
Returns constant reference to options.
Definition activation.hpp:2530
~Softmin() override=default
void pretty_print(std::ostream &os) const noexcept override
Returns a string representation of the activation function.
Definition activation.hpp:2542
torch::serialize::InputArchive & read(torch::serialize::InputArchive &archive, const std::string &key="softmin") override
Reads the activation function from a torch::serialize::InputArchive object.
Definition activation.hpp:2569
torch::nn::functional::SoftminFuncOptions & options()
Returns non-constant reference to options.
Definition activation.hpp:2536
Softmin(const torch::nn::functional::SoftminFuncOptions &options)
Provides the Softmin operation.
Definition activation.hpp:2516
Softplus activation function.
Definition activation.hpp:2592
torch::nn::functional::SoftplusFuncOptions options_
Definition activation.hpp:2676
torch::Tensor apply(const torch::Tensor &input) const override
Applies the activation function to the given input.
Definition activation.hpp:2612
Softplus(torch::nn::functional::SoftplusFuncOptions options={})
Provides the Softplus operation.
Definition activation.hpp:2596
const torch::nn::functional::SoftplusFuncOptions & options() const
Returns constant reference to options.
Definition activation.hpp:2618
Softplus(double beta, double threshold)
Provides the Softplus operation.
Definition activation.hpp:2602
torch::nn::functional::SoftplusFuncOptions & options()
Returns non-constant reference to options.
Definition activation.hpp:2624
torch::serialize::InputArchive & read(torch::serialize::InputArchive &archive, const std::string &key="softplus") override
Reads the activation function from a torch::serialize::InputArchive object.
Definition activation.hpp:2659
torch::serialize::OutputArchive & write(torch::serialize::OutputArchive &archive, const std::string &key="softplus") const override
Writes the activation function into a torch::serialize::OutputArchive object.
Definition activation.hpp:2641
void pretty_print(std::ostream &os) const noexcept override
Returns a string representation of the activation function.
Definition activation.hpp:2630
~Softplus() override=default
Softshrink activation function.
Definition activation.hpp:2689
const torch::nn::functional::SoftshrinkFuncOptions & options() const
Returns constant reference to options.
Definition activation.hpp:2713
Softshrink(double lambda)
Provides the Softshrink operation.
Definition activation.hpp:2698
torch::serialize::OutputArchive & write(torch::serialize::OutputArchive &archive, const std::string &key="softshrink") const override
Writes the activation function into a torch::serialize::OutputArchive object.
Definition activation.hpp:2736
Softshrink(torch::nn::functional::SoftshrinkFuncOptions options={})
Provides the Softshrink operation.
Definition activation.hpp:2693
torch::Tensor apply(const torch::Tensor &input) const override
Applies the activation function to the given input.
Definition activation.hpp:2707
torch::serialize::InputArchive & read(torch::serialize::InputArchive &archive, const std::string &key="softshrink") override
Reads the activation function from a torch::serialize::InputArchive object.
Definition activation.hpp:2752
torch::nn::functional::SoftshrinkFuncOptions options_
Definition activation.hpp:2767
torch::nn::functional::SoftshrinkFuncOptions & options()
Returns non-constant reference to options.
Definition activation.hpp:2719
~Softshrink() override=default
void pretty_print(std::ostream &os) const noexcept override
Returns a string representation of the activation function.
Definition activation.hpp:2725
Softsign activation function.
Definition activation.hpp:2775
torch::Tensor apply(const torch::Tensor &input) const override
Applies the activation function to the given input.
Definition activation.hpp:2780
void pretty_print(std::ostream &os) const noexcept override
Returns a string representation of the activation function.
Definition activation.hpp:2786
torch::serialize::InputArchive & read(torch::serialize::InputArchive &archive, const std::string &key="softsign") override
Reads the activation function from a torch::serialize::InputArchive object.
Definition activation.hpp:2810
torch::serialize::OutputArchive & write(torch::serialize::OutputArchive &archive, const std::string &key="softsign") const override
Writes the activation function into a torch::serialize::OutputArchive object.
Definition activation.hpp:2796
Tanh activation function.
Definition activation.hpp:2827
void pretty_print(std::ostream &os) const noexcept override
Returns a string representation of the activation function.
Definition activation.hpp:2838
torch::serialize::OutputArchive & write(torch::serialize::OutputArchive &archive, const std::string &key="tanh") const override
Writes the activation function into a torch::serialize::OutputArchive object.
Definition activation.hpp:2848
torch::Tensor apply(const torch::Tensor &input) const override
Applies the activation function to the given input.
Definition activation.hpp:2832
torch::serialize::InputArchive & read(torch::serialize::InputArchive &archive, const std::string &key="tanh") override
Reads the activation function from a torch::serialize::InputArchive object.
Definition activation.hpp:2862
Tanhshrink activation function.
Definition activation.hpp:2879
torch::Tensor apply(const torch::Tensor &input) const override
Applies the activation function to the given input.
Definition activation.hpp:2884
torch::serialize::InputArchive & read(torch::serialize::InputArchive &archive, const std::string &key="tanhshrink") override
Reads the activation function from a torch::serialize::InputArchive object.
Definition activation.hpp:2914
torch::serialize::OutputArchive & write(torch::serialize::OutputArchive &archive, const std::string &key="tanhshrink") const override
Writes the activation function into a torch::serialize::OutputArchive object.
Definition activation.hpp:2900
void pretty_print(std::ostream &os) const noexcept override
Returns a string representation of the activation function.
Definition activation.hpp:2890
Threshold activation function.
Definition activation.hpp:2935
const torch::nn::functional::ThresholdFuncOptions & options() const
Returns constant reference to options.
Definition activation.hpp:2961
void pretty_print(std::ostream &os) const noexcept override
Returns a string representation of the activation function.
Definition activation.hpp:2973
Threshold(const torch::nn::functional::ThresholdFuncOptions &options)
Provides the Threshold operation.
Definition activation.hpp:2939
~Threshold() override=default
Threshold(double threshold, double value, bool inplace=false)
Provides the Threshold operation.
Definition activation.hpp:2946
torch::nn::functional::ThresholdFuncOptions & options()
Returns non-constant reference to options.
Definition activation.hpp:2967
torch::Tensor apply(const torch::Tensor &input) const override
Applies the activation function to the given input.
Definition activation.hpp:2955
torch::serialize::InputArchive & read(torch::serialize::InputArchive &archive, const std::string &key="threshold") override
Reads the activation function from a torch::serialize::InputArchive object.
Definition activation.hpp:3004
torch::serialize::OutputArchive & write(torch::serialize::OutputArchive &archive, const std::string &key="threshold") const override
Writes the activation function into a torch::serialize::OutputArchive object.
Definition activation.hpp:2986
torch::nn::functional::ThresholdFuncOptions options_
Definition activation.hpp:3023
Full qualified name descriptor.
Definition fqn.hpp:22
virtual const std::string & name() const noexcept
Returns the full qualified name of the object.
Definition fqn.hpp:28
Core components.
Full qualified name utility functions.
Definition core.hpp:73
bool is_verbose(std::ostream &os)
Tests whether verbose output is enabled on a stream.
Definition core.hpp:871
std::ostream & operator<<(std::ostream &os, const MemoryDebugger< id > &obj)
Prints a memory debugger object.
Definition memory.hpp:145
struct iganet::@0 Log
Logger.
@ none
Definition boundary.hpp:38
activation
Enumerator for nonlinear activation functions.
Definition activation.hpp:26
short int short_t
Signed short integer type used by IgANet's compact enumerations.
Definition core.hpp:76
STL namespace.
Definition optimizer.hpp:61