tomoto 0.6.1 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/ext/tomoto/ct.cpp +1 -1
  4. data/ext/tomoto/dmr.cpp +1 -1
  5. data/ext/tomoto/dt.cpp +1 -1
  6. data/ext/tomoto/extconf.rb +4 -8
  7. data/ext/tomoto/gdmr.cpp +1 -1
  8. data/ext/tomoto/hdp.cpp +1 -1
  9. data/ext/tomoto/hlda.cpp +1 -1
  10. data/ext/tomoto/hpa.cpp +1 -1
  11. data/ext/tomoto/lda.cpp +29 -3
  12. data/ext/tomoto/llda.cpp +1 -1
  13. data/ext/tomoto/mglda.cpp +1 -1
  14. data/ext/tomoto/pa.cpp +1 -1
  15. data/ext/tomoto/plda.cpp +1 -1
  16. data/ext/tomoto/slda.cpp +1 -1
  17. data/lib/tomoto/lda.rb +1 -0
  18. data/lib/tomoto/version.rb +1 -1
  19. data/vendor/EigenRand/EigenRand/Core.h +6 -4
  20. data/vendor/EigenRand/EigenRand/CwiseHeteroBinaryOp.h +265 -0
  21. data/vendor/EigenRand/EigenRand/Dists/Basic.h +345 -12
  22. data/vendor/EigenRand/EigenRand/Dists/Discrete.h +381 -7
  23. data/vendor/EigenRand/EigenRand/Dists/GammaPoisson.h +4 -4
  24. data/vendor/EigenRand/EigenRand/Dists/NormalExp.h +576 -4
  25. data/vendor/EigenRand/EigenRand/EigenRand +4 -4
  26. data/vendor/EigenRand/EigenRand/Macro.h +3 -3
  27. data/vendor/EigenRand/EigenRand/MorePacketMath.h +31 -30
  28. data/vendor/EigenRand/EigenRand/MvDists/Multinomial.h +41 -29
  29. data/vendor/EigenRand/EigenRand/MvDists/MvNormal.h +19 -7
  30. data/vendor/EigenRand/EigenRand/PacketFilter.h +8 -5
  31. data/vendor/EigenRand/EigenRand/PacketRandomEngine.h +3 -3
  32. data/vendor/EigenRand/EigenRand/RandUtils.h +180 -5
  33. data/vendor/EigenRand/EigenRand/arch/AVX/MorePacketMath.h +42 -3
  34. data/vendor/EigenRand/EigenRand/arch/AVX/PacketFilter.h +3 -3
  35. data/vendor/EigenRand/EigenRand/arch/AVX/RandUtils.h +3 -3
  36. data/vendor/EigenRand/EigenRand/arch/AVX512/MorePacketMath.h +312 -0
  37. data/vendor/EigenRand/EigenRand/arch/AVX512/PacketFilter.h +79 -0
  38. data/vendor/EigenRand/EigenRand/arch/AVX512/RandUtils.h +147 -0
  39. data/vendor/EigenRand/EigenRand/arch/NEON/MorePacketMath.h +118 -3
  40. data/vendor/EigenRand/EigenRand/arch/NEON/PacketFilter.h +3 -3
  41. data/vendor/EigenRand/EigenRand/arch/NEON/RandUtils.h +21 -3
  42. data/vendor/EigenRand/EigenRand/arch/SSE/MorePacketMath.h +32 -4
  43. data/vendor/EigenRand/EigenRand/arch/SSE/PacketFilter.h +3 -3
  44. data/vendor/EigenRand/EigenRand/arch/SSE/RandUtils.h +3 -3
  45. data/vendor/EigenRand/EigenRand/doc.h +108 -157
  46. data/vendor/EigenRand/README.md +60 -272
  47. data/vendor/tomotopy/README.kr.rst +27 -5
  48. data/vendor/tomotopy/README.rst +27 -5
  49. data/vendor/tomotopy/README_pypi.rst +583 -0
  50. data/vendor/tomotopy/licenses_bundled/EigenRand +21 -0
  51. data/vendor/tomotopy/src/TopicModel/CT.h +1 -1
  52. data/vendor/tomotopy/src/TopicModel/CTModel.cpp +1 -1
  53. data/vendor/tomotopy/src/TopicModel/DMR.h +1 -1
  54. data/vendor/tomotopy/src/TopicModel/DMRModel.cpp +1 -1
  55. data/vendor/tomotopy/src/TopicModel/DT.h +1 -1
  56. data/vendor/tomotopy/src/TopicModel/DTModel.cpp +1 -1
  57. data/vendor/tomotopy/src/TopicModel/GDMR.h +1 -1
  58. data/vendor/tomotopy/src/TopicModel/GDMRModel.cpp +1 -1
  59. data/vendor/tomotopy/src/TopicModel/HDP.h +1 -1
  60. data/vendor/tomotopy/src/TopicModel/HDPModel.cpp +1 -1
  61. data/vendor/tomotopy/src/TopicModel/HLDA.h +1 -1
  62. data/vendor/tomotopy/src/TopicModel/HLDAModel.cpp +1 -1
  63. data/vendor/tomotopy/src/TopicModel/HPA.h +1 -1
  64. data/vendor/tomotopy/src/TopicModel/HPAModel.cpp +1 -1
  65. data/vendor/tomotopy/src/TopicModel/LDA.h +1 -1
  66. data/vendor/tomotopy/src/TopicModel/LDAModel.cpp +1 -1
  67. data/vendor/tomotopy/src/TopicModel/LDAModel.hpp +6 -6
  68. data/vendor/tomotopy/src/TopicModel/LLDA.h +1 -1
  69. data/vendor/tomotopy/src/TopicModel/LLDAModel.cpp +1 -1
  70. data/vendor/tomotopy/src/TopicModel/MGLDA.h +1 -1
  71. data/vendor/tomotopy/src/TopicModel/MGLDAModel.cpp +1 -1
  72. data/vendor/tomotopy/src/TopicModel/PA.h +1 -1
  73. data/vendor/tomotopy/src/TopicModel/PAModel.cpp +1 -1
  74. data/vendor/tomotopy/src/TopicModel/PLDA.h +1 -1
  75. data/vendor/tomotopy/src/TopicModel/PLDAModel.cpp +1 -1
  76. data/vendor/tomotopy/src/TopicModel/PT.h +1 -1
  77. data/vendor/tomotopy/src/TopicModel/PTModel.cpp +1 -1
  78. data/vendor/tomotopy/src/TopicModel/SLDA.h +1 -1
  79. data/vendor/tomotopy/src/TopicModel/SLDAModel.cpp +1 -1
  80. data/vendor/tomotopy/src/TopicModel/TopicModel.hpp +6 -6
  81. data/vendor/tomotopy/src/Utils/EigenAddonOps.hpp +41 -0
  82. data/vendor/tomotopy/src/Utils/ThreadPool.hpp +6 -6
  83. data/vendor/tomotopy/src/Utils/Utils.hpp +3 -3
  84. data/vendor/tomotopy/src/Utils/avx512_gamma.h +46 -0
  85. data/vendor/tomotopy/src/Utils/avx512_mathfun.h +99 -0
  86. metadata +9 -8
  87. data/vendor/variant/LICENSE +0 -25
  88. data/vendor/variant/LICENSE_1_0.txt +0 -23
  89. data/vendor/variant/README.md +0 -102
  90. data/vendor/variant/include/mapbox/optional.hpp +0 -74
  91. data/vendor/variant/include/mapbox/recursive_wrapper.hpp +0 -122
  92. data/vendor/variant/include/mapbox/variant.hpp +0 -974
  93. data/vendor/variant/include/mapbox/variant_io.hpp +0 -45
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f261799f417a11ff64ca5ece40201469b3ca4d59e1ae7967b744e342476df61e
4
- data.tar.gz: 698cbb9b4a51c9bbd4d5b1a2a5bb641d2e0328e32009bb4dc2835eaff164a17d
3
+ metadata.gz: 7b9dd5706eb7ad70f92f52d3a321d6a9f96fb1b06243170657a722c3e1b99a2d
4
+ data.tar.gz: 50b3a62afbf79d23cbf2b11956e26fcfb922e26b229a0f82eaf1946d4e86a65f
5
5
  SHA512:
6
- metadata.gz: fe5e6840fdd9c056747529fd590319390e90c06e273c6f843dae2cd862f2cf17891f3681c5e5fb7442ee7f16c2ae82cc96b7f6d6c8df96269e6993dc6204c9ef
7
- data.tar.gz: 57681426bba4aa89a3482955d3b4f40a1dcc2a673d4f5700c12805c1f90d9710923489927dddb33b54f0b14f864ecf14de24768f28d08166c0e0ccdce81e2ffc
6
+ metadata.gz: ee26d6f9789a461dbcdd2995ab8db74c42cda56abd127af1567b100fbcb14b770942f0f03a5b5d2782475abdaae69f9dabb2aaf31d81ce4ec267870cf78b39e7
7
+ data.tar.gz: 181ce20d28f143a03964818806caa49f596eb22423302a24b2d0c5f4a53c07f1369aed642ad920b676c12aa4fea3d21599185d4ef66019cbacd36a745728e5f2
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.6.2 (2026-02-21)
2
+
3
+ - Updated tomoto to 0.14.0
4
+ - Fixed memory leak with `make_doc` method
5
+
1
6
  ## 0.6.1 (2026-01-01)
2
7
 
3
8
  - Added support for Ruby 4.0
data/ext/tomoto/ct.cpp CHANGED
@@ -16,7 +16,7 @@ void init_ct(Rice::Module& m) {
16
16
  if (seed >= 0) {
17
17
  args.seed = seed;
18
18
  }
19
- return tomoto::ICTModel::create((tomoto::TermWeight)tw, args);
19
+ return tomoto::ICTModel::create((tomoto::TermWeight)tw, args).release();
20
20
  }, Rice::Return().takeOwnership())
21
21
  .define_method(
22
22
  "_correlations",
data/ext/tomoto/dmr.cpp CHANGED
@@ -22,7 +22,7 @@ void init_dmr(Rice::Module& m) {
22
22
  if (seed >= 0) {
23
23
  args.seed = seed;
24
24
  }
25
- return tomoto::IDMRModel::create((tomoto::TermWeight)tw, args);
25
+ return tomoto::IDMRModel::create((tomoto::TermWeight)tw, args).release();
26
26
  }, Rice::Return().takeOwnership())
27
27
  .define_method(
28
28
  "_add_doc",
data/ext/tomoto/dt.cpp CHANGED
@@ -27,7 +27,7 @@ void init_dt(Rice::Module& m) {
27
27
  if (seed >= 0) {
28
28
  args.seed = seed;
29
29
  }
30
- return tomoto::IDTModel::create((tomoto::TermWeight)tw, args);
30
+ return tomoto::IDTModel::create((tomoto::TermWeight)tw, args).release();
31
31
  }, Rice::Return().takeOwnership())
32
32
  .define_method(
33
33
  "_add_doc",
@@ -19,25 +19,21 @@ end
19
19
  apple_clang = RbConfig::CONFIG["CC_VERSION_MESSAGE"] =~ /apple clang/i
20
20
 
21
21
  if apple_clang
22
- # silence rice warnings
23
- $CXXFLAGS += " -Wno-deprecated-declarations"
22
+ # silence tomoto warnings
23
+ $CXXFLAGS += " -Wno-switch -Wno-unqualified-std-cast-call -Wno-inconsistent-missing-override"
24
24
  else
25
25
  # silence eigen warnings
26
- $CXXFLAGS += " -Wno-ignored-attributes -Wno-deprecated-copy"
26
+ $CXXFLAGS += " -Wno-ignored-attributes"
27
27
  end
28
28
 
29
- # silence tomoto warnings
30
- $CXXFLAGS += " -Wno-unused-variable -Wno-switch -Wno-unqualified-std-cast-call"
31
-
32
29
  ext = File.expand_path(".", __dir__)
33
30
  tomoto = File.expand_path("../../vendor/tomotopy/src/TopicModel", __dir__)
34
31
  tomoto_utils = File.expand_path("../../vendor/tomotopy/src/Utils", __dir__)
35
32
  eigen = File.expand_path("../../vendor/eigen", __dir__)
36
33
  eigen_rand = File.expand_path("../../vendor/EigenRand", __dir__)
37
- variant = File.expand_path("../../vendor/variant/include", __dir__)
38
34
 
39
35
  $srcs = Dir["{#{ext},#{tomoto},#{tomoto_utils}}/*.cpp"]
40
- $INCFLAGS += " -I#{tomoto} -I#{eigen} -I#{eigen_rand} -I#{variant}"
36
+ $INCFLAGS += " -I#{tomoto} -I#{eigen} -I#{eigen_rand}"
41
37
  $VPATH << tomoto
42
38
  $VPATH << tomoto_utils
43
39
 
data/ext/tomoto/gdmr.cpp CHANGED
@@ -24,7 +24,7 @@ void init_gdmr(Rice::Module& m) {
24
24
  if (seed >= 0) {
25
25
  args.seed = seed;
26
26
  }
27
- return tomoto::IGDMRModel::create((tomoto::TermWeight)tw, args);
27
+ return tomoto::IGDMRModel::create((tomoto::TermWeight)tw, args).release();
28
28
  }, Rice::Return().takeOwnership())
29
29
  .define_method(
30
30
  "_add_doc",
data/ext/tomoto/hdp.cpp CHANGED
@@ -17,7 +17,7 @@ void init_hdp(Rice::Module& m) {
17
17
  if (seed >= 0) {
18
18
  args.seed = seed;
19
19
  }
20
- return tomoto::IHDPModel::create((tomoto::TermWeight)tw, args);
20
+ return tomoto::IHDPModel::create((tomoto::TermWeight)tw, args).release();
21
21
  }, Rice::Return().takeOwnership())
22
22
  .define_method(
23
23
  "alpha",
data/ext/tomoto/hlda.cpp CHANGED
@@ -17,7 +17,7 @@ void init_hlda(Rice::Module& m) {
17
17
  if (seed >= 0) {
18
18
  args.seed = seed;
19
19
  }
20
- return tomoto::IHLDAModel::create((tomoto::TermWeight)tw, args);
20
+ return tomoto::IHLDAModel::create((tomoto::TermWeight)tw, args).release();
21
21
  }, Rice::Return().takeOwnership())
22
22
  .define_method(
23
23
  "alpha",
data/ext/tomoto/hpa.cpp CHANGED
@@ -17,7 +17,7 @@ void init_hpa(Rice::Module& m) {
17
17
  if (seed >= 0) {
18
18
  args.seed = seed;
19
19
  }
20
- return tomoto::IHPAModel::create((tomoto::TermWeight)tw, false, args);
20
+ return tomoto::IHPAModel::create((tomoto::TermWeight)tw, false, args).release();
21
21
  }, Rice::Return().takeOwnership())
22
22
  .define_method(
23
23
  "alpha",
data/ext/tomoto/lda.cpp CHANGED
@@ -12,10 +12,36 @@
12
12
 
13
13
  class DocumentObject {
14
14
  public:
15
- DocumentObject(const tomoto::DocumentBase* _doc, const tomoto::ITopicModel* _tm) : doc{ _doc }, tm{ _tm } {}
15
+ DocumentObject(const tomoto::DocumentBase* _doc, const tomoto::ITopicModel* _tm, bool _owner = false) : doc{ _doc }, tm{ _tm }, owner{ _owner } {}
16
+
17
+ ~DocumentObject() {
18
+ if (owner && doc) {
19
+ delete doc;
20
+ doc = NULL;
21
+ }
22
+ }
23
+
24
+ // prevent copy
25
+ DocumentObject(const DocumentObject&) = delete;
26
+ DocumentObject& operator=(const DocumentObject&) = delete;
27
+
28
+ DocumentObject(DocumentObject&& other) noexcept {
29
+ *this = std::move(other);
30
+ }
31
+
32
+ DocumentObject& operator=(DocumentObject&& other) noexcept {
33
+ if (this != &other) {
34
+ doc = other.doc;
35
+ tm = other.tm;
36
+ owner = other.owner;
37
+ other.owner = false;
38
+ }
39
+ return *this;
40
+ }
16
41
 
17
42
  const tomoto::DocumentBase* doc;
18
43
  const tomoto::ITopicModel* tm;
44
+ bool owner;
19
45
  };
20
46
 
21
47
  void init_lda(Rice::Module& m) {
@@ -42,7 +68,7 @@ void init_lda(Rice::Module& m) {
42
68
  if (seed >= 0) {
43
69
  args.seed = seed;
44
70
  }
45
- return tomoto::ILDAModel::create((tomoto::TermWeight)tw, args);
71
+ return tomoto::ILDAModel::create((tomoto::TermWeight)tw, args).release();
46
72
  }, Rice::Return().takeOwnership())
47
73
  .define_method(
48
74
  "_add_doc",
@@ -52,7 +78,7 @@ void init_lda(Rice::Module& m) {
52
78
  .define_method(
53
79
  "_make_doc",
54
80
  [](tomoto::ILDAModel& self, std::vector<std::string> words) {
55
- return DocumentObject(self.makeDoc(buildDoc(words)).release(), &self);
81
+ return DocumentObject(self.makeDoc(buildDoc(words)).release(), &self, true);
56
82
  })
57
83
  .define_method(
58
84
  "_infer",
data/ext/tomoto/llda.cpp CHANGED
@@ -20,7 +20,7 @@ void init_llda(Rice::Module& m) {
20
20
  if (seed >= 0) {
21
21
  args.seed = seed;
22
22
  }
23
- return tomoto::ILLDAModel::create((tomoto::TermWeight)tw, args);
23
+ return tomoto::ILLDAModel::create((tomoto::TermWeight)tw, args).release();
24
24
  }, Rice::Return().takeOwnership())
25
25
  .define_method(
26
26
  "_add_doc",
data/ext/tomoto/mglda.cpp CHANGED
@@ -23,7 +23,7 @@ void init_mglda(Rice::Module& m) {
23
23
  args.alphaML = alpha_ml;
24
24
  args.eta = eta_g;
25
25
  // TODO more args
26
- return tomoto::IMGLDAModel::create((tomoto::TermWeight)tw, args);
26
+ return tomoto::IMGLDAModel::create((tomoto::TermWeight)tw, args).release();
27
27
  }, Rice::Return().takeOwnership())
28
28
  .define_method(
29
29
  "_add_doc",
data/ext/tomoto/pa.cpp CHANGED
@@ -17,7 +17,7 @@ void init_pa(Rice::Module& m) {
17
17
  if (seed >= 0) {
18
18
  args.seed = seed;
19
19
  }
20
- return tomoto::IPAModel::create((tomoto::TermWeight)tw, args);
20
+ return tomoto::IPAModel::create((tomoto::TermWeight)tw, args).release();
21
21
  }, Rice::Return().takeOwnership())
22
22
  .define_method(
23
23
  "k1",
data/ext/tomoto/plda.cpp CHANGED
@@ -20,7 +20,7 @@ void init_plda(Rice::Module& m) {
20
20
  if (seed >= 0) {
21
21
  args.seed = seed;
22
22
  }
23
- return tomoto::IPLDAModel::create((tomoto::TermWeight)tw, args);
23
+ return tomoto::IPLDAModel::create((tomoto::TermWeight)tw, args).release();
24
24
  }, Rice::Return().takeOwnership())
25
25
  .define_method(
26
26
  "_add_doc",
data/ext/tomoto/slda.cpp CHANGED
@@ -29,7 +29,7 @@ void init_slda(Rice::Module& m) {
29
29
  if (seed >= 0) {
30
30
  args.seed = seed;
31
31
  }
32
- return tomoto::ISLDAModel::create((tomoto::TermWeight)tw, args);
32
+ return tomoto::ISLDAModel::create((tomoto::TermWeight)tw, args).release();
33
33
  }, Rice::Return().takeOwnership())
34
34
  .define_method(
35
35
  "_add_doc",
data/lib/tomoto/lda.rb CHANGED
@@ -11,6 +11,7 @@ module Tomoto
11
11
  def self.load(filename)
12
12
  model = new
13
13
  model._load(filename)
14
+ model.instance_variable_set(:@prepared, true)
14
15
  model
15
16
  end
16
17
 
@@ -1,3 +1,3 @@
1
1
  module Tomoto
2
- VERSION = "0.6.1"
2
+ VERSION = "0.6.2"
3
3
  end
@@ -2,10 +2,10 @@
2
2
  * @file Core.h
3
3
  * @author bab2min (bab2min@gmail.com)
4
4
  * @brief
5
- * @version 0.4.1
6
- * @date 2022-08-13
7
- *
8
- * @copyright Copyright (c) 2020-2021
5
+ * @version 0.5.1
6
+ * @date 2024-09-08
7
+ *
8
+ * @copyright Copyright (c) 2020-2024
9
9
  *
10
10
  */
11
11
 
@@ -15,6 +15,8 @@
15
15
 
16
16
  #include "RandUtils.h"
17
17
 
18
+ #include "CwiseHeteroBinaryOp.h"
19
+
18
20
  #include "Dists/Basic.h"
19
21
  #include "Dists/Discrete.h"
20
22
  #include "Dists/NormalExp.h"
@@ -0,0 +1,265 @@
1
+ // This file is part of Eigen, a lightweight C++ template library
2
+ // for linear algebra.
3
+ //
4
+ // Copyright (C) 2008-2014 Gael Guennebaud <gael.guennebaud@inria.fr>
5
+ // Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
6
+ //
7
+ // This Source Code Form is subject to the terms of the Mozilla
8
+ // Public License v. 2.0. If a copy of the MPL was not distributed
9
+ // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10
+
11
+ #ifndef EIGEN_CWISE_HETERO_BINARY_OP_H
12
+ #define EIGEN_CWISE_HETERO_BINARY_OP_H
13
+
14
+ namespace Eigen {
15
+
16
+ template<typename BinaryOp, typename LhsType, typename RhsType>
17
+ class CwiseHeteroBinaryOp;
18
+
19
+ namespace internal {
20
+ template<typename BinaryOp, typename Lhs, typename Rhs>
21
+ struct traits<CwiseHeteroBinaryOp<BinaryOp, Lhs, Rhs> >
22
+ {
23
+ // we must not inherit from traits<Lhs> since it has
24
+ // the potential to cause problems with MSVC
25
+ typedef typename remove_all<Lhs>::type Ancestor;
26
+ typedef typename traits<Ancestor>::XprKind XprKind;
27
+ enum {
28
+ RowsAtCompileTime = traits<Ancestor>::RowsAtCompileTime,
29
+ ColsAtCompileTime = traits<Ancestor>::ColsAtCompileTime,
30
+ MaxRowsAtCompileTime = traits<Ancestor>::MaxRowsAtCompileTime,
31
+ MaxColsAtCompileTime = traits<Ancestor>::MaxColsAtCompileTime
32
+ };
33
+
34
+ // even though we require Lhs and Rhs to have the same scalar type (see CwiseHeteroBinaryOp constructor),
35
+ // we still want to handle the case when the result type is different.
36
+ typedef typename result_of<
37
+ BinaryOp(
38
+ const typename Lhs::Scalar&,
39
+ const typename Rhs::Scalar&
40
+ )
41
+ >::type Scalar;
42
+ typedef typename cwise_promote_storage_type<typename traits<Lhs>::StorageKind,
43
+ typename traits<Rhs>::StorageKind,
44
+ BinaryOp>::ret StorageKind;
45
+ typedef typename promote_index_type<typename traits<Lhs>::StorageIndex,
46
+ typename traits<Rhs>::StorageIndex>::type StorageIndex;
47
+ typedef typename Lhs::Nested LhsNested;
48
+ typedef typename Rhs::Nested RhsNested;
49
+ typedef typename remove_reference<LhsNested>::type _LhsNested;
50
+ typedef typename remove_reference<RhsNested>::type _RhsNested;
51
+ enum {
52
+ Flags = cwise_promote_storage_order<typename traits<Lhs>::StorageKind, typename traits<Rhs>::StorageKind, _LhsNested::Flags& RowMajorBit, _RhsNested::Flags& RowMajorBit>::value
53
+ };
54
+ };
55
+ } // end namespace internal
56
+
57
+ template<typename BinaryOp, typename Lhs, typename Rhs, typename StorageKind>
58
+ class CwiseHeteroBinaryOpImpl;
59
+
60
+ /** \class CwiseHeteroBinaryOp
61
+ * \ingroup Core_Module
62
+ *
63
+ * \brief Generic expression where a coefficient-wise binary operator is applied to two expressions
64
+ *
65
+ * \tparam BinaryOp template functor implementing the operator
66
+ * \tparam LhsType the type of the left-hand side
67
+ * \tparam RhsType the type of the right-hand side
68
+ *
69
+ * This class represents an expression where a coefficient-wise binary operator is applied to two expressions.
70
+ * It is the return type of binary operators, by which we mean only those binary operators where
71
+ * both the left-hand side and the right-hand side are Eigen expressions.
72
+ * For example, the return type of matrix1+matrix2 is a CwiseHeteroBinaryOp.
73
+ *
74
+ * Most of the time, this is the only way that it is used, so you typically don't have to name
75
+ * CwiseHeteroBinaryOp types explicitly.
76
+ *
77
+ * \sa MatrixBase::binaryExpr(const MatrixBase<OtherDerived> &,const CustomBinaryOp &) const, class CwiseUnaryOp, class CwiseNullaryOp
78
+ */
79
+ template<typename BinaryOp, typename LhsType, typename RhsType>
80
+ class CwiseHeteroBinaryOp :
81
+ public CwiseHeteroBinaryOpImpl<
82
+ BinaryOp, LhsType, RhsType,
83
+ typename internal::cwise_promote_storage_type<typename internal::traits<LhsType>::StorageKind,
84
+ typename internal::traits<RhsType>::StorageKind,
85
+ BinaryOp>::ret>,
86
+ internal::no_assignment_operator
87
+ {
88
+ public:
89
+
90
+ typedef typename internal::remove_all<BinaryOp>::type Functor;
91
+ typedef typename internal::remove_all<LhsType>::type Lhs;
92
+ typedef typename internal::remove_all<RhsType>::type Rhs;
93
+
94
+ typedef typename CwiseHeteroBinaryOpImpl<
95
+ BinaryOp, LhsType, RhsType,
96
+ typename internal::cwise_promote_storage_type<typename internal::traits<LhsType>::StorageKind,
97
+ typename internal::traits<Rhs>::StorageKind,
98
+ BinaryOp>::ret>::Base Base;
99
+ EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseHeteroBinaryOp)
100
+
101
+ typedef typename internal::ref_selector<LhsType>::type LhsNested;
102
+ typedef typename internal::ref_selector<RhsType>::type RhsNested;
103
+ typedef typename internal::remove_reference<LhsNested>::type _LhsNested;
104
+ typedef typename internal::remove_reference<RhsNested>::type _RhsNested;
105
+
106
+ #if EIGEN_COMP_MSVC && EIGEN_HAS_CXX11
107
+ //Required for Visual Studio or the Copy constructor will probably not get inlined!
108
+ EIGEN_STRONG_INLINE
109
+ CwiseHeteroBinaryOp(const CwiseHeteroBinaryOp<BinaryOp, LhsType, RhsType>&) = default;
110
+ #endif
111
+
112
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
113
+ CwiseHeteroBinaryOp(const Lhs& aLhs, const Rhs& aRhs, const BinaryOp& func = BinaryOp())
114
+ : m_lhs(aLhs), m_rhs(aRhs), m_functor(func)
115
+ {
116
+ // require the sizes to match
117
+ EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(Lhs, Rhs)
118
+ eigen_assert(aLhs.rows() == aRhs.rows() && aLhs.cols() == aRhs.cols());
119
+ }
120
+
121
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr
122
+ Index rows() const EIGEN_NOEXCEPT {
123
+ // return the fixed size type if available to enable compile time optimizations
124
+ return internal::traits<typename internal::remove_all<LhsNested>::type>::RowsAtCompileTime == Dynamic ? m_rhs.rows() : m_lhs.rows();
125
+ }
126
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr
127
+ Index cols() const EIGEN_NOEXCEPT {
128
+ // return the fixed size type if available to enable compile time optimizations
129
+ return internal::traits<typename internal::remove_all<LhsNested>::type>::ColsAtCompileTime == Dynamic ? m_rhs.cols() : m_lhs.cols();
130
+ }
131
+
132
+ /** \returns the left hand side nested expression */
133
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
134
+ const _LhsNested& lhs() const { return m_lhs; }
135
+ /** \returns the right hand side nested expression */
136
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
137
+ const _RhsNested& rhs() const { return m_rhs; }
138
+ /** \returns the functor representing the binary operation */
139
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
140
+ const BinaryOp& functor() const { return m_functor; }
141
+
142
+ protected:
143
+ LhsNested m_lhs;
144
+ RhsNested m_rhs;
145
+ const BinaryOp m_functor;
146
+ };
147
+
148
+ // Generic API dispatcher
149
+ template<typename BinaryOp, typename Lhs, typename Rhs, typename StorageKind>
150
+ class CwiseHeteroBinaryOpImpl
151
+ : public internal::generic_xpr_base<CwiseHeteroBinaryOp<BinaryOp, Lhs, Rhs> >::type
152
+ {
153
+ public:
154
+ typedef typename internal::generic_xpr_base<CwiseHeteroBinaryOp<BinaryOp, Lhs, Rhs> >::type Base;
155
+ };
156
+
157
+
158
+ namespace internal {
159
+ // -------------------- CwiseHeteroBinaryOp --------------------
160
+
161
+ // this is a binary expression
162
+ template<typename BinaryOp, typename Lhs, typename Rhs>
163
+ struct evaluator<CwiseHeteroBinaryOp<BinaryOp, Lhs, Rhs> >
164
+ : public binary_evaluator<CwiseHeteroBinaryOp<BinaryOp, Lhs, Rhs> >
165
+ {
166
+ typedef CwiseHeteroBinaryOp<BinaryOp, Lhs, Rhs> XprType;
167
+ typedef binary_evaluator<CwiseHeteroBinaryOp<BinaryOp, Lhs, Rhs> > Base;
168
+
169
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
170
+ explicit evaluator(const XprType& xpr) : Base(xpr) {}
171
+ };
172
+
173
+ template<typename BinaryOp, typename Lhs, typename Rhs>
174
+ struct binary_evaluator<CwiseHeteroBinaryOp<BinaryOp, Lhs, Rhs>, IndexBased, IndexBased>
175
+ : evaluator_base<CwiseHeteroBinaryOp<BinaryOp, Lhs, Rhs> >
176
+ {
177
+ typedef CwiseHeteroBinaryOp<BinaryOp, Lhs, Rhs> XprType;
178
+ using LhsScalar = typename Lhs::Scalar;
179
+ using RhsScalar = typename Rhs::Scalar;
180
+
181
+ enum {
182
+ CoeffReadCost = int(evaluator<Lhs>::CoeffReadCost) + int(evaluator<Rhs>::CoeffReadCost) + int(functor_traits<BinaryOp>::Cost),
183
+
184
+ LhsFlags = evaluator<Lhs>::Flags,
185
+ RhsFlags = evaluator<Rhs>::Flags,
186
+ SameType = is_same<typename Lhs::Scalar, typename Rhs::Scalar>::value,
187
+ StorageOrdersAgree = (int(LhsFlags) & RowMajorBit) == (int(RhsFlags) & RowMajorBit),
188
+ Flags0 = (int(LhsFlags) | int(RhsFlags)) & (
189
+ HereditaryBits
190
+ | (int(LhsFlags) & int(RhsFlags) &
191
+ ((StorageOrdersAgree ? LinearAccessBit : 0)
192
+ | (functor_traits<BinaryOp>::PacketAccess && StorageOrdersAgree ? PacketAccessBit : 0)
193
+ )
194
+ )
195
+ ),
196
+ Flags = (Flags0 & ~RowMajorBit) | (LhsFlags & RowMajorBit),
197
+ Alignment = EIGEN_PLAIN_ENUM_MIN(evaluator<Lhs>::Alignment, evaluator<Rhs>::Alignment)
198
+ };
199
+
200
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
201
+ explicit binary_evaluator(const XprType& xpr) : m_d(xpr)
202
+ {
203
+ EIGEN_INTERNAL_CHECK_COST_VALUE(functor_traits<BinaryOp>::Cost);
204
+ EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
205
+ }
206
+
207
+ typedef typename XprType::CoeffReturnType CoeffReturnType;
208
+
209
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
210
+ CoeffReturnType coeff(Index row, Index col) const
211
+ {
212
+ return m_d.func()(m_d.lhsImpl.coeff(row, col), m_d.rhsImpl.coeff(row, col));
213
+ }
214
+
215
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
216
+ CoeffReturnType coeff(Index index) const
217
+ {
218
+ return m_d.func()(m_d.lhsImpl.coeff(index), m_d.rhsImpl.coeff(index));
219
+ }
220
+
221
+ template<int LoadMode, typename PacketType>
222
+ EIGEN_STRONG_INLINE
223
+ PacketType packet(Index row, Index col) const
224
+ {
225
+ using IPacketType = decltype(reinterpret_to_float(std::declval<PacketType>()));
226
+ using FPacketType = decltype(reinterpret_to_float(std::declval<PacketType>()));
227
+ using RhsPacket = typename std::conditional<std::is_same<RhsScalar, float>::value, FPacketType, IPacketType>::type;
228
+
229
+ return m_d.func().packetOp(m_d.lhsImpl.template packet<LoadMode, PacketType>(row, col),
230
+ m_d.rhsImpl.template packet<LoadMode, RhsPacket>(row, col));
231
+ }
232
+
233
+ template<int LoadMode, typename PacketType>
234
+ EIGEN_STRONG_INLINE
235
+ PacketType packet(Index index) const
236
+ {
237
+ using IPacketType = decltype(reinterpret_to_float(std::declval<PacketType>()));
238
+ using FPacketType = decltype(reinterpret_to_float(std::declval<PacketType>()));
239
+ using RhsPacket = typename std::conditional<std::is_same<RhsScalar, float>::value, FPacketType, IPacketType>::type;
240
+
241
+ return m_d.func().packetOp(m_d.lhsImpl.template packet<LoadMode, PacketType>(index),
242
+ m_d.rhsImpl.template packet<LoadMode, RhsPacket>(index));
243
+ }
244
+
245
+ protected:
246
+
247
+ // this helper permits to completely eliminate the functor if it is empty
248
+ struct Data
249
+ {
250
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
251
+ Data(const XprType& xpr) : op(xpr.functor()), lhsImpl(xpr.lhs()), rhsImpl(xpr.rhs()) {}
252
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
253
+ const BinaryOp& func() const { return op; }
254
+ BinaryOp op;
255
+ evaluator<Lhs> lhsImpl;
256
+ evaluator<Rhs> rhsImpl;
257
+ };
258
+
259
+ Data m_d;
260
+ };
261
+ }
262
+
263
+ } // end namespace Eigen
264
+
265
+ #endif // EIGEN_CWISE_HETERO_BINARY_OP_H