remove \r
[extl.git] / extl / intelligence / ann / float_sample.h
blobaca0127da1f5afbf0d0e4f6b3352f994216cf56b
1 /* ///////////////////////////////////////////////////////////////////////
2 * File: float_sample.h
4 * Created: 09.03.15
5 * Updated: 09.03.15
7 * Brief: The float_sample class
9 * [<Home>]
10 * Copyright (c) 2008-2020, Waruqi All rights reserved.
11 * //////////////////////////////////////////////////////////////////// */
13 #ifndef EXTL_INTELLIGENCE_ANN_FLOAT_SAMPLE_H
14 #define EXTL_INTELLIGENCE_ANN_FLOAT_SAMPLE_H
16 /*!\file float_sample.h
17 * \brief float_sample class
20 /* ///////////////////////////////////////////////////////////////////////
21 * Includes
23 #include "prefix.h"
25 /* ///////////////////////////////////////////////////////////////////////
26 * ::extl::intelligence namespace
28 EXTL_INTELLIGENCE_BEGIN_WHOLE_NAMESPACE
30 /*!brief float_sample
32 * \param InN the input demension
33 * \param OutN the output demension
35 * \ingroup extl_group_intelligence
37 template< e_size_t InN
38 , e_size_t OutN
40 class float_sample
42 /// \name Types
43 /// @{
44 public:
45 typedef float_sample class_type;
46 typedef e_bool_t bool_type;
47 typedef e_size_t size_type;
48 typedef size_type index_type;
49 typedef e_float_t float_type;
50 typedef e_char_t achar_type;
51 typedef e_wchar_t wchar_type;
52 typedef typename_type_k vvector_selector<float_type>::vvector_type input_type;
53 typedef typename_type_k vvector_selector<float_type>::vvector_type output_type;
54 typedef typename_type_k vvector_selector<float_type>::vvector_type real_type;
55 /// @}
57 /// \name Members
58 /// @{
59 private:
60 input_type m_input;
61 real_type m_real;
62 output_type m_output;
63 /// @}
65 /// \name Constants
66 /// @{
67 public:
68 enum { en_input_size = InN };
69 enum { en_output_size = OutN };
70 /// @}
73 /// \name Constructors
74 /// @{
75 public:
76 float_sample()
77 : m_input(en_input_size)
78 , m_real(en_output_size)
79 , m_output(en_output_size)
82 explicit_k float_sample(input_type const& input)
83 : m_input(input)
84 , m_real(en_output_size)
85 , m_output(en_output_size)
88 float_sample(input_type const& input, real_type const& real)
89 : m_input(input)
90 , m_real(real)
91 , m_output(en_output_size)
94 /// @}
96 /// \name Native Accessors
97 /// @{
98 public:
99 /// gets the input sample
100 input_type& input() { return m_input; }
101 /// gets the input sample
102 input_type const& input() const { return m_input; }
104 /// gets the output sample
105 output_type& output() { return m_output; }
106 /// gets the output sample
107 output_type const& output() const { return m_output; }
109 /// gets the result output
110 output_type& real() { return m_real; }
111 /// gets the result output
112 output_type const& real() const { return m_real; }
113 /// @}
115 /// \name Attributes
116 /// @{
117 public:
118 /// gets the size of the input
119 size_type const input_size() const { return m_input.size(); }
120 /// gets the size of the real
121 size_type const real_size() const { return m_real.size(); }
122 /// gets the size of the output
123 size_type const output_size() const { return m_output.size(); }
125 /// @}
127 /// \name Accessors (Recommended)
128 /// @{
129 public:
130 /// sets the input by string e.g. "010101"
131 void binput(achar_type const* s, size_type n);
132 /// sets the input by string e.g. "010101"
133 void binput(achar_type const* s) { binput(s, (NULL != s)? std_strlen(s) : 0); }
134 /// sets the input by string e.g. "010101"
135 void binput(wchar_type const* s, size_type n);
136 /// sets the input by string e.g. "010101"
137 void binput(wchar_type const* s) { binput(s, (NULL != s)? std_strlen(s) : 0); }
139 /// sets the input by digit e.g. 4
140 /// \note cannot be larger than 32-bits
141 void dinput(size_type digit);
142 /// gets the input by digit e.g. 4
143 /// \note cannot be larger than 32-bits
144 size_type dinput() const;
146 /// sets the input by string e.g. "010101"
147 void breal(achar_type const* s, size_type n);
148 /// sets the input by string e.g. "010101"
149 void breal(achar_type const* s) { breal(s, (NULL != s)? std_strlen(s) : 0); }
150 /// sets the input by string e.g. "010101"
151 void breal(wchar_type const* s, size_type n);
152 /// sets the input by string e.g. "010101"
153 void breal(wchar_type const* s) { breal(s, (NULL != s)? std_strlen(s) : 0); }
155 /// sets the real by digit e.g. 4
156 /// \note cannot be larger than 32-bits
157 void dreal(size_type digit);
158 /// gets the real by digit e.g. 4
159 /// \note cannot be larger than 32-bits
160 size_type dreal() const;
162 /// sets the output by digit e.g. 4
163 /// \note cannot be larger than 32-bits
164 void doutput(size_type digit);
165 /// gets the output sample by digit e.g. 4
166 /// \note cannot be larger than 32-bits
167 size_type doutput() const;
169 /// sets the float input value at the given position
170 void set_finput(index_type i, float_type f) { m_input[i] = f; }
171 /// gets the float input at the given position
172 float_type const get_finput(index_type i) const { return m_input[i]; }
174 /// sets the bool input value at the given position
175 void set_binput(index_type i, bool_type b) { m_input[i] = static_cast<float_type>(b); }
176 /// gets the bool input at the given position
177 bool_type const get_binput(index_type i) const { return (xtl_round45(m_input[i]) == 1); }
179 /// sets the float real value at the given position
180 void set_freal(index_type i, float_type f) { m_real[i] = f; }
181 /// gets the float real at the given position
182 float_type const get_freal(index_type i) const { return m_real[i]; }
184 /// sets the bool real value at the given position
185 void set_breal(index_type i, bool_type b) { m_real[i] = static_cast<float_type>(b); }
186 /// gets the bool real at the given position
187 bool_type const get_breal(index_type i) const { return (xtl_round45(m_real[i]) == 1); }
189 /// sets the float output value at the given position
190 void set_foutput(index_type i, float_type f) { m_output[i] = f; }
191 /// gets the float output at the given position
192 float_type const get_foutput(index_type i) const { return m_output[i]; }
194 /// sets the bool output value at the given position
195 void set_boutput(index_type i, bool_type b) { m_output[i] = static_cast<float_type>(b); }
196 /// gets the bool output at the given position
197 bool_type const get_boutput(index_type i) const { return (xtl_round45(m_output[i]) == 1); }
198 /// @}
200 /* ///////////////////////////////////////////////////////////////////////
201 * Implemention
203 template< e_size_t InN
204 , e_size_t OutN
206 inline void float_sample<InN, OutN>::binput(achar_type const* s, size_type n)
208 for (index_type i = 0; i < n; ++i)
209 set_binput(i, s[i] != '0');
211 template< e_size_t InN
212 , e_size_t OutN
214 inline void float_sample<InN, OutN>::binput(wchar_type const* s, size_type n)
216 for (index_type i = 0; i < n; ++i)
217 set_binput(i, s[i] != L'0');
219 template< e_size_t InN
220 , e_size_t OutN
222 inline void float_sample<InN, OutN>::breal(achar_type const* s, size_type n)
224 for (index_type i = 0; i < n; ++i)
225 set_breal(i, s[i] != '0');
227 template< e_size_t InN
228 , e_size_t OutN
230 inline void float_sample<InN, OutN>::breal(wchar_type const* s, size_type n)
232 for (index_type i = 0; i < n; ++i)
233 set_breal(i, s[i] != L'0');
235 template< e_size_t InN
236 , e_size_t OutN
238 inline void float_sample<InN, OutN>::dinput(size_type digit)
240 size_type n = xtl_min(input_size(), sizeof(size_type) * 8);
241 bit_field<size_type> field(n);
242 field.numeric(digit);
243 for (index_type i = 0; i < n; ++i)
244 set_binput(i, field[i]);
246 template< e_size_t InN
247 , e_size_t OutN
249 inline typename_type_ret_k float_sample<InN, OutN>::
250 size_type float_sample<InN, OutN>::dinput() const
252 size_type n = xtl_min(input_size(), sizeof(size_type) * 8);
253 bit_field<size_type> field(n);
254 for (index_type i = 0; i < n; ++i)
255 field.set(i, get_binput(i));
256 return field.numeric();
258 template< e_size_t InN
259 , e_size_t OutN
261 inline void float_sample<InN, OutN>::dreal(size_type digit)
263 size_type n = xtl_min(real_size(), sizeof(size_type) * 8);
264 bit_field<size_type> field(n);
265 field.numeric(digit);
266 for (index_type i = 0; i < n; ++i)
267 set_breal(i, field[i]);
269 template< e_size_t InN
270 , e_size_t OutN
272 inline typename_type_ret_k float_sample<InN, OutN>::
273 size_type float_sample<InN, OutN>::dreal() const
275 size_type n = xtl_min(real_size(), sizeof(size_type) * 8);
276 bit_field<size_type> field(n);
277 for (index_type i = 0; i < n; ++i)
278 field.set(i, get_breal(i));
279 return field.numeric();
281 template< e_size_t InN
282 , e_size_t OutN
284 inline void float_sample<InN, OutN>::doutput(size_type digit)
286 size_type n = xtl_min(output_size(), sizeof(size_type) * 8);
287 bit_field<size_type> field(n);
288 field.numeric(digit);
289 for (index_type i = 0; i < n; ++i)
290 set_boutput(i, field[i]);
292 template< e_size_t InN
293 , e_size_t OutN
295 inline typename_type_ret_k float_sample<InN, OutN>::
296 size_type float_sample<InN, OutN>::doutput() const
298 size_type n = xtl_min(output_size(), sizeof(size_type) * 8);
299 bit_field<size_type> field(n);
300 for (index_type i = 0; i < n; ++i)
301 field.set(i, get_boutput(i));
302 return field.numeric();
304 /* ///////////////////////////////////////////////////////////////////////
305 * ::extl::intelligence namespace
307 EXTL_INTELLIGENCE_END_WHOLE_NAMESPACE
309 /* //////////////////////////////////////////////////////////////////// */
310 #endif /* EXTL_INTELLIGENCE_ANN_FLOAT_SAMPLE_H */
311 /* //////////////////////////////////////////////////////////////////// */