STK++ 0.9.13
STK_SArray1D.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: 26 nov. 2007
28 * Author: Serge Iovleff, S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
29 **/
30
35#ifndef STK_SARRAY1D_H
36#define STK_SARRAY1D_H
37
39
40namespace STK
41{
42template<class Type_, int Size_ = UnknownSize, int NzMax_ = UnknownSize > class SArray1D;
43
44namespace hidden
45{
49template<class Type_, int Size_, int NzMax_>
50struct Traits< SArray1D<Type_, Size_, NzMax_> >
51{
55
56 typedef Type_ Type;
57 typedef typename RemoveConst<Type>::Type const& TypeConst;
58
59 enum
60 {
61 structure_ = Arrays::vector_,
62 orient_ = Arrays::by_col_,
63 sizeCols_ = 1,
64 sizeRows_ = Size_,
65 size_ = Size_,
66 nzmax_ = NzMax_,
67 storage_ = Arrays::sparse_
68 };
69
71
74
75 typedef int Index;
76
79
80 typedef std::reverse_iterator<Iterator> ReverseIterator;
81 typedef std::reverse_iterator<ConstIterator> ConstReverseIterator;
82};
83
84} // namespace hidden
85
86}
87
88namespace STK
89{
102template<class Type_, int Size_, int NzMax_ >
103class SArray1D: public IArray1D< SArray1D<Type_, Size_, NzMax_> >
104{
105 public:
107
111
112 enum
113 {
120 };
121
124
126
129
130 using Base::range;
131 using Base::begin;
132 using Base::end;
133 using Base::resize;
134 using Base::allocator;
135
141 SArray1D( Range const& I): Base(I) {}
146 SArray1D( Range const& I, Type const& v): Base(I, v) {}
151 SArray1D( SArray1D const& T, bool ref =false): Base(T, ref) {}
156 template<int OtherSize_, int OtherNzMax_>
158 : Base(T, ref) {}
163 template<int OtherSize_, int OtherNzMax_>
164 SArray1D( SArray1D<Type, OtherSize_, OtherNzMax_> const& T, RowRange const& I, bool ref = true)
165 : Base(T, I, ref) {}
169 SArray1D( Type* q, Range const& I): Base(q, I) {}
176 { return Base::assign(T);}
180 template<class OtherArray>
182 {
183 // check size
184 if (range() != T.range()) { resize(T.range());}
185 for (int i=begin(); i<end(); i++)
186 { allocator().setValue(i, T.elt(i));}
187 return *this;
188 }
193 {
194 allocator().assign(range(), v);
195 return *this;
196 }
197};
198
199} // namespace STK
200
201#endif // STK_SARRAY1D_H
In this file we.
template one dimensional Array.
SArray1D< Type_, Size_, NzMax_ > & assign(IArray1D const &src)
overwrite this with src.
Derived & resize(Range const &I=RowRange())
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
template one dimensional Arrays.
hidden::Traits< SArray1D< Type_, Size_ > >::Type Type
SArray1D(Range const &I, Type const &v)
Misc constructor with beg and end, initialization with a constant.
IArray1D< SArray1D< Type_, Size_, NzMax_ > > Base
TRange< 1 > ColRange
hidden::Traits< SArray1D< Type_, Size_, NzMax_ > >::Col Col
SArray1D(SArray1D< Type, OtherSize_, OtherNzMax_ > const &T, bool ref=false)
Copy constructor.
SArray1D()
Default constructor.
hidden::Traits< SArray1D< Type_, Size_, NzMax_ > >::Row Row
TRange< size_ > RowRange
SArray1D(Type *q, Range const &I)
Wrapper constructor: the container is a reference of a C-Array.
~SArray1D()
destructor: allocated memory is liberated by MemAllocator base class.
hidden::Traits< SArray1D< Type_, Size_, NzMax_ > >::SubVector SubVector
hidden::Traits< SArray1D< Type_, Size_ > >::Allocator Allocator
SArray1D(SArray1D const &T, bool ref=false)
Copy constructor.
SArray1D & operator=(SArray1D const &T)
operator = : overwrite the SArray1D with T.
hidden::Traits< SArray1D< Type_, Size_ > >::TypeConst TypeConst
SArray1D & operator=(ITContainer1D< OtherArray > const &T)
Copy an other type of 1D array in an SArray1D.
SArray1D(SArray1D< Type, OtherSize_, OtherNzMax_ > const &T, RowRange const &I, bool ref=true)
constructor by reference, ref_=1.
SArray1D(Range const &I)
constructor with a specified Range
SArray1D & operator=(Type const &v)
operator= : set the container to a constant value.
Index sub-vector region: Specialization when the size is unknown.
Definition STK_Range.h:265
@ sparse_
sparse matrix/vector/array/expression
@ vector_
column oriented vector/array/expression
@ by_col_
storage by column
The namespace STK is the main domain space of the Statistical ToolKit project.
SArray1D< Type_, UnknownSize, NzMax_ > SubVector
ConstDenseRandomIterator< SArray1D< Type_, Size_, NzMax_ > > ConstIterator
std::reverse_iterator< Iterator > ReverseIterator
DenseRandomIterator< SArray1D< Type_, Size_, NzMax_ > > Iterator
std::reverse_iterator< ConstIterator > ConstReverseIterator