File: disarray_seq.icc

package info (click to toggle)
rheolef 7.2-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 88,200 kB
  • sloc: cpp: 110,259; sh: 16,733; makefile: 5,406; python: 1,391; yacc: 218; javascript: 203; xml: 191; awk: 61; sed: 5
file content (139 lines) | stat: -rw-r--r-- 4,906 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
///
/// This file is part of Rheolef.
///
/// Copyright (C) 2000-2009 Pierre Saramito <Pierre.Saramito@imag.fr>
///
/// Rheolef is free software; you can redistribute it and/or modify
/// it under the terms of the GNU General Public License as published by
/// the Free Software Foundation; either version 2 of the License, or
/// (at your option) any later version.
///
/// Rheolef is distributed in the hope that it will be useful,
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
/// GNU General Public License for more details.
///
/// You should have received a copy of the GNU General Public License
/// along with Rheolef; if not, write to the Free Software
/// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
/// 
/// =========================================================================
# include "rheolef/disarray.h"
# include "rheolef/load_chunk.h"
namespace rheolef {
// ----------------------------------------------------------------------------
// class member functions
// ----------------------------------------------------------------------------
template <class T, class A>
disarray_rep<T,sequential,A>::disarray_rep (const A& alloc)
  : base(alloc),
    _ownership ()
{
}
template <class T, class A>
disarray_rep<T,sequential,A>::disarray_rep (size_type loc_size1, const T& init_val, const A& alloc)
  : base(loc_size1, init_val, alloc),
    _ownership (distributor (distributor::decide, communicator(), loc_size1))
{
}
template <class T, class A>
disarray_rep<T,sequential,A>::disarray_rep (const distributor& ownership, const T& init_val, const A& alloc)
 : base(ownership.size(),init_val), // TODO: add alloc extra-arg for heap_allocator
  _ownership(ownership)
{
}
template <class T, class A>
disarray_rep<T,sequential,A>::disarray_rep (const disarray_rep<T,sequential,A>& x)
  : base(x.size()),
    _ownership(x._ownership)
{
   std::copy (x.begin(), x.end(), begin()); 
}
template <class T, class A>
void
disarray_rep<T,sequential,A>::resize (const distributor& ownership, const T&  init_val)
{
    // note: also called by disarray_rep<T,distributed,A>, so should works in distributed mode
    _ownership = ownership;
    base::resize (_ownership.size(), init_val);
    std::fill (begin(), end(), init_val);
}
template <class T, class A>
void
disarray_rep<T,sequential,A>::resize (size_type loc_size1, const T& init_val)
{
    // note: also called by disarray_rep<T,distributed,A>, so should works in distributed mode
    _ownership.resize (distributor::decide, _ownership.comm(), loc_size1);
    base::resize (_ownership.size(), init_val);
    std::fill (begin(), end(), init_val);
}
template <class T, class A>
template <class GetFunction>
idiststream&
disarray_rep<T,sequential,A>::get_values (idiststream& ips, GetFunction get_element) {
  std::istream& is = ips.is();
  if (!load_chunk (is, begin(), end(), get_element))
	error_macro("read failed on input stream.");
  return ips;
}
template <class T, class A>
idiststream&
disarray_rep<T,sequential,A>::get_values (idiststream& ips) 
{
  return get_values (ips, _disarray_get_element_type<T>());
}
template <class T, class A>
template <class PutFunction>
odiststream&
disarray_rep<T,sequential,A>::put_values (odiststream& ops, PutFunction put_element) const
{
    std::ostream& os = ops.os();
    for (size_type i = 0; i < size(); i++) {
        put_element (os, operator[](i));
	os << std::endl;
    }
    return ops;
}
template <class T, class A>
odiststream&
disarray_rep<T,sequential,A>::put_values (odiststream& ops) const
{
  return put_values (ops, _disarray_put_element_type<T>());
}
template <class T, class A>
odiststream&
disarray_rep<T,sequential,A>::put_matlab (odiststream& ops) const
{
  ops << "[";
  put_values (ops, _disarray_put_matlab_type<T>());
  return ops << "];";
}
template <class T, class A>
void
disarray_rep<T,sequential,A>::dump (std::string name) const {
    std::ofstream os (name.c_str());
    std::cerr << "! file \"" << name << "\" created." << std::endl;
    odiststream ops(os);
    put_values(ops);
}
template <class T, class A>
template<class A2>
void
disarray_rep<T,sequential,A>::reverse_permutation (                // old_ownership for *this=iold2inew
        disarray_rep<size_type,sequential,A2>& inew2iold) const    // new_ownership
{
  check_macro (inew2iold.size() == size(), "reverse permutation[0:"<<inew2iold.size()
        <<"[ has incompatible dis_range with oriinal permutation[0:"<<size()<<"[");
  for (size_type iold = 0, nold = size(); iold < nold; iold++) {
    size_type inew = operator[] (iold);
    inew2iold [inew] = iold;
  }
}
template <class T, class A>
void
disarray_rep<T,sequential,A>::get_dis_indexes (std::set<size_type>& ext_idx_set) const
{ 
  ext_idx_set.clear(); 
}   
//=======================================
} // namespace rheolef