[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: problem with octfile (c++)
From: |
Olaf Till |
Subject: |
Re: problem with octfile (c++) |
Date: |
Tue, 31 Jan 2012 18:17:42 +0100 |
User-agent: |
Mutt/1.5.20 (2009-06-14) |
On Tue, Jan 31, 2012 at 04:20:41PM +0100, Guido Biele wrote:
> Hi,
>
> I have written an octfile which which sometimes runs, and sometimes
> crashes octave.
> Weirdly I can get the octfile to do its job by inserting a printf
> command at a certain location. however, if I call the function in a
> different setup, it will sometimes crash again. to makes things even
> weirder (to me), I can sometimes remove the printf command and the
> code still works (for soem tries).
>
> I think I must be missing something when werting the octfile.
> I'd appreciate very much if anybody could have a brief look and
> point me to possible sources of the error.
>
> the code for the octfile is below. the printf command that sometimes
> "helps" is in line 71.
>
> not sure if this helps: I have more generally problems with the
> dbstop function, so that the debugger does often not stop in the
> line in which i have set a break point. maybe this has to do with
> the octfile-problem?
>
> thanks in advance! Guido
Normally you have to use a debugger first, but ...
> ########### begin octfile ###############
> 1 #include <octave/oct.h>
> 2 #include <iostream>
> 3 using namespace std;
> 4
> 5 #define HELP (" \n \
> 6 usage: [nDetected] =
> global_detect40_c(NoiseMatrix,SignalMatrix,thetas1,thetas2,thetas3,thetas4)\n
> \
> 7 \n \
> 8 applies all combinations of thetas with decision rules on
> feature-vectors \n \
> 9 in order to detect noise. \n \
> 10 NoiseMatrix is a matrix with 6 feature for all noise components \n \
> 11 SignalMatrix is a matrix with 6 feature for all signal components \n \
> 12 thetas1 - thetas4 are matrices of three theta vlaues for ach of
> the 4 decision rules \n \
> 13 \n ")
> 14
> 15 DEFUN_DLD(global_detect4o_c, argv, , HELP){
> 16 octave_value retval;
> 17
> 18 if ( argv.length() != 6 ) {
> 19 error(HELP);
> 20 return retval;
> 21 }// Checking input
> 22
> 23 // defining output list
> 24 octave_value_list varargout;
> 25
> 26 printf ("%s ","begin global fit");
> 27
> 28 // get variables from input
> 29 Matrix NoiseMatrix( argv(0).matrix_value() );
> 30 Matrix SignalMatrix( argv(1).matrix_value() );
> 31 Matrix theta1( argv(2).matrix_value() );
> 32 Matrix theta2( argv(3).matrix_value() );
> 33 Matrix theta3( argv(4).matrix_value() );
> 34 Matrix theta4( argv(5).matrix_value() );
> 35
> 36 // set up required variables
> 37 int n_noisecomps = NoiseMatrix.rows();
> 38 int n_signalcomps = SignalMatrix.rows();
> 39 int ntheta1 = theta1.rows();
> 40 int ntheta2 = theta2.rows();
> 41 int ntheta3 = theta3.rows();
> 42 int ntheta4 = theta4.rows();
> 43 int nfeatures = NoiseMatrix.cols();
> 44
> 45 printf ("%i ",ntheta1);
> 46 printf ("%i ",ntheta2);
> 47 printf ("%i ",ntheta3);
> 48 printf ("%i \n",ntheta4);
> 49
> 50 // set up output_matrices
> 51 int ntheta_combs = ntheta1*ntheta2*ntheta3*ntheta4;
> 52 Matrix nDetected(ntheta_combs,1);
> 53 nDetected.fill(0);
> 54 Matrix nFalseAlarm(ntheta_combs,1);
> 55 nFalseAlarm.fill(0);
> 56
> 57 // intitialize required matrices
> 58 int nf, sf, t, c1, c2, c3, c4, DetectCount, FACount;
Here you declare, among others, 't', but it seems to be never
initialized, so should have an undefined value, which can change
between invocations.
> 59
> 60 for (c1=0; c1<ntheta1; c1++){
> 61 for (c2=0; c2<ntheta2; c2++){
> 62 for (c3=0; c3<ntheta3; c3++){
> 63 for (c4=0; c4<ntheta4; c4++){
> 64 DetectCount = 0;
> 65 printf ("%i ",t);
This printf above should show you the undefined value.
> 66 for (nf=0; nf<n_noisecomps; nf++){
> 67 if ( ( (NoiseMatrix(nf,1) < theta1(c1,0)) &&
> (NoiseMatrix(nf,3) < theta1(c1,1)) && (NoiseMatrix(nf,5) <
> theta1(c1,2)) ) || \
> 68 ( (NoiseMatrix(nf,0) < theta2(c2,0)) &&
> ((NoiseMatrix(nf,2) < theta2(c2,1)) || (NoiseMatrix(nf,3) <
> theta2(c2,2))) ) || \
> 69 ( (NoiseMatrix(nf,1) < theta3(c3,0)) &&
> (NoiseMatrix(nf,3) < theta3(c3,1)) && (NoiseMatrix(nf,5) <
> theta3(c3,3)) ) || \
> 70 ( (NoiseMatrix(nf,1) < theta4(c4,0)) &&
> (NoiseMatrix(nf,3) < theta4(c4,1)) && (NoiseMatrix(nf,4) <
> theta4(c4,3)) ) )
> 71 {DetectCount++;}
> 72 }
> 73 nDetected(t,0) = DetectCount;
And in the line above you use the undefined 't' as an index into
'nDetected', so it might (sometimes) index a position which does not
belong to nDetected -> crash.
(I stopped here looking for possible sources of the crash.)
Olaf
> 74
> 75 FACount = 0;
> 76 for (sf=0; sf<n_signalcomps; sf++){
> 77 if ( ( (SignalMatrix(sf,1) < theta1(c1,0)) &&
> (SignalMatrix(sf,3) < theta1(c1,1)) && (SignalMatrix(sf,5) <
> theta1(c1,2)) ) || \
> 78 ( (SignalMatrix(sf,0) < theta2(c2,0)) &&
> ((SignalMatrix(sf,2) < theta2(c2,1)) || (SignalMatrix(sf,3) <
> theta2(c2,2))) ) || \
> 79 ( (SignalMatrix(sf,1) < theta3(c3,0)) &&
> (SignalMatrix(sf,3) < theta3(c3,1)) && (SignalMatrix(sf,5) <
> theta3(c3,3)) ) || \
> 80 ( (SignalMatrix(sf,1) < theta4(c4,0)) &&
> (SignalMatrix(sf,3) < theta4(c4,1)) && (SignalMatrix(sf,4) <
> theta4(c4,3)) ) )
> 81 {FACount++;}
> 82 }
> 83 nFalseAlarm(t,0) = FACount;
> 84 t++;
> 85 }
> 86 }
> 87 }
> 88 }
> 89
> 90 printf ("%s \n \n","global fit finished");
> 91
> 92 varargout(0) = nDetected/n_noisecomps;
> 93 varargout(1) = nFalseAlarm/n_signalcomps;
> 94 return varargout;
> 95 }
> ########### end octfile ###############
>
>
> --
> ------------------------------------------------------------------------
>
> Guido Biele
> Email: address@hidden
> Phone: +47 228 45172
> Website <https://sites.google.com/a/neuro-cognition.org/guido/home>
>
>
> Visiting Address
> Psykologisk Institutt
> Forskningsveien 3 A
> 0373 OSLO
>
>
>
> Mailing Address
> Psykologisk Institutt
> Postboks 1094
> Blindern 0317 OSLO
>
>
>
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://mailman.cae.wisc.edu/listinfo/help-octave