forum.alglib.net

ALGLIB forum
It is currently Thu Mar 28, 2024 5:47 pm

All times are UTC


Forum rules


1. This forum can be used for discussion of both ALGLIB-related and general numerical analysis questions
2. This forum is English-only - postings in other languages will be removed.



Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: cannot compile examples
PostPosted: Wed Jul 29, 2020 6:44 pm 
Offline

Joined: Wed Jul 29, 2020 6:24 pm
Posts: 3
I have recently installed alglib and I am attempting to compile an example
My system is Ubuntu 18.04 64bit
I am using Qt Creator as my IDE for C++
C++17, gcc 7.4
the file I'm attempting to compile is shown below:
However, the C++ compiler and IDE both flag the line 63 and others containing
alglib::get_error_flag();
alglib::clear_error_flag();

where the IDE and compiler both say that clear_error_flag() is not in the namespace, e.g. "no member named 'get_error_flag" in namespace 'alglib'
Strange because when I look at the namespace alglib defined by ap.h, the alglib namespace apparently contains get_error_flag()
Any ideas?
thanks,
Phil





###########################################
#include <sstream>
#include <math.h>
#include <ap.h>
#include "linalg.h"
#include "stdafx.h"
#include "solvers.h"
#include "alglibmisc.h"
#include "statistics.h"
#include "integration.h"
#include "dataanalysis.h"
#include "optimization.h"
#include "alglibinternal.h"
#include "diffequations.h"
#include "interpolation.h"
#include "alglibinternal.h"
#include "fasttransforms.h"
#include "specialfunctions.h"


//#if !defined(AE_NO_EXCEPTIONS)
//#error "This test should be compiled with AE_NO_EXCEPTIONS defined"
//#endif

using namespace alglib;

const char *fmt_str = "%-29s %s\n";

int main()
{
printf("Test exception-free error handling:\n");

#ifdef AE_USE_ALLOC_COUNTER
printf("Allocation counter activated...\n");
alglib_impl::_use_alloc_counter = ae_true;
if( alglib_impl::_alloc_counter!=0 )
{
printf("FAILURE: alloc_counter is non-zero on start!\n");
return 1;
}
{
{
alglib::real_1d_array x;
x.setlength(1);
if( alglib_impl::_alloc_counter==0 )
printf(":::: WARNING: ALLOC_COUNTER IS INACTIVE!!! :::::\\n");
}
if( alglib_impl::_alloc_counter!=0 )
{
printf("FAILURE: alloc_counter does not decrease!\n");
return 1;
}
}
#endif

//
// Test default state of the error flag
//
{
bool passed = true;
passed = passed && !alglib::get_error_flag();
printf(fmt_str, "* default flag value", passed ? "OK" : "FAILED");
fflush(stdout);
if( !passed )
return 1;
}

//
// Test errors during array creation
//
{
bool passed = true;
alglib::clear_error_flag();

// constructors succeeded with working malloc()
alglib::clear_error_flag();
alglib::real_1d_array r1;
passed = passed && !alglib::get_error_flag();

// even with broken malloc() constructor succeeded()
alglib::clear_error_flag();
alglib_impl::_force_malloc_failure = true;
alglib::real_1d_array r2;
passed = passed && !alglib::get_error_flag();

// but setlength() fails without malloc()
alglib::clear_error_flag();
r2.setlength(5);
passed = passed && alglib::get_error_flag();

// clear_error_flag() clears error flag
alglib::clear_error_flag();
passed = passed && !alglib::get_error_flag();

// without clear_error_flag(), error flag is not reset by successful calls
alglib::clear_error_flag();
alglib_impl::_force_malloc_failure = true;
r2.setlength(5);
passed = passed && alglib::get_error_flag() && r2.length()==0;
alglib_impl::_force_malloc_failure = false;
r2.setlength(6);
passed = passed && alglib::get_error_flag() && r2.length()==6;
alglib::clear_error_flag();
r2.setlength(7);
passed = passed && !alglib::get_error_flag() && r2.length()==7;

// assignment to empty array requires malloc()
alglib::clear_error_flag();
alglib_impl::_force_malloc_failure = false;
alglib::real_1d_array r3;
r2.setlength(1);
r2[0] = 123.25;
alglib_impl::_force_malloc_failure = true;
r3 = r2;
passed = passed && alglib::get_error_flag() && r3.length()==0;
alglib_impl::_force_malloc_failure = false;
alglib::clear_error_flag();
r3 = r2;
passed = passed && !alglib::get_error_flag() && r3.length()==1 && r3[0]==123.25;

// assignment to non-empty array does NOT require malloc()
alglib::clear_error_flag();
alglib_impl::_force_malloc_failure = true;
r2[0] = 345;
r3 = r2;
passed = passed && !alglib::get_error_flag() && r3.length()==1 && r3[0]==345;
alglib_impl::_force_malloc_failure = false;

printf(fmt_str, "* 1D arrays", passed ? "OK" : "FAILED");
fflush(stdout);
if( !passed )
return 1;
}
{
bool passed = true;
alglib::clear_error_flag();

// constructors succeeded with working malloc()
alglib::clear_error_flag();
alglib::real_2d_array r1;
passed = passed && !alglib::get_error_flag();

// even with broken malloc() constructor succeeded()
alglib::clear_error_flag();
alglib_impl::_force_malloc_failure = true;
alglib::real_2d_array r2;
passed = passed && !alglib::get_error_flag();

// but setlength() fails without malloc()
alglib::clear_error_flag();
r2.setlength(5,6);
passed = passed && alglib::get_error_flag();

// clear_error_flag() clears error flag
alglib::clear_error_flag();
passed = passed && !alglib::get_error_flag();

// without clear_error_flag(), error flag is not reset by successful calls
alglib::clear_error_flag();
alglib_impl::_force_malloc_failure = true;
r2.setlength(5,6);
passed = passed && alglib::get_error_flag() && r2.rows()==0 && r2.cols()==0;
alglib_impl::_force_malloc_failure = false;
r2.setlength(6,7);
passed = passed && alglib::get_error_flag() && r2.rows()==6 && r2.cols()==7;
alglib::clear_error_flag();
r2.setlength(7,8);
passed = passed && !alglib::get_error_flag() && r2.rows()==7 && r2.cols()==8;

// assignment to empty array requires malloc()
alglib::clear_error_flag();
alglib_impl::_force_malloc_failure = false;
alglib::real_2d_array r3;
r2.setlength(1,1);
r2[0][0] = 123.25;
alglib_impl::_force_malloc_failure = true;
r3 = r2;
passed = passed && alglib::get_error_flag() && r3.rows()==0 && r3.cols()==0;
alglib_impl::_force_malloc_failure = false;
alglib::clear_error_flag();
r3 = r2;
passed = passed && !alglib::get_error_flag() && r3.rows()==1 && r3.cols()==1 && r3[0][0]==123.25;

// assignment to non-empty array does NOT require malloc()
alglib::clear_error_flag();
alglib_impl::_force_malloc_failure = true;
r2[0][0] = 345;
r3 = r2;
passed = passed && !alglib::get_error_flag() && r3.rows()==1 && r3.cols()==1 && r3[0][0]==345;
alglib_impl::_force_malloc_failure = false;

printf(fmt_str, "* 2D arrays", passed ? "OK" : "FAILED");
fflush(stdout);
if( !passed )
return 1;
}

//
// Test ALGLIB objects
//
{
bool passed = true;
alglib::clear_error_flag();

// prepare data for tests
alglib::real_1d_array x, y;
x.setlength(2);
x[0] = 0;
x[1] = 1;
y.setlength(2);
y[0] = 2;
y[1] = 3;

// constructors succeeded with working malloc()
alglib::clear_error_flag();
alglib::spline1dinterpolant s1;
passed = passed && !alglib::get_error_flag();

// with broken malloc() constructor fails()
alglib::clear_error_flag();
alglib_impl::_force_malloc_failure = true;
alglib::spline1dinterpolant s2;
passed = passed && alglib::get_error_flag();
alglib_impl::_force_malloc_failure = false;

// construction with correct malloc() succeeds
alglib::clear_error_flag();
alglib::spline1dbuildlinear(x, y, 2, s1);
passed = passed && !alglib::get_error_flag() && fabs(alglib::spline1dcalc(s1,0.5)-2.5)<1.0E-12;

// assignment with broken malloc() fails
alglib::clear_error_flag();
alglib::spline1dinterpolant s3;
alglib_impl::_force_malloc_failure = true;
s3 = s1;
alglib_impl::_force_malloc_failure = false;
passed = passed && alglib::get_error_flag();

// assignment with broken object fails, but does not crash
alglib::clear_error_flag();
alglib_impl::_force_malloc_failure = true;
alglib::spline1dinterpolant s3b;
passed = passed && s3b.c_ptr()==NULL;
s3b = s1;
alglib_impl::_force_malloc_failure = false;
passed = passed && alglib::get_error_flag();

// assignment with working malloc() succeeds
alglib::clear_error_flag();
s3 = s1;
passed = passed && !alglib::get_error_flag() && fabs(alglib::spline1dcalc(s3,0.5)-2.5)<1.0E-12;

// copy constructor with broken malloc fails
alglib::clear_error_flag();
alglib_impl::_force_malloc_failure = true;
alglib::spline1dinterpolant s4(s1);
alglib_impl::_force_malloc_failure = false;
passed = passed && alglib::get_error_flag();

// copy constructor with working malloc succeeds
alglib::clear_error_flag();
alglib::spline1dinterpolant s5(s1);
passed = passed && !alglib::get_error_flag() && fabs(alglib::spline1dcalc(s5,0.5)-2.5)<1.0E-12;

printf(fmt_str, "* ALGLIB objects", passed ? "OK" : "FAILED");
fflush(stdout);
if( !passed )
return 1;
}

//
// Test ALGLIB functions
//
{
bool passed = true;
//
alglib::clear_error_flag();
alglib::spline1dinterpolant s1;
alglib::real_1d_array x, y;
x.setlength(2);
x[0] = 0;
x[1] = 1;
y.setlength(2);
y[0] = 2;
y[1] = alglib::fp_nan;
passed = passed && !alglib::get_error_flag();
alglib::spline1dbuildlinear(x, y, 2, s1);
passed = passed && alglib::get_error_flag();

printf(fmt_str, "* ALGLIB functions", passed ? "OK" : "FAILED");
fflush(stdout);
if( !passed )
return 1;
}

//
// Allocation counter
//
#ifdef AE_USE_ALLOC_COUNTER
printf("Allocation counter checked... ");
if( alglib_impl::_alloc_counter!=0 )
{
printf("FAILURE: alloc_counter is non-zero on end!\n");
return 1;
}
else
printf("OK\n");
#endif

//
// Return
//
return 0;
}
########################################################


Top
 Profile  
 
 Post subject: Re: cannot compile examples
PostPosted: Wed Jul 29, 2020 9:39 pm 
Offline

Joined: Wed Jul 29, 2020 6:24 pm
Posts: 3
Hi I think I answered my own questions.
I just needed to add
#define AE_NO_EXCEPTIONS
#define AE_THREADING AE_SERIAL_UNSAFE
to the top of the file I showed in my last posting.
This will apparently enable inclusion of alglib::get_error_flag() and other similar functions
Thanks,
Phil


Top
 Profile  
 
 Post subject: Re: cannot compile examples
PostPosted: Wed Jul 29, 2020 11:23 pm 
Offline

Joined: Wed Jul 29, 2020 6:24 pm
Posts: 3
As it turns out I still do have a problem, namely compiling

############################################
#define AE_NO_EXCEPTIONS
#define AE_THREADING AE_SERIAL_UNSAFE

#include <sstream>
#include <math.h>
#include "ap.h"
#include "linalg.h"
#include "stdafx.h"
#include "solvers.h"
#include "alglibmisc.h"
#include "statistics.h"
#include "integration.h"
#include "dataanalysis.h"
#include "optimization.h"
#include "alglibinternal.h"
#include "diffequations.h"
#include "interpolation.h"
#include "alglibinternal.h"
#include "fasttransforms.h"
#include "specialfunctions.h"


#if !defined(AE_NO_EXCEPTIONS)
#error "This test should be compiled with AE_NO_EXCEPTIONS defined"
#endif

using namespace alglib;

const char *fmt_str = "%-29s %s\n";

int main()
{
printf("Test exception-free error handling:\n");

#ifdef AE_USE_ALLOC_COUNTER
printf("Allocation counter activated...\n");
alglib_impl::_use_alloc_counter = ae_true;
if( alglib_impl::_alloc_counter!=0 )
{
printf("FAILURE: alloc_counter is non-zero on start!\n");
return 1;
}
{
{
alglib::real_1d_array x;
x.setlength(1);
if( alglib_impl::_alloc_counter==0 )
printf(":::: WARNING: ALLOC_COUNTER IS INACTIVE!!! :::::\\n");
}
if( alglib_impl::_alloc_counter!=0 )
{
printf("FAILURE: alloc_counter does not decrease!\n");
return 1;
}
}
#endif

//
// Test default state of the error flag
//
{
bool passed = true;
passed = passed && !alglib::get_error_flag();
printf(fmt_str, "* default flag value", passed ? "OK" : "FAILED");
fflush(stdout);
if( !passed )
return 1;
}

//
// Test errors during array creation
//
{
bool passed = true;
alglib::clear_error_flag();

// constructors succeeded with working malloc()
alglib::clear_error_flag();
alglib::real_1d_array r1;
passed = passed && !alglib::get_error_flag();

// even with broken malloc() constructor succeeded()
alglib::clear_error_flag();
alglib_impl::_force_malloc_failure = true;
alglib::real_1d_array r2;
passed = passed && !alglib::get_error_flag();

// but setlength() fails without malloc()
alglib::clear_error_flag();
r2.setlength(5);
passed = passed && alglib::get_error_flag();

// clear_error_flag() clears error flag
alglib::clear_error_flag();
passed = passed && !alglib::get_error_flag();

// without clear_error_flag(), error flag is not reset by successful calls
alglib::clear_error_flag();
alglib_impl::_force_malloc_failure = true;
r2.setlength(5);
passed = passed && alglib::get_error_flag() && r2.length()==0;
alglib_impl::_force_malloc_failure = false;
r2.setlength(6);
passed = passed && alglib::get_error_flag() && r2.length()==6;
alglib::clear_error_flag();
r2.setlength(7);
passed = passed && !alglib::get_error_flag() && r2.length()==7;

// assignment to empty array requires malloc()
alglib::clear_error_flag();
alglib_impl::_force_malloc_failure = false;
alglib::real_1d_array r3;
r2.setlength(1);
r2[0] = 123.25;
alglib_impl::_force_malloc_failure = true;
r3 = r2;
passed = passed && alglib::get_error_flag() && r3.length()==0;
alglib_impl::_force_malloc_failure = false;
alglib::clear_error_flag();
r3 = r2;
passed = passed && !alglib::get_error_flag() && r3.length()==1 && r3[0]==123.25;

// assignment to non-empty array does NOT require malloc()
alglib::clear_error_flag();
alglib_impl::_force_malloc_failure = true;
r2[0] = 345;
r3 = r2;
passed = passed && !alglib::get_error_flag() && r3.length()==1 && r3[0]==345;
alglib_impl::_force_malloc_failure = false;

printf(fmt_str, "* 1D arrays", passed ? "OK" : "FAILED");
fflush(stdout);
if( !passed )
return 1;
}
{
bool passed = true;
alglib::clear_error_flag();

// constructors succeeded with working malloc()
alglib::clear_error_flag();
alglib::real_2d_array r1;
passed = passed && !alglib::get_error_flag();

// even with broken malloc() constructor succeeded()
alglib::clear_error_flag();
alglib_impl::_force_malloc_failure = true;
alglib::real_2d_array r2;
passed = passed && !alglib::get_error_flag();

// but setlength() fails without malloc()
alglib::clear_error_flag();
r2.setlength(5,6);
passed = passed && alglib::get_error_flag();

// clear_error_flag() clears error flag
alglib::clear_error_flag();
passed = passed && !alglib::get_error_flag();

// without clear_error_flag(), error flag is not reset by successful calls
alglib::clear_error_flag();
alglib_impl::_force_malloc_failure = true;
r2.setlength(5,6);
passed = passed && alglib::get_error_flag() && r2.rows()==0 && r2.cols()==0;
alglib_impl::_force_malloc_failure = false;
r2.setlength(6,7);
passed = passed && alglib::get_error_flag() && r2.rows()==6 && r2.cols()==7;
alglib::clear_error_flag();
r2.setlength(7,8);
passed = passed && !alglib::get_error_flag() && r2.rows()==7 && r2.cols()==8;

// assignment to empty array requires malloc()
alglib::clear_error_flag();
alglib_impl::_force_malloc_failure = false;
alglib::real_2d_array r3;
r2.setlength(1,1);
r2[0][0] = 123.25;
alglib_impl::_force_malloc_failure = true;
r3 = r2;
passed = passed && alglib::get_error_flag() && r3.rows()==0 && r3.cols()==0;
alglib_impl::_force_malloc_failure = false;
alglib::clear_error_flag();
r3 = r2;
passed = passed && !alglib::get_error_flag() && r3.rows()==1 && r3.cols()==1 && r3[0][0]==123.25;

// assignment to non-empty array does NOT require malloc()
alglib::clear_error_flag();
alglib_impl::_force_malloc_failure = true;
r2[0][0] = 345;
r3 = r2;
passed = passed && !alglib::get_error_flag() && r3.rows()==1 && r3.cols()==1 && r3[0][0]==345;
alglib_impl::_force_malloc_failure = false;

printf(fmt_str, "* 2D arrays", passed ? "OK" : "FAILED");
fflush(stdout);
if( !passed )
return 1;
}

//
// Test ALGLIB objects
//
{
bool passed = true;
alglib::clear_error_flag();

// prepare data for tests
alglib::real_1d_array x, y;
x.setlength(2);
x[0] = 0;
x[1] = 1;
y.setlength(2);
y[0] = 2;
y[1] = 3;

// constructors succeeded with working malloc()
alglib::clear_error_flag();
alglib::spline1dinterpolant s1;
passed = passed && !alglib::get_error_flag();

// with broken malloc() constructor fails()
alglib::clear_error_flag();
alglib_impl::_force_malloc_failure = true;
alglib::spline1dinterpolant s2;
passed = passed && alglib::get_error_flag();
alglib_impl::_force_malloc_failure = false;

// construction with correct malloc() succeeds
alglib::clear_error_flag();
alglib::spline1dbuildlinear(x, y, 2, s1);
passed = passed && !alglib::get_error_flag() && fabs(alglib::spline1dcalc(s1,0.5)-2.5)<1.0E-12;

// assignment with broken malloc() fails
alglib::clear_error_flag();
alglib::spline1dinterpolant s3;
alglib_impl::_force_malloc_failure = true;
s3 = s1;
alglib_impl::_force_malloc_failure = false;
passed = passed && alglib::get_error_flag();

// assignment with broken object fails, but does not crash
alglib::clear_error_flag();
alglib_impl::_force_malloc_failure = true;
alglib::spline1dinterpolant s3b;
passed = passed && s3b.c_ptr()==NULL;
s3b = s1;
alglib_impl::_force_malloc_failure = false;
passed = passed && alglib::get_error_flag();

// assignment with working malloc() succeeds
alglib::clear_error_flag();
s3 = s1;
passed = passed && !alglib::get_error_flag() && fabs(alglib::spline1dcalc(s3,0.5)-2.5)<1.0E-12;

// copy constructor with broken malloc fails
alglib::clear_error_flag();
alglib_impl::_force_malloc_failure = true;
alglib::spline1dinterpolant s4(s1);
alglib_impl::_force_malloc_failure = false;
passed = passed && alglib::get_error_flag();

// copy constructor with working malloc succeeds
alglib::clear_error_flag();
alglib::spline1dinterpolant s5(s1);
passed = passed && !alglib::get_error_flag() && fabs(alglib::spline1dcalc(s5,0.5)-2.5)<1.0E-12;

printf(fmt_str, "* ALGLIB objects", passed ? "OK" : "FAILED");
fflush(stdout);
if( !passed )
return 1;
}

//
// Test ALGLIB functions
//
{
bool passed = true;
//
alglib::clear_error_flag();
alglib::spline1dinterpolant s1;
alglib::real_1d_array x, y;
x.setlength(2);
x[0] = 0;
x[1] = 1;
y.setlength(2);
y[0] = 2;
y[1] = alglib::fp_nan;
passed = passed && !alglib::get_error_flag();
alglib::spline1dbuildlinear(x, y, 2, s1);
passed = passed && alglib::get_error_flag();

printf(fmt_str, "* ALGLIB functions", passed ? "OK" : "FAILED");
fflush(stdout);
if( !passed )
return 1;
}

//
// Allocation counter
//
#ifdef AE_USE_ALLOC_COUNTER
printf("Allocation counter checked... ");
if( alglib_impl::_alloc_counter!=0 )
{
printf("FAILURE: alloc_counter is non-zero on end!\n");
return 1;
}
else
printf("OK\n");
#endif

//
// Return
//
return 0;
}
#################################################################################
gives error messages:
/carbonics/owncloudsync/programs/C++/build-alglibtest-Desktop_Qt_5_12_4_GCC_64bit-Debug/../alglibtest/main.cpp:292: undefined reference to `alglib::get_error_flag(char const**)'

It appears that my installation of alglib is missing something?
Thanks in advance.
Phil


Top
 Profile  
 
 Post subject: Re: cannot compile examples
PostPosted: Tue Oct 06, 2020 9:12 pm 
Offline

Joined: Mon Nov 20, 2017 11:14 pm
Posts: 21
We made some changes here

https://github.com/LydiaMarieWilliamson/ALGLIB_cpp

and (hopefully) improvements to ALGLIB, better adapting it to a Linux configuration Linux:x86:GCC. Try that and see if it works.

A Makefile is included that runs the test files (as "make" or "make test"), which you can also use as a demo & example for creating your own build scripts or Makefiles for whatever project you include this in. It should also compile for 64-bit without problems. Optimization is turned fully on. If you have difficulties with it, post a note on her GitHub page.

Another revision will be uploaded possibly this week, so stay tuned for further developments (including later revisions to add in more multi-threading support)...

A few notes for Sergei:
(1) the redone version of the manual has some significant improvements in the layout, and keeps intact the class/function/example reference section from the C++ version of your documentation, so it may be something worth integrating into your distribution, as well,
(2) the GPL license in our version makes an explicit exception to allow you to incorporate changes made in our version into both your GPL version *and* your commercial version,
(3) as mentioned a while back in an earlier comment, we fixed the problems with real-number comparisons that occurs for GCC on x86-derived CPU's,
(4) we WILL be adding DSP-related routines into our version of FastTransforms.cpp soon (including routines for windowed Fourier Transforms, spectrographs, continuous wavelet transforms, scalographs, and possibly other time-frequency analysis transforms), all of which (2) will apply to.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 46 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group