STK++ 0.9.13
STK_DotProduct.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------*/
2/* Copyright (C) 2004-2016 Serge Iovleff, Université Lille 1, Inria
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this program; if not, write to the
16 Free Software Foundation, Inc.,
17 59 Temple Place,
18 Suite 330,
19 Boston, MA 02111-1307
20 USA
21
22 Contact : S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
23*/
24
25/*
26 * Project: stkpp::Arrays
27 * created on: 20 oct. 2012
28 * Author: iovleff, S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
29 **/
30
35#ifndef STK_DOTPRODUCT_H
36#define STK_DOTPRODUCT_H
37
38namespace STK
39{
40// forward declarations
41template<typename Lhs, typename Rhs> class DotProduct;
42template<typename Type, int SizeRows_, int SizeCols_, bool Orient_> class CAllocator;
43
44namespace hidden
45{
46
50template< typename Lhs, typename Rhs>
51struct Traits< DotProduct < Lhs, Rhs> >
52{
53 enum
54 {
55 structure_ = Arrays::number_,
56 orient_ = Arrays::by_col_,
57 sizeRows_ = 1,
58 sizeCols_ = 1,
59 storage_ = Arrays::dense_
60 };
62 typedef typename RemoveConst<Type>::Type const& TypeConst;
63 typedef CAllocator<Type, sizeRows_, sizeCols_, (bool)orient_> Allocator;
64};
65
66} // end namespace hidden
67
68
83template<typename Lhs, typename Rhs>
84class DotProduct: public ExprBase< DotProduct<Lhs, Rhs> >
85 , public TRef<1>
86{
87 public:
91
92 enum
93 {
99 };
104
105 inline DotProduct( const Lhs& lhs, const Rhs& rhs)
106 : lhs_(lhs), rhs_(rhs)
107 , result_()
108 {
111#ifdef STK_BOUNDS_CHECK
112 if (lhs.range() != rhs.range())
114#endif
115 result_.shift(lhs.beginRows(), rhs.beginCols());
116 result_.elt() = lhs.dot(rhs);
117 }
119 inline RowRange const& rowsImpl() const { return result_.rows();}
121 inline ColRange const& colsImpl() const { return result_.cols();}
122
124 inline TypeConst elt2Impl(int i, int j) const
125 {
126#ifdef STK_BOUNDS_CHECK
127 if ( (result_.beginRows() != i) || (result_.beginCols() !=j) )
129#endif
130 return result_.elt(i, j);
131 }
133 inline TypeConst elt0Impl() const { return result_.elt();}
134
136 inline Lhs const& lhs() const { return lhs_; }
138 inline Rhs const& rhs() const { return rhs_; }
140 inline Allocator const& result() const { return result_; }
141
142 protected:
143 Lhs const& lhs_;
144 Rhs const& rhs_;
145
146 private:
148};
149
150} // namespace STK
151
152#endif /* STK_DOTPRODUCT_H */
#define STKRUNTIME_ERROR_NO_ARG(Where, Error)
Definition STK_Macros.h:138
#define STKRUNTIME_ERROR_2ARG(Where, Arg1, Arg2, Error)
Definition STK_Macros.h:120
#define STK_STATIC_ASSERT_POINT_ONLY(EXPR)
#define STK_STATIC_ASSERT_VECTOR_ONLY(EXPR)
Allocator for dense Array classes.
Generic expression where a DotProduct is applied to two expressions.
hidden::Traits< DotProduct >::TypeConst TypeConst
DotProduct(const Lhs &lhs, const Rhs &rhs)
Rhs const & rhs() const
hidden::Traits< DotProduct >::Type Type
Allocator const & result() const
TRange< sizeCols_ > ColRange
Type of the Range for the columns.
RowRange const & rowsImpl() const
TRange< sizeRows_ > RowRange
Type of the Range for the rows.
ColRange const & colsImpl() const
Lhs const & lhs() const
TypeConst elt0Impl() const
access to the element
hidden::Traits< DotProduct >::Allocator Allocator
TypeConst elt2Impl(int i, int j) const
access to the element
base class for template evaluation expressions and visitors.
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
@ dense_
dense matrix/vector/array/expression
@ number_
(1,1) matrix/vector/array/expression (like a number)
@ by_col_
storage by column
The namespace STK is the main domain space of the Statistical ToolKit project.
Base class for all referencing containers.
If<(sizeof(Type1)>sizeof(Type2)), Type1, Type2 >::Result result_type
Promote< typenameLhs::Type, typenameRhs::Type >::result_type Type
RemoveConst< Type >::Type const & TypeConst