[b92126]: src / __errcore__.cc  Maximize  Restore  History

Download this file

85 lines (75 with data), 2.4 kB

 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
//Copyright (C) 2003 David Bateman
//
// This program 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 3 of the
// License, or (at your option) any later version.
//
// This program 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 this program; if not, see
// <http://www.gnu.org/licenses/>.
//
// In addition to the terms of the GPL, you are permitted to link this
// program with any Open Source program, as defined by the Open Source
// Initiative (www.opensource.org)
#include <iostream>
#include <iomanip>
#include <sstream>
#include <octave/oct.h>
#include <octave/pager.h>
DEFUN_DLD (__errcore__, args, ,
"-*- texinfo -*-\n\
@deftypefn {Loadable Function} {@var{c} =} __errcore__ (@var{a}, @var{b})\n\
Returns the number of bit errors comparing the matrices @var{a} and\n\
@var{b}. These matrices must be of the same size. The return matrix @var{c}\n\
will also be of the same size.\n\
\n\
This is an internal function of @code{biterr} and @code{symerr}. You should\n\
use these functions instead.\n\
@seealso{biterr, symerr}\n\
@end deftypefn")
{
octave_value retval;
if (args.length () != 2)
{
print_usage ();
return retval;
}
Matrix a = args(0).matrix_value ();
Matrix b = args(1).matrix_value ();
if ((a.rows () != b.rows ()) || (a.cols () != b.cols ()))
{
error ("__errcore__: Matrix mismatch");
return retval;
}
unsigned int sz = (sizeof (unsigned int) << 3);
Matrix c (a.rows (), a.cols (), 0);
for (int i = 0; i < a.rows (); i++)
for (int j = 0; j < a.cols (); j++)
{
unsigned int tmp = (unsigned int)a(i,j) ^ (unsigned int)b(i,j);
if (tmp != 0)
for (unsigned int k=0; k < sz; k++)
if (tmp & (1<<k))
c(i,j)++;
}
retval = octave_value (c);
return retval;
}
/*
%% Test input validation
%!error __errcore__ ()
%!error __errcore__ (1)
%!error __errcore__ (1, 2, 3)
%!error __errcore__ ([1 2], 3)
*/
/*
;;; Local Variables: ***
;;; mode: C++ ***
;;; End: ***
*/

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks