source: mmcs/armadillo_bits/op_hist_meat.hpp @ 8daa049

matrices
Last change on this file since 8daa049 was 9dd61b1, checked in by rboet <rboet@…>, 9 years ago

Avance del proyecto 60%

  • Property mode set to 100644
File size: 1.8 KB
Line 
1// Copyright (C) 2012 Conrad Sanderson
2// Copyright (C) 2012 NICTA (www.nicta.com.au)
3//
4// This Source Code Form is subject to the terms of the Mozilla Public
5// License, v. 2.0. If a copy of the MPL was not distributed with this
6// file, You can obtain one at http://mozilla.org/MPL/2.0/.
7
8
9
10//! \addtogroup op_hist
11//! @{
12
13
14
15template<typename T1>
16inline
17void
18op_hist::apply(Mat<uword>& out, const mtOp<uword, T1, op_hist>& X)
19  {
20  arma_extra_debug_sigprint();
21 
22  typedef typename T1::elem_type eT;
23 
24  const uword n_bins = X.aux_uword_a;
25 
26  const unwrap_check_mixed<T1> tmp(X.m, out);
27  const Mat<eT>& A           = tmp.M;
28 
29 
30        uword A_n_elem = A.n_elem;
31  const eT*   A_mem    = A.memptr();
32 
33  eT min_val = priv::most_pos<eT>();
34  eT max_val = priv::most_neg<eT>();
35 
36  uword i,j;
37  for(i=0, j=1; j < A_n_elem; i+=2, j+=2)
38    {
39    const eT val_i = A_mem[i];
40    const eT val_j = A_mem[j];
41   
42    if(min_val > val_i) { min_val = val_i; }
43    if(min_val > val_j) { min_val = val_j; }
44     
45    if(max_val < val_i) { max_val = val_i; }
46    if(max_val < val_j) { max_val = val_j; }
47    }
48 
49  if(i < A_n_elem)
50    {
51    const eT val_i = A_mem[i];
52   
53    if(min_val > val_i) { min_val = val_i; }
54    if(max_val < val_i) { max_val = val_i; }
55    }
56 
57  if(arma_isfinite(min_val) == false) { min_val = priv::most_neg<eT>(); }
58  if(arma_isfinite(max_val) == false) { max_val = priv::most_pos<eT>(); }
59 
60  if(n_bins >= 1)
61    {
62    Col<eT> c(n_bins);
63    eT* c_mem = c.memptr();
64   
65    for(uword ii=0; ii < n_bins; ++ii)
66      {
67      c_mem[ii] = (0.5 + ii) / double(n_bins);   // TODO: may need to be modified for integer matrices
68      }
69   
70    c = ((max_val - min_val) * c) + min_val;
71   
72    out = hist(A, c);
73    }
74  else
75    {
76    out.reset();
77    }
78  }
79
80
81
82//! @}
Note: See TracBrowser for help on using the repository browser.