1 /* ///////////////////////////////////////////////////////////////////////
7 * Brief: The float_sample class
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 /* ///////////////////////////////////////////////////////////////////////
25 /* ///////////////////////////////////////////////////////////////////////
26 * ::extl::intelligence namespace
28 EXTL_INTELLIGENCE_BEGIN_WHOLE_NAMESPACE
32 * \param InN the input demension
33 * \param OutN the output demension
35 * \ingroup extl_group_intelligence
37 template< e_size_t InN
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
;
68 enum { en_input_size
= InN
};
69 enum { en_output_size
= OutN
};
73 /// \name Constructors
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
)
84 , m_real(en_output_size
)
85 , m_output(en_output_size
)
88 float_sample(input_type
const& input
, real_type
const& real
)
91 , m_output(en_output_size
)
96 /// \name Native Accessors
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
; }
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(); }
127 /// \name Accessors (Recommended)
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); }
200 /* ///////////////////////////////////////////////////////////////////////
203 template< e_size_t InN
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
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
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
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
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
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
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
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
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
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 /* //////////////////////////////////////////////////////////////////// */