From b4bd6b4ba89415e5dcb7d4d2258cd605e8b5dcc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Santos=20Costa?= Date: Thu, 18 Oct 2018 22:00:27 +0100 Subject: [PATCH 1/2] small fixes --- C/fli_absmi_insts.h | 4 ++++ CXX/yapi.cpp | 2 +- CXX/yapt.hh | 3 ++- library/lists.yap | 2 +- packages/ProbLog/problog_lbfgs.yap | 21 ++++----------------- packages/jpl/src/c/jpl.c | 4 ++-- pl/listing.yap | 2 +- pl/protect.yap | 2 +- 8 files changed, 16 insertions(+), 24 deletions(-) diff --git a/C/fli_absmi_insts.h b/C/fli_absmi_insts.h index 4a08b62ec..b59b41aa0 100644 --- a/C/fli_absmi_insts.h +++ b/C/fli_absmi_insts.h @@ -623,6 +623,10 @@ BOp(undef_p, e); /* save S for module name */ + if (LOCAL_DoingUndefp) { + PREG=FAILCODE; + JMPNext(); + } LOCAL_DoingUndefp = true; saveregs(); undef_goal(PASS_REGS1); diff --git a/CXX/yapi.cpp b/CXX/yapi.cpp index 77103c7fc..c0859d0dd 100644 --- a/CXX/yapi.cpp +++ b/CXX/yapi.cpp @@ -977,7 +977,7 @@ PredEntry *YAPPredicate::getPred(Term &t, Term &m, CELL *&out) { } else { ap = RepPredProp(PredPropByFunc(f, m)); if (out) - memmove(out, RepAppl(t) + 1, ap->ArityOfPE * sizeof(CELL)); + memmove(out, (const CELL *)RepAppl(t) + 1, ap->ArityOfPE * sizeof(CELL)); else out = RepAppl(t) + 1; } diff --git a/CXX/yapt.hh b/CXX/yapt.hh index c7086702f..bf8abb188 100644 --- a/CXX/yapt.hh +++ b/CXX/yapt.hh @@ -525,8 +525,9 @@ public: mk(t); } } + /// type check for unbound bool unbound() { return IsUnboundVar(VarOfTerm(gt())); } - inline bool isVar() { return true; } /// type check for unbound + inline bool isVar() { return true; } inline bool isAtom() { return false; } /// type check for atom inline bool isInteger() { return false; } /// type check for integer inline bool isFloat() { return false; } /// type check for floating-point diff --git a/library/lists.yap b/library/lists.yap index f6f927a7f..e1c85f902 100644 --- a/library/lists.yap +++ b/library/lists.yap @@ -57,7 +57,7 @@ with the `use_module(library(lists))` command. */ -:- include(pl/bootlists). +%:- include(pl/bootlists). /** @pred list_concat(+ _Lists_,? _List_) diff --git a/packages/ProbLog/problog_lbfgs.yap b/packages/ProbLog/problog_lbfgs.yap index 8dbdc5bb8..4a0ae9057 100644 --- a/packages/ProbLog/problog_lbfgs.yap +++ b/packages/ProbLog/problog_lbfgs.yap @@ -703,7 +703,7 @@ ground_truth_difference :- %= -Float %======================================================================== -mse_trainingset_only_for_linesearch(MSE) :- +mse_trainingset_only_for_linesearch(MSE, FX) :- update_values, example_count(Example_Count), @@ -712,21 +712,8 @@ mse_trainingset_only_for_linesearch(MSE) :- forall(user:example(QueryID,_Query,QueryProb,Type), ( once(update_query(QueryID,'.',probability)), - query_probability(QueryID,CurrentProb), once(update_query_cleanup(QueryID)), - ( - (Type == '='; (Type == '<', CurrentProb>QueryProb); (Type=='>',CurrentProb - ( - bb_get(error_train_line_search,Old_Error), - New_Error is Old_Error + (CurrentProb-QueryProb)**2, - bb_put(error_train_line_search,New_Error) - );true - ) - ) - ), - bb_delete(error_train_line_search,Error), - MSE is Error/Example_Count, + ), format_learning(3,' (~8f)~n',[MSE]), retractall(values_correct). @@ -842,7 +829,7 @@ set_tunable(I,Slope,P) :- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % start calculate gradient - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% user:evaluate(LLH_Training_Queries, X,Grad,N,_,_) :- %Handle = user_error, example_count(TrainingExampleCount), @@ -984,7 +971,7 @@ user:progress(FX,X,_G,X_Norm,G_Norm,Step,_N,Iteration,Ls,0) :- NextIteration is CurrentIteration+1, assertz(current_iteration(NextIteration)), save_model, - set_problog_flag(mse_trainset, FX), + set_problog_flag(mse_trainingset, FX), X0 <== X[0], sigmoid(X0,Slope,P0), X1 <== X[1], sigmoid(X1,Slope,P1), format('~d. Iteration : (x0,x1)=(~4f,~4f) f(X)=~4f |X|=~4f |X\'|=~4f Step=~4f Ls=~4f~n',[Iteration,P0 ,P1,FX,X_Norm,G_Norm,Step,Ls]). diff --git a/packages/jpl/src/c/jpl.c b/packages/jpl/src/c/jpl.c index d7e0c6c21..dcf432df5 100755 --- a/packages/jpl/src/c/jpl.c +++ b/packages/jpl/src/c/jpl.c @@ -640,7 +640,7 @@ static JNIEnv* jni_env(void) /* economically gets a JNIEnv pointer, valid for this thread */ { JNIEnv *env; - switch( (*jvm)->GetEnv(jvm, (void**)&env, JNI_VERSION_1_8) ) + switch( (*jvm)->GetEnv(jvm, (void**)&env, JNI_VERSION_1_4) ) { case JNI_OK: return env; case JNI_EDETACHED: @@ -5675,7 +5675,7 @@ static foreign_t int i; term_t head; term_t list; - char *s; + char *s = NULL; if ( jvm_dia == NULL ) /* presumably, JVM is already started, so default options cannot now be set */ { diff --git a/pl/listing.yap b/pl/listing.yap index dec2fe9e1..a6ca3227a 100644 --- a/pl/listing.yap +++ b/pl/listing.yap @@ -166,7 +166,7 @@ listing(Stream, [MV|MVs]) :- !, -> format( Stream, ':- dynamic ~q/~d.~n', [N,Ar]) ; -\ format( Stream, ':- dynamic ~q:~q/~d.~n', [M,N,Ar]) + format( Stream, ':- dynamic ~q:~q/~d.~n', [M,N,Ar]) ), fail. '$list_clauses'(Stream, M, Pred) :- diff --git a/pl/protect.yap b/pl/protect.yap index 242d951c5..1676096e4 100755 --- a/pl/protect.yap +++ b/pl/protect.yap @@ -48,7 +48,7 @@ prolog:'$protect' :- '$new_system_predicate'(Name,Arity,M), sub_atom(Name,0,1,_, '$'), functor(P,Name,Arity), - %'$hide_predicate'(P,M), + '$stash_predicate'(P,M), fail. prolog:'$protect' :- current_atom(Name), From 8fcf3eb00844c5791e614106c08455dd3907cab7 Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Fri, 19 Oct 2018 14:56:49 +0100 Subject: [PATCH 2/2] lbfgs memory leaks with _output_ improve configure --- .configure-custom.sh | 6 +- C/c_interface.c | 21 - C/dbase.c | 2 +- C/text.c | 119 ++-- CMakeLists.txt | 771 ++++++++++++------------ configure | 12 +- os/sysbits.c | 4 +- packages/ProbLog/problog_lbdd.yap | 6 +- packages/ProbLog/problog_lbfgs.yap | 170 +++--- packages/bdd/cudd.c | 3 + packages/myddas/mysql/CMakeLists.txt | 4 + packages/myddas/odbc/CMakeLists.txt | 75 +-- packages/myddas/postgres/CMakeLists.txt | 68 ++- packages/myddas/sqlite3/CMakeLists.txt | 122 ++-- packages/python/pybips.c | 8 +- 15 files changed, 731 insertions(+), 660 deletions(-) diff --git a/.configure-custom.sh b/.configure-custom.sh index c907ced73..dec040a31 100644 --- a/.configure-custom.sh +++ b/.configure-custom.sh @@ -12,11 +12,15 @@ WITH_VARS="swig|yes|WITH_SWIG \ mpi|yes|WITH_MPI \ gecode|yes|WITH_GECODE \ docs|yes|WITH_DOCS \ - r|yes|WITH_REAL \ + r|yes|WITH_R \ + myddas|yes|WITH_MYDDAS \ cudd|yes|WITH_CUDD \ xml2|yes|WITH_XML2 \ raptor|yes|WITH_RAPTOR \ python|yes|WITH_PYTHON \ openssl|yes|WITH_OPENSSL\ + java|yes|WITH_JAVA + lbfgs|yes|WITH_LBFGS + extensions|yes|WITH_EXTENSIONS readline|yes|WITH_READLINE \ gmp|yes|WITH_GMP" diff --git a/C/c_interface.c b/C/c_interface.c index ca0fb9e39..85ce12a72 100755 --- a/C/c_interface.c +++ b/C/c_interface.c @@ -1811,27 +1811,6 @@ X_API bool YAP_RetryGoal(YAP_dogoalinfo *dgi) { return out; } -static void completeInnerCall(bool on_cut, yamop *old_CP, yamop *old_P) { - if (on_cut) { - P = old_P; - ENV = (CELL *)ENV[E_E]; - CP = old_CP; - LOCAL_AllowRestart = TRUE; - // we are back to user code again, need slots */ - } else { - P = old_P; - ENV = B->cp_env; - ENV = (CELL *)ENV[E_E]; - CP = old_CP; - HR = B->cp_h; - TR = B->cp_tr; - B = B->cp_b; - LOCAL_AllowRestart = FALSE; - SET_ASP(ENV, E_CB * sizeof(CELL)); - // make sure the slots are ok. - } -} - X_API bool YAP_LeaveGoal(bool successful, YAP_dogoalinfo *dgi) { CACHE_REGS choiceptr myB, handler; diff --git a/C/dbase.c b/C/dbase.c index 7f1b53f67..db253b349 100644 --- a/C/dbase.c +++ b/C/dbase.c @@ -25,7 +25,7 @@ static char SccsId[] = "%W% %G%"; * * @brief record and other forms of storing terms. * - * / + */ /** @defgroup Internal_Database Internal Data Base diff --git a/C/text.c b/C/text.c index 7b1a1bd16..b161b6456 100644 --- a/C/text.c +++ b/C/text.c @@ -59,54 +59,6 @@ typedef struct TextBuffer_manager { } text_buffer_t; int AllocLevel(void) { return LOCAL_TextBuffer->lvl; } -int push_text_stack__(USES_REGS1) { - int i = LOCAL_TextBuffer->lvl; - i++; - LOCAL_TextBuffer->lvl = i; - - return i; -} - -int pop_text_stack__(int i) { - int lvl = LOCAL_TextBuffer->lvl; - while (lvl >= i) { - struct mblock *p = LOCAL_TextBuffer->first[lvl]; - while (p) { - struct mblock *np = p->next; - free(p); - p = np; - } - LOCAL_TextBuffer->first[lvl] = NULL; - LOCAL_TextBuffer->last[lvl] = NULL; - lvl--; - } - LOCAL_TextBuffer->lvl = lvl; - return lvl; -} - -void *pop_output_text_stack__(int i, const void *export) { - int lvl = LOCAL_TextBuffer->lvl; - while (lvl >= i) { - struct mblock *p = LOCAL_TextBuffer->first[lvl]; - while (p) { - struct mblock *np = p->next; - if (p + 1 == export) { - size_t sz = p->sz - sizeof(struct mblock); - memmove(p, p + 1, sz); - export = p; - } else { - free(p); - } - p = np; - } - LOCAL_TextBuffer->first[lvl] = NULL; - LOCAL_TextBuffer->last[lvl] = NULL; - lvl--; - } - LOCAL_TextBuffer->lvl = lvl; - return (void *)export; -} - // void pop_text_stack(int i) { LOCAL_TextBuffer->lvl = i; } void insert_block(struct mblock *o) { int lvl = o->lvl; @@ -138,6 +90,68 @@ void release_block(struct mblock *o) { o->next->prev = o->prev; } +int push_text_stack__(USES_REGS1) { + int i = LOCAL_TextBuffer->lvl; + i++; + LOCAL_TextBuffer->lvl = i; + + return i; +} + +int pop_text_stack__(int i) { + int lvl = LOCAL_TextBuffer->lvl; + while (lvl >= i) { + struct mblock *p = LOCAL_TextBuffer->first[lvl]; + while (p) { + struct mblock *np = p->next; + free(p); + p = np; + } + LOCAL_TextBuffer->first[lvl] = NULL; + LOCAL_TextBuffer->last[lvl] = NULL; + lvl--; + } + LOCAL_TextBuffer->lvl = lvl; + return lvl; +} + +void *pop_output_text_stack__(int i, const void *export) { + int lvl = LOCAL_TextBuffer->lvl; + bool found = false; + while (lvl >= i) { + struct mblock *p = LOCAL_TextBuffer->first[lvl]; + while (p) { + struct mblock *np = p->next; + if (p + 1 == export) { + found = true; + } else { + free(p); + } + p = np; + } + LOCAL_TextBuffer->first[lvl] = NULL; + LOCAL_TextBuffer->last[lvl] = NULL; + lvl--; + } + LOCAL_TextBuffer->lvl = lvl; + if (found) { + if (lvl) { + struct mblock *o = (struct mblock *)export-1; + o->lvl = lvl; + o->prev = o->next = 0; + insert_block(o); + + } else { + struct mblock *p = (struct mblock *)export-1; + size_t sz = p->sz - sizeof(struct mblock); + memmove(p, p + 1, sz); + export = p; + + } + } + return (void *)export; +} + void *Malloc(size_t sz USES_REGS) { int lvl = LOCAL_TextBuffer->lvl; if (sz == 0) @@ -1027,10 +1041,11 @@ bool Yap_Concat_Text(int tot, seq_tv_t inp[], seq_tv_t *out USES_REGS) { void **bufv; unsigned char *buf; int i, j; - // int lvl = push_text_stack(); + + int lvl = push_text_stack(); bufv = Malloc(tot * sizeof(unsigned char *)); if (!bufv) { - // pop_text_stack(lvl); + pop_text_stack(lvl); return NULL; } for (i = 0, j = 0; i < tot; i++) { @@ -1038,7 +1053,7 @@ bool Yap_Concat_Text(int tot, seq_tv_t inp[], seq_tv_t *out USES_REGS) { unsigned char *nbuf = Yap_readText(inp + i PASS_REGS); if (!nbuf) { - // pop_text_stack(lvl); + pop_text_stack(lvl); return NULL; } // if (!nbuf[0]) @@ -1054,7 +1069,7 @@ bool Yap_Concat_Text(int tot, seq_tv_t inp[], seq_tv_t *out USES_REGS) { buf = concat(tot, bufv PASS_REGS); } bool rc = write_Text(buf, out PASS_REGS); - // pop_text_stack( lvl ); + pop_text_stack( lvl ); return rc; } diff --git a/CMakeLists.txt b/CMakeLists.txt index 6b11bf0f0..5437b9137 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,24 +50,79 @@ include(GetGitRevisionDescription) # Search packages for host system instead of packages for target system # in case of cross compilation define these macro by toolchain file if (NOT COMMAND find_host_package) - macro(find_host_package) - find_package(${ARGN}) - endmacro() + macro(find_host_package) + find_package(${ARGN}) + endmacro() endif () if (NOT COMMAND find_host_program) - macro(find_host_program) - find_program(${ARGN}) - endmacro() + macro(find_host_program) + find_program(${ARGN}) + endmacro() endif () if (POLICY CMP0003) - cmake_policy(SET CMP0003 NEW) + cmake_policy(SET CMP0003 NEW) endif () if (POLICY CMP0068) - cmake_policy(SET CMP0068 NEW) + cmake_policy(SET CMP0068 NEW) endif () +## options: compilation flags option(BUILD_SHARED_LIBS "Build shared library" ON) +CMAKE_DEPENDENT_OPTION(WITH_SYSTEM_MMAP "Use MMAP for shared memory allocation" ON "NOT WITH_YAPOR_THOR" OFF) +CMAKE_DEPENDENT_OPTION(WITH_SYSTEM_SHM "Use SHM for shared memory allocation" ON "NOT WITH_YAPOR_THOR; NOT WITH_SYSTEM_MMAP" OFF) +OPTION(WITH_CALL_TRACER "support for procedure-call tracing" ${DEBUG}) +option(WITH_YAP_DLL "compile YAP as a DLL" ON) +option(WITH_YAP_STATIC "compile YAP statically" OFF) +option(WITH_YAP_CONDOR "allow YAP to be used from condor" OFF) +option(WITH_YAP_DLL "compile YAP as a DLL" ON) +if (WITH_YAP_CONDOR) + set(WITH_YAP_STATIC ON) + set(WITH_YAP_DLL OFF) +endif () + +## options: libraries +option(WITH_THREADED_CODE "threaded code" ON) +option(WITH_MPI "Interface to OpenMPI/MPICH" ON) +option(WITH_READLINE "use readline or libedit" ON) +option(WITH_JIT "just in Time Clause Compilation" OFF) + +if (APPLE) + option(WITH_BREW "brew" ON) + if (not WITH_BREW) + option(WITH_MACPORTS "mac-ports" ON) + endif() +endif() + +option (WITH_EXTENSIONS "packages and libraries that add value to YAP" ON) +if (ANDROID) + OPTION(WITH_MYDDAS " Enable MYDDAS driver" ON) + OPTION(WITH_SQLITE3 " Enable MYDDAS SQLITE3 driver" ON) +elseif(WITH_EXTENSIONS) + if (WITH_MYDDAS) + OPTION(WITH_MYSQL " Enable MYDDAS MYSQL driver" ON) + OPTION(WITH_ODBC " Enable MYDDAS ODBC driver" ON) + OPTION(WITH_POSTGRES " Enable MYDDAS POSTGRES driver" ON) + OPTION(WITH_SQLITE3 " Enable MYDDAS SQLITE3 driver" ON) + endif() + OPTION(WITH_SWIG " Enable SWIG interfaces to foreign languages" ON) + OPTION(WITH_RAPTOR " Enable the RAPTOR RDF library" ON) + OPTION(WITH_XML2 " Enable the RAPTOR XML2 library" ON) + OPTION(WITH_XML " Enable the Prolog XML library" ON) + OPTION(WITH_CLPBN" Enable the CLPBN and PFL probabilistic languages" ON) + IF (WITH_CLPBN) + OPTION(WITH_HORUS " Enable the HORUS inference libraray for CLPBN and PFL" ON) + ENDIF() + option(WITH_PROBLOG "include Problog-I." ON) + OPTION(WITH_CPLINT " Enable the cplint probabilistic language" ON) + option(WITH_GECODE "interface gecode constraint solver" ON) + option(WITH_LBFGS "interface with lbfgs" ON) + option(WITH_PRISM "use PRISM system in YAP" ON) + option(WITH_PYTHON "Allow Python->YAP and YAP->Python" ON) + option(WITH_R "Use R Interface" ON) + option(WITH_JAVA "Try to use Java (currently Java 6,7,8)" ON) + +endif() set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE) @@ -77,124 +132,124 @@ set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE) include(MacroLogFeature) if (POLICY CMP0042) - cmake_policy(SET CMP0042 NEW) + cmake_policy(SET CMP0042 NEW) endif () function(add_to_group list output) - set(tmp ${${output}}) - foreach (path ${${list}}) - get_source_file_property(path ${path} LOCATION) - list(APPEND tmp ${path}) - endforeach () - set(${output} ${tmp} CACHE INTERNAL "prolog library files") + set(tmp ${${output}}) + foreach (path ${${list}}) + get_source_file_property(path ${path} LOCATION) + list(APPEND tmp ${path}) + endforeach () + set(${output} ${tmp} CACHE INTERNAL "prolog library files") endfunction(add_to_group list output) function(add_to_libgroup el list) - # add_custom_command( TARGET ${el} POST_BUILD - # COMMAND ${CMAKE_COMMAND} -E copy $ ${CMAKE_BINARY_DIR}/packages/python/swig/yap4py - # DEPENDS ${el} ) - list(APPEND ${list} ${${el}}) - set(${list} ${${list}} CACHE INTERNAL "prolog dll files") + # add_custom_command( TARGET ${el} POST_BUILD + # COMMAND ${CMAKE_COMMAND} -E copy $ ${CMAKE_BINARY_DIR}/packages/python/swig/yap4py + # DEPENDS ${el} ) + list(APPEND ${list} ${${el}}) + set(${list} ${${list}} CACHE INTERNAL "prolog dll files") endfunction(add_to_libgroup el list) function(add_to_corelibgroup el list) - # add_custom_command( TARGET ${el} POST_BUILD - # COMMAND ${CMAKE_COMMAND} -E copy $ $ $ ${CMAKE_BINARY_DIR}/packages/python/swig/yap4py - # DEPENDS ${el} ) - list(APPEND ${list} ${${el}}) - set(${list} ${${list}} CACHE INTERNAL "prolog dll files") + # add_custom_command( TARGET ${el} POST_BUILD + # COMMAND ${CMAKE_COMMAND} -E copy $ $ $ ${CMAKE_BINARY_DIR}/packages/python/swig/yap4py + # DEPENDS ${el} ) + list(APPEND ${list} ${${el}}) + set(${list} ${${list}} CACHE INTERNAL "prolog dll files") endfunction(add_to_corelibgroup el list) if (ANDROID_OLD) - macro(MY_add_custom_target) - endmacro() + macro(MY_add_custom_target) + endmacro() else () - macro(MY_add_custom_target) - add_custom_target(${ARGN}) - endmacro() + macro(MY_add_custom_target) + add_custom_target(${ARGN}) + endmacro() endif () if (WIN32) - macro(add_component arg1) - add_library(${arg1} OBJECT ${ARGN}) - endmacro() + macro(add_component arg1) + add_library(${arg1} OBJECT ${ARGN}) + endmacro() else () - macro(add_component arg1) - add_library(${arg1} OBJECT ${ARGN}) - endmacro() + macro(add_component arg1) + add_library(${arg1} OBJECT ${ARGN}) + endmacro() endif () macro(add_lib arg1) - add_library(${arg1} SHARED ${ARGN}) - add_to_libgroup(${arg1} YAP_DLLS) + add_library(${arg1} SHARED ${ARGN}) + add_to_libgroup(${arg1} YAP_DLLS) endmacro() macro(add_corelib arg1) - add_library(${arg1} SHARED ${ARGN}) - add_to_corelibgroup(${arg1} YAP_DLLS) + add_library(${arg1} SHARED ${ARGN}) + add_to_corelibgroup(${arg1} YAP_DLLS) endmacro() if (ANDROID_OLD) - macro(MY_add_dependencies) - endmacro() + macro(MY_add_dependencies) + endmacro() else () - macro(MY_add_dependencies) - add_dependencies(${ARGN}) - endmacro() + macro(MY_add_dependencies) + add_dependencies(${ARGN}) + endmacro() endif () if (ANDROID_OLD) - macro(MY_add_library) - endmacro() + macro(MY_add_library) + endmacro() else () - macro(MY_add_library) - add_library(${ARGN}) - endmacro() + macro(MY_add_library) + add_library(${ARGN}) + endmacro() endif () if (ANDROID) - macro(MY_add_subdirectory) - endmacro() + macro(MY_add_subdirectory) + endmacro() else () - macro(MY_add_subdirectory) - add_subdirectory(${ARGN}) - endmacro() + macro(MY_add_subdirectory) + add_subdirectory(${ARGN}) + endmacro() endif () if (ANDROID_OLD) - macro(MY_include) - endmacro() + macro(MY_include) + endmacro() else () - macro(MY_include) - include(${ARGN}) - endmacro() + macro(MY_include) + include(${ARGN}) + endmacro() endif () if (ANDROID) - macro(MY_install) - endmacro() + macro(MY_install) + endmacro() else () - macro(MY_install) - install(${ARGN}) - endmacro() + macro(MY_install) + install(${ARGN}) + endmacro() endif () if (ANDROID_OLD) - macro(MY_set_target_properties) - endmacro() + macro(MY_set_target_properties) + endmacro() else () - macro(MY_set_target_properties) - set_target_properties(${ARGN}) - endmacro() + macro(MY_set_target_properties) + set_target_properties(${ARGN}) + endmacro() endif () if (ANDROID_OLD) - macro(MY_target_link_libraries) - endmacro() + macro(MY_target_link_libraries) + endmacro() else () - macro(MY_target_link_libraries) - target_link_libraries(${ARGN}) - endmacro() + macro(MY_target_link_libraries) + target_link_libraries(${ARGN}) + endmacro() endif () @@ -210,15 +265,15 @@ disallow_intree_builds() # set(CMAKE_BUILD_TYPE Debug) if ($ENV{CONDA_BUILD}x STREQUAL "1x" ) - set(CMAKE_LIBRARY_ARCHITECTURE $ENV{PREFIX}) - set(CMAKE_PREFIX_PATH $ENV{PREFIX}) - set( R_COMMAND "$ENV{R}") - set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS CONDA_BUILD=1) - list (APPEND CMAKE_REQUIRED_INCLUDES - ${PREFIX}/include - ${SYS_PREFIX}/include + set(CMAKE_LIBRARY_ARCHITECTURE $ENV{PREFIX}) + set(CMAKE_PREFIX_PATH $ENV{PREFIX}) + set( R_COMMAND "$ENV{R}") + set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS CONDA_BUILD=1) + list (APPEND CMAKE_REQUIRED_INCLUDES + ${PREFIX}/include + ${SYS_PREFIX}/include ) -set(YAP_IS_MOVABLE 1) + set(YAP_IS_MOVABLE 1) endif() @@ -228,56 +283,54 @@ ADD_CUSTOM_TARGET(run_install COMMAND ${CMAKE_MAKE_PROGRAM} install) if (APPLE) set(MACOSX_RPATH ON) - if (NOT $ENV{CONDA_BUILD}x STREQUAL "1x") + if (NOT $ENV{CONDA_BUILD}x STREQUAL "1x") - set(PATH $ENV{PATH}) + set(PATH $ENV{PATH}) - option(WITH_BREW "brew" ON) - if (WITH_MACPORTS) -# Add MacPorts -# Detect if the "port" command is valid on this system; if so, return full path -EXECUTE_PROCESS(COMMAND which port RESULT_VARIABLE DETECT_MACPORTS OUTPUT_VARIABLE MACPORTS_PREFIX ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) + if (WITH_MACPORTS) + # Add MacPorts + # Detect if the "port" command is valid on this system; if so, return full path + EXECUTE_PROCESS(COMMAND which port RESULT_VARIABLE DETECT_MACPORTS OUTPUT_VARIABLE MACPORTS_PREFIX ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) -IF (${DETECT_MACPORTS} EQUAL 0) - # "/opt/local/bin/port" doesn't have libs, so we get the parent directory - GET_FILENAME_COMPONENT(MACPORTS_PREFIX ${MACPORTS_PREFIX} DIRECTORY) + IF (${DETECT_MACPORTS} EQUAL 0) + # "/opt/local/bin/port" doesn't have libs, so we get the parent directory + GET_FILENAME_COMPONENT(MACPORTS_PREFIX ${MACPORTS_PREFIX} DIRECTORY) - # "/opt/local/bin" doesn't have libs, so we get the parent directory - GET_FILENAME_COMPONENT(MACPORTS_PREFIX ${MACPORTS_PREFIX} DIRECTORY) + # "/opt/local/bin" doesn't have libs, so we get the parent directory + GET_FILENAME_COMPONENT(MACPORTS_PREFIX ${MACPORTS_PREFIX} DIRECTORY) - # "/opt/local" is where MacPorts lives, add `/lib` suffix and link - LINK_DIRECTORIES(${LINK DIRECTORIES} ${MACPORTS_PREFIX}/lib) + # "/opt/local" is where MacPorts lives, add `/lib` suffix and link + LINK_DIRECTORIES(${LINK DIRECTORIES} ${MACPORTS_PREFIX}/lib) - MESSAGE("WINNING!: ${MACPORTS_PREFIX}/lib") -ENDIF() -ENDIF() + MESSAGE("WINNING!: ${MACPORTS_PREFIX}/lib") + ENDIF() + ENDIF() - option(WITH_BREW "brew" ON) if (WITH_BREW) -EXECUTE_PROCESS(COMMAND brew --prefix RESULT_VARIABLE DETECT_BREW OUTPUT_VARIABLE BREW_PREFIX ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) + EXECUTE_PROCESS(COMMAND brew --prefix RESULT_VARIABLE DETECT_BREW OUTPUT_VARIABLE BREW_PREFIX ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) -IF (${DETECT_BREW} EQUAL 0) + IF (${DETECT_BREW} EQUAL 0) - # "/opt/local" is where MacPorts lives, add `/lib` suffix and link - LINK_DIRECTORIES( ${BREW_PREFIX}/lib) + # "/opt/local" is where MacPorts lives, add `/lib` suffix and link + LINK_DIRECTORIES( ${BREW_PREFIX}/lib) - MESSAGE("BREW!: ${BREW_PREFIX}/lib") -ENDIF() + MESSAGE("BREW!: ${BREW_PREFIX}/lib") + ENDIF() - list(INSERT CMAKE_PREFIX_PATH pos - ${BREW_PREFIX}/opt/gmp - ${BREW_PREFIX}/opt/libxml2 - ${BREW_PREFIX}/opt/openmpi - ${BREW_PREFIX}/opt/openssl - ${BREW_PREFIX}/opt/postgresql - ${BREW_PREFIX}/opt/python3 - ${BREW_PREFIX}/opt/readline - ${BREW_PREFIX}/opt/swig - ) - endif () - endif() + list(INSERT CMAKE_PREFIX_PATH pos + ${BREW_PREFIX}/opt/gmp + ${BREW_PREFIX}/opt/libxml2 + ${BREW_PREFIX}/opt/openmpi + ${BREW_PREFIX}/opt/openssl + ${BREW_PREFIX}/opt/postgresql + ${BREW_PREFIX}/opt/python3 + ${BREW_PREFIX}/opt/readline + ${BREW_PREFIX}/opt/swig + ) + endif () + endif() endif () @@ -288,7 +341,7 @@ set(libdir ${CMAKE_INSTALL_PREFIX}/lib) #LIBDIR}) set(exec_prefix ${CMAKE_INSTALL_PREFIX}/libexec) #LIBEXECDIR}) set(datarootdir ${CMAKE_INSTALL_PREFIX}/share) #DATAROOTDIR}) if (ANDROID) - set(datarootdir ${YAP_APP_DIR}/src/generated/assets) + set(datarootdir ${YAP_APP_DIR}/src/generated/assets) endif () set(datadir ${CMAKE_INSTALL_PREFIX}/share) #DATADIR}) set(mandir ${CMAKE_INSTALL_PREFIX}/share/man) #MANDIR}) @@ -336,31 +389,30 @@ list(APPEND YAP_SYSTEM_OPTIONS big_numbers) if (GMP_FOUND) - #config.h needs this (TODO: change in code latter) - include_directories(${GMP_INCLUDE_DIRS}) - check_include_file(gmp.h HAVE_GMP_H) - check_include_file_cxx(gmpxx.h HAVE_GMPXX_H) + #config.h needs this (TODO: change in code latter) + include_directories(${GMP_INCLUDE_DIRS}) + check_include_file(gmp.h HAVE_GMP_H) + check_include_file_cxx(gmpxx.h HAVE_GMPXX_H) endif (GMP_FOUND) - option(WITH_READLINE "use readline or libedit" ON) if (WITH_READLINE) -include(FindReadline) + include(FindReadline) -List(APPEND YAP_SYSTEM_OPTIONS readline) -# include subdirectories configuration -## after we have all functionality in -# -# ADD_SUBDIRECTORY(console/terminal) + List(APPEND YAP_SYSTEM_OPTIONS readline) + # include subdirectories configuration + ## after we have all functionality in + # + # ADD_SUBDIRECTORY(console/terminal) -if (READLINE_FOUND) + if (READLINE_FOUND) include_directories(${READLINE_INCLUDE_DIR}) # required for configure list(APPEND CMAKE_REQUIRED_LIBRARIES ${READLINE_LIBRARIES}) list(APPEND CMAKE_REQUIRED_INCLUDES ${READLINE_INCLUDE_DIR}) -endif () + endif () endif() #MPI STUFF @@ -382,27 +434,27 @@ set(YAP_MINOR_VERSION 4) set(YAP_PATCH_VERSION 1) set(YAP_FULL_VERSION - ${YAP_MAJOR_VERSION}.${YAP_MINOR_VERSION}.${YAP_PATCH_VERSION}) + ${YAP_MAJOR_VERSION}.${YAP_MINOR_VERSION}.${YAP_PATCH_VERSION}) set(YAP_FVERSION - ${YAP_MAJOR_VERSION}.${YAP_MINOR_VERSION}.${YAP_PATCH_VERSION}) + ${YAP_MAJOR_VERSION}.${YAP_MINOR_VERSION}.${YAP_PATCH_VERSION}) set(YAP_NUMERIC_VERSION - ${YAP_MAJOR_VERSION}*10000+${YAP_MINOR_VERSION}*100+${YAP_PATCH_VERSION}) + ${YAP_MAJOR_VERSION}*10000+${YAP_MINOR_VERSION}*100+${YAP_PATCH_VERSION}) set(MYDDAS_VERSION MYDDAS-0.9.1) site_name(YAP_SITE) if (WIN32) - set(YAP_ARCH $ENV{PROCESSOR_ARCHITECTURE}) - set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS "MS_WIN64=1") - set(YAP_SYSTEM_OPTIONS "windows " ${YAP_SYSTEM_OPTIONS}) + set(YAP_ARCH $ENV{PROCESSOR_ARCHITECTURE}) + set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS "MS_WIN64=1") + set(YAP_SYSTEM_OPTIONS "windows " ${YAP_SYSTEM_OPTIONS}) endif () if (UNIX) - find_program(UNAME uname) - execute_process( - COMMAND ${UNAME} -m - OUTPUT_VARIABLE YAP_ARCH OUTPUT_STRIP_TRAILING_WHITESPACE) - set(YAP_SYSTEM_OPTIONS "unix " ${YAP_SYSTEM_OPTIONS}) + find_program(UNAME uname) + execute_process( + COMMAND ${UNAME} -m + OUTPUT_VARIABLE YAP_ARCH OUTPUT_STRIP_TRAILING_WHITESPACE) + set(YAP_SYSTEM_OPTIONS "unix " ${YAP_SYSTEM_OPTIONS}) endif () @@ -440,16 +492,16 @@ set(MSHIFTOFFS 1) set(C_COMPILER CMAKE_C_COMPILER_ID) if (${C_COMPILER} MATCHES "GNU") - set(HAVE_GCC 1) + set(HAVE_GCC 1) endif () # compatible compilers if (${C_COMPILER} MATCHES "Clang") - set(HAVE_GCC 1) + set(HAVE_GCC 1) endif () if (${C_COMPILER} MATCHES "Intel") - set(HAVE_GCC 1) + set(HAVE_GCC 1) endif () # rpath stuff, hopefully it works @@ -475,46 +527,43 @@ endif () #ENDIF("${isSystemDir}" STREQUAL "-1") # IF(NOT WIN32 AND NOT APPLE) -LIST(APPEND CMAKE_INSTALL_RPATH \\$ORIGIN/../lib/Yap) -LIST(APPEND CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_FULL_LIBDIR}) -LIST(APPEND CMAKE_INSTALL_RPATH \\$ORIGIN/../lib) -LIST(APPEND CMAKE_INSTALL_RPATH \\$ORIGIN/../../../lib) + LIST(APPEND CMAKE_INSTALL_RPATH \\$ORIGIN/../lib/Yap) + LIST(APPEND CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_FULL_LIBDIR}) + LIST(APPEND CMAKE_INSTALL_RPATH \\$ORIGIN/../lib) + LIST(APPEND CMAKE_INSTALL_RPATH \\$ORIGIN/../../../lib) ELSE() - LIST(APPEND CMAKE_INSTALL_RPATH @loader_path/../lib/Yap) - LIST(APPEND CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_FULL_LIBDIR}) - LIST(APPEND CMAKE_INSTALL_RPATH @loader_path/../lib) - LIST(APPEND CMAKE_INSTALL_RPATH @loader_path/../../../lib) + LIST(APPEND CMAKE_INSTALL_RPATH @loader_path/../lib/Yap) + LIST(APPEND CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_FULL_LIBDIR}) + LIST(APPEND CMAKE_INSTALL_RPATH @loader_path/../lib) + LIST(APPEND CMAKE_INSTALL_RPATH @loader_path/../../../lib) ENDIF() # Model Specific if (HAVE_GCC) - set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS -Wall) - if (${C_COMPILER} MATCHES "GNU") - set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS $<$:-O3;-fomit-frame-pointer;-fstrict-aliasing;-freorder-blocks;-fsched-interblock>) - else () - set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS $<$:-O3;-fstrict-aliasing;-freorder-blocks;-fsched-interblock>) - endif () - set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS -fexceptions) + set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS -Wall) + if (${C_COMPILER} MATCHES "GNU") + set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS $<$:-O3;-fomit-frame-pointer;-fstrict-aliasing;-freorder-blocks;-fsched-interblock>) + else () + set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS $<$:-O3;-fstrict-aliasing;-freorder-blocks;-fsched-interblock>) + endif () + set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS -fexceptions) endif () # set_property( DIRECTORY APPEND_STRING PROPERTY -fsanitize=memory;-fsanitize-memory-track-origins=2) if (HAVE_GCC) - # replace instructions codes by the address of their code - option(WITH_THREADED_CODE "threaded code" ON) - if (WITH_THREADED_CODE) - set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS THREADED_CODE=1) - endif (WITH_THREADED_CODE) + # replace instructions codes by the address of their code + if (WITH_THREADED_CODE) + set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS THREADED_CODE=1) + endif (WITH_THREADED_CODE) endif (HAVE_GCC) # #option (YAP_SWI_IO ON) -OPTION(WITH_CALL_TRACER - "support for procedure-call tracing" ON) #TODO: if (WITH_CALL_TRACER) - list(APPEND YAP_SYSTEM_OPTIONS "call_tracer " ${YAP_SYSTEM_OPTIONS}) - set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS $<$:LOW_LEVEL_TRACER=1>) + list(APPEND YAP_SYSTEM_OPTIONS "call_tracer " ${YAP_SYSTEM_OPTIONS}) + set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS $<$:LOW_LEVEL_TRACER=1>) endif (WITH_CALL_TRACER) set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS UTF8PROC=1) @@ -523,47 +572,45 @@ include_directories(utf8proc packages/myddas packages/myddas/sqlite3/src ) set_property(SOURCE ${LIBYAP_SOURCES} APPEND PROPERTY COMPILE_DEFINITIONS YAP_KERNEL=1) -add_definitions(-DUSE_MYDDAS=1 -DMYDDAS_SQLITE3=1) -if (ANDROID) - else() +IF (WITH_MYDDAS) + if (ANDROID) + else() -if (MYSQL_FOUND) - add_definitions(= -DMYDDAS_MYSQL=1) -endif () + add_definitions(-DUSE_MYDDAS=1 -DMYDDAS_SQLITE3=1) -if (ODBC_FOUND) - add_definitions(= -DMYDDAS_ODBC=1) -endif () + if (MYSQL_FOUND) + add_definitions(= -DMYDDAS_MYSQL=1) + endif () -if (MYSQL_POSTGRES) - add_definitions(= -DMYDDAS_POSTGRES=1) -endif () -endif() + if (ODBC_FOUND) + add_definitions(= -DMYDDAS_ODBC=1) + endif () + + if (MYSQL_POSTGRES) + add_definitions(= -DMYDDAS_POSTGRES=1) + endif () + endif(ANDROID) +endif(WITH_MYDDAS) -OPTION(WITH_SWIG " Enable SWIG interfaces to foreign languages" ON) IF (WITH_SWIG) - find_host_package(SWIG) - # macro_log_feature (SWIG_FOUND "Swig" - # "Use SWIG Interface Generator " - # "http://www.swig.org" ON) + find_host_package(SWIG) + # macro_log_feature (SWIG_FOUND "Swig" + # "Use SWIG Interface Generator " + # "http://www.swig.org" ON) ENDIF (WITH_SWIG) -option(WITH_PYTHON - "Allow Python->YAP and YAP->Python" ON) IF (WITH_PYTHON) - include(python ) + include(python ) ENDIF (WITH_PYTHON) -option(WITH_R - "Use R Interface" ON) IF (WITH_R) - find_host_package(LibR) -add_subDIRECTORY(packages/real) + find_host_package(LibR) + add_subDIRECTORY(packages/real) ENDIF (WITH_R) @@ -573,47 +620,47 @@ List(APPEND YLIBS $) List(APPEND YLIBS $) List(APPEND YLIBS $) if (WIN32 OR ANDROID) - List(APPEND YLIBS $) - if (WIN32 AND WITH_PYTHON) - List(APPEND YLIBS $) - endif () - if (ANDROID) - List(APPEND YLIBS $) - List(APPEND YLIBS $) + List(APPEND YLIBS $) + if (WIN32 AND WITH_PYTHON) + List(APPEND YLIBS $) + endif () + if (ANDROID) + List(APPEND YLIBS $) + List(APPEND YLIBS $) + endif () endif () - endif () include(Sources) add_corelib( # Sets the name of the library. - libYap + libYap - # Sets the library as a shared library. - SHARED + # Sets the library as a shared library. + SHARED - ${ENGINE_SOURCES} - ${C_INTERFACE_SOURCES} - //${STATIC_SOURCES} - # cmake object libraries - ${YLIBS} - ) + ${ENGINE_SOURCES} + ${C_INTERFACE_SOURCES} + //${STATIC_SOURCES} + # cmake object libraries + ${YLIBS} + ) if (GMP_FOUND) - target_link_libraries(libYap ${GMP_LIBRARIES}) + target_link_libraries(libYap ${GMP_LIBRARIES}) endif (GMP_FOUND) if (READLINE_FOUND) - target_link_libraries(libYap ${READLINE_LIBRARIES}) - # required for configure + target_link_libraries(libYap ${READLINE_LIBRARIES}) + # required for configure endif () if (WIN32) - target_link_libraries(libYap ${WINDLLS}) - if (WITH_PYTHON AND PYTHON_INCLUDE_DIRS AND PYTHON_LIBRARIES) - target_link_libraries(libYap ${PYTHON_LIBRARIES}) - endif () + target_link_libraries(libYap ${WINDLLS}) + if (WITH_PYTHON AND PYTHON_INCLUDE_DIRS AND PYTHON_LIBRARIES) + target_link_libraries(libYap ${PYTHON_LIBRARIES}) + endif () endif (WIN32) target_link_libraries(libYap m) @@ -640,12 +687,12 @@ set_property(DIRECTORY PROPERTY CXX_STANDARD 11) include_directories(H - H/generated - include os OPTYap utf8proc JIT/HPP) + H/generated + include os OPTYap utf8proc JIT/HPP) include_directories(BEFORE ${CMAKE_BINARY_DIR} ${CMAKE_TOP_BINARY_DIR}) if (ANDROID) - include_directories(CXX ${CMAKE_SOURCE_DIR}/../generated/src/jni) + include_directories(CXX ${CMAKE_SOURCE_DIR}/../generated/src/jni) endif () include(Threads) # @@ -657,12 +704,12 @@ include(Threads) list(APPEND YAP_SYSTEM_OPTIONS "thread support") set_target_properties(libYap - PROPERTIES OUTPUT_NAME Yap - ) + PROPERTIES OUTPUT_NAME Yap + ) MY_set_target_properties(libYap - PROPERTIES VERSION ${YAP_FULL_VERSION} - SOVERSION ${YAP_MAJOR_VERSION}.${YAP_MINOR_VERSION} - ) + PROPERTIES VERSION ${YAP_FULL_VERSION} + SOVERSION ${YAP_MAJOR_VERSION}.${YAP_MINOR_VERSION} + ) #utf-8 is not aPconn option @@ -687,40 +734,40 @@ ADD_SUBDIRECTORY(library) ADD_SUBDIRECTORY(swi/library "swiLibrary") set_target_properties(libYap - PROPERTIES OUTPUT_NAME Yap - ) + PROPERTIES OUTPUT_NAME Yap + ) # file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/packages/python/swig/yap4py) if (WITH_PYTHON AND PYTHONLIBS_FOUND AND SWIG_FOUND) - set( ENV{PYTHONPATH} ${CMAKE_BINARY_DIR}/packages/python/swig:${CMAKE_BINARY_DIR}/packages/python/yap_kernel:. ) -add_subdirectory(packages/python/swig) + set( ENV{PYTHONPATH} ${CMAKE_BINARY_DIR}/packages/python/swig:${CMAKE_BINARY_DIR}/packages/python/yap_kernel:. ) + add_subdirectory(packages/python/swig) - include(FindPythonModule) + include(FindPythonModule) - find_python_module(jupyter) - find_python_module(wheel) - find_python_module(setuptools) - if (PY_JUPYTER AND PY_WHEEL AND PY_SETUPTOOLS) - add_subdirectory(packages/python/yap_kernel) - else() - message("will not compile yap_kernel, as jupyter=${PY_JUPYTER};wheel=${PY_WHEEL};setuptools=${PY_SETUPTOOLS}") - ENDIF () + find_python_module(jupyter) + find_python_module(wheel) + find_python_module(setuptools) + if (PY_JUPYTER AND PY_WHEEL AND PY_SETUPTOOLS) + add_subdirectory(packages/python/yap_kernel) + else() + message("will not compile yap_kernel, as jupyter=${PY_JUPYTER};wheel=${PY_WHEEL};setuptools=${PY_SETUPTOOLS}") + ENDIF () endif () IF ( ANDROID) - set(CMAKE_SWIG_OUTDIR ${YAP_APP_DIR}/src/generated/java/pt/up/yap/lib ) - set(CMAKE_SWIG_OUTPUT ${YAP_APP_DIR}/src/generated/jni ) - set( SWIG_MODULE_NAME pt.up.yap.lib ) + set(CMAKE_SWIG_OUTDIR ${YAP_APP_DIR}/src/generated/java/pt/up/yap/lib ) + set(CMAKE_SWIG_OUTPUT ${YAP_APP_DIR}/src/generated/jni ) + set( SWIG_MODULE_NAME pt.up.yap.lib ) add_subDIRECTORY(packages/swig ) - target_link_libraries(libYap ${CMAKE_SOURCE_DIR}/../sqlite-android/jni/${ANDROID_ABI}/libsqliteX.so android log ) + target_link_libraries(libYap ${CMAKE_SOURCE_DIR}/../sqlite-android/jni/${ANDROID_ABI}/libsqliteX.so android log ) ENDIF () @@ -729,145 +776,150 @@ message(STATUS "Building YAP packages version ${YAP_VERSION}") if (NOT WIN32) - set(BUILD_SHARED_LIBS ON) + set(BUILD_SHARED_LIBS ON) endif () -option(WITH_JIT - "just in Time Clause Compilation" OFF) if (WITH_JIT) - add_subDIRECTORY(JIT) + add_subDIRECTORY(JIT) endif (WITH_JIT) -add_subDIRECTORY(packages/raptor) -add_subDIRECTORY(packages/xml) +if (WITH_XML2 OR WITH_RAPTOR) + + add_subDIRECTORY(packages/raptor) + +endif() -OPTION(WITH_CLPBN " Enable the CLPBN and PFL probabilistic languages" ON) +if (WITH_XML) -OPTION(WITH_CPLINT " Enable the cplint probabilistic language" ON) + add_subDIRECTORY(packages/xml) -OPTION(WITH_HORUS " Enable the CLPBN and PFL probabilistic languages" ON) +endif () -find_host_package(Doxygen) - -option(WITH_DOCS "Create and install the HTML based API documentation (requires Doxygen)" ${DOXYGEN_FOUND}) IF (WITH_CLPBN) - add_subDIRECTORY(packages/CLPBN) + add_subDIRECTORY(packages/CLPBN) ENDIF (WITH_CLPBN) IF (WITH_CPLINT) - add_subDIRECTORY(packages/cplint) + add_subDIRECTORY(packages/cplint) ENDIF (WITH_CPLINT) -# please install doxygen for prolog first -# git clone http://www.github.com/vscosta/doxygen-yap -# cd doxygen-yap -# mkdir -p build -# cd build -# make; sudo make install -option(WITH_DOCS - "generate YAP docs" OFF) IF (WITH_DOCS) -get_target_property(YAP_SOURCES libYap SOURCES) + get_target_property(YAP_SOURCES libYap SOURCES) + + add_subDIRECTORY(docs) + + + find_host_package(Doxygen) - add_subDIRECTORY(docs) ENDIF (WITH_DOCS) # add_subDIRECTORY (packages/cuda) -option(WITH_GECODE - "interface gecode constraint solver" ON) if (WITH_GECODE) - add_subDIRECTORY(packages/gecode) + add_subDIRECTORY(packages/gecode) endif () -option(WITH_LBFGS - "interface with lbfgs" ON) - if (WITH_LBFGS) - add_subDIRECTORY(packages/yap-lbfgs) + add_subDIRECTORY(packages/yap-lbfgs) endif () -option(WITH_JAVA "Try to use Java (currently Java 6,7,8)" ON) if (WITH_JAVA) -#detect java setup, as it is shared between different installations. + #detect java setup, as it is shared between different installations. -find_package(Java COMPONENTS Runtime Development) -# find_package(Java COMPONENTS Development) -# find_package(Java COMPONENTS Runtime) -#find_package(JavaLibs) + find_package(Java COMPONENTS Runtime Development) + # find_package(Java COMPONENTS Development) + # find_package(Java COMPONENTS Runtime) + #find_package(JavaLibs) -if (Java_Development_FOUND) + if (Java_Development_FOUND) set (STD_CMAKE_FIND_FRAMEWORK ${CMAKE_FIND_FRAMEWORK}) - set (CMAKE_FIND_FRAMEWORK LAST) # CMake will find the Java returned by /usr/libexec/java_home. - - macro_optional_find_package(JNI ON) - + set (CMAKE_FIND_FRAMEWORK LAST) # CMake will find the Java returned by /usr/libexec/java_home. + + macro_optional_find_package(JNI ON) + - set (CMAKE_FIND_FRAMEWORK ${STD_CMAKE_FIND_FRAMEWORK}) + set (CMAKE_FIND_FRAMEWORK ${STD_CMAKE_FIND_FRAMEWORK}) - if (JNI_FOUND) + if (JNI_FOUND) -get_filename_component(JAVA_HOME ${JAVA_INCLUDE_PATH} DIRECTORY) + get_filename_component(JAVA_HOME ${JAVA_INCLUDE_PATH} DIRECTORY) - include(UseJava) + include(UseJava) - # - # Java_JAVA_EXECUTABLE = the full path to the Java runtime - # Java_JAVAC_EXECUTABLE = the full path to the Java compiler - # Java_JAVAH_EXECUTABLE = the full path to the Java header generator - # Java_JAVADOC_EXECUTABLE = the full path to the Java documention generator - # Java_IDLJ_EXECUTABLE = the full path to the Java idl compiler - # Java_JAR_EXECUTABLE = the full path to the Java archiver - # Java_JARSIGNER_EXECUTABLE = the full path to the Java jar signer - # Java_VERSION_STRING = Version of java found, eg. 1.6.0_12 - # Java_VERSION_MAJOR = The major version of the package found. - # Java_VERSION_MINOR = The minor version of the package found. - # Java_VERSION_PATCH = The patch version of the package found. - # Java_VERSION_TWEAK = The tweak version of the package found (after '_') - # Java_VERSION = This is set to: $major.$minor.$patch(.$tweak) - # - # The Java_ADDITIONAL_VERSIONS variable can be used to specify a list - # of version numbers that should be taken into account when searching - # for Java. You need to set this variable before calling + # + # Java_JAVA_EXECUTABLE = the full path to the Java runtime + # Java_JAVAC_EXECUTABLE = the full path to the Java compiler + # Java_JAVAH_EXECUTABLE = the full path to the Java header generator + # Java_JAVADOC_EXECUTABLE = the full path to the Java documention generator + # Java_IDLJ_EXECUTABLE = the full path to the Java idl compiler + # Java_JAR_EXECUTABLE = the full path to the Java archiver + # Java_JARSIGNER_EXECUTABLE = the full path to the Java jar signer + # Java_VERSION_STRING = Version of java found, eg. 1.6.0_12 + # Java_VERSION_MAJOR = The major version of the package found. + # Java_VERSION_MINOR = The minor version of the package found. + # Java_VERSION_PATCH = The patch version of the package found. + # Java_VERSION_TWEAK = The tweak version of the package found (after '_') + # Java_VERSION = This is set to: $major.$minor.$patch(.$tweak) + # + # The Java_ADDITIONAL_VERSIONS variable can be used to specify a list + # of version numbers that should be taken into account when searching + # for Java. You need to set this variable before calling - # - #macro_optional_find_package(JNI ON) - # JNI_INCLUDE_DIRS = the include dirs to use - # JNI_LIBRARIES = the libraries to use - # JNI_FOUND = TRUE if JNI headers and libraries were found. - # JAVA_AWT_LIBRARY = the path to the jawt library - # JAVA_JVM_LIBRARY = the path to the jvm library - # JAVA_INCLUDE_PATH = the include path to jni.h - # JAVA_INCLUDE_PATH2 = the include path to jni_md.h - # JAVA_AWT_INCLUDE_PATH = the include path to jawt.h + # + #macro_optional_find_package(JNI ON) + # JNI_INCLUDE_DIRS = the include dirs to use + # JNI_LIBRARIES = the libraries to use + # JNI_FOUND = TRUE if JNI headers and libraries were found. + # JAVA_AWT_LIBRARY = the path to the jawt library + # JAVA_JVM_LIBRARY = the path to the jvm library + # JAVA_INCLUDE_PATH = the include path to jni.h + # JAVA_INCLUDE_PATH2 = the include path to jni_md.h + # JAVA_AWT_INCLUDE_PATH = the include path to jawt.h -endif (JNI_FOUND) + endif (JNI_FOUND) -endif (Java_Development_FOUND) + endif (Java_Development_FOUND) + + add_subDIRECTORY(packages/jpl) + endif(WITH_JAVA) -add_subDIRECTORY(packages/jpl) +if (WITH_CUDD) -add_subDIRECTORY(packages/bdd) + add_subDIRECTORY(packages/bdd) -add_subDIRECTORY(packages/ProbLog) +endif() -add_subDIRECTORY(packages/swi-minisat2) +if (WITH_PROBLOG) -add_subDIRECTORY(packages/clpqr) + add_subDIRECTORY(packages/ProbLog) + +endif() + +if (WITH_MINISAT) + + add_subDIRECTORY(packages/swi-minisat2) + +endif() + +if (WITH_CLPQR) + + add_subDIRECTORY(packages/clpqr) + +endif() #todo: use cmake target builds @@ -886,28 +938,9 @@ add_subDIRECTORY(packages/clpqr) # option (USE_CYGWIN # "use cygwin library in WIN32" OFF) -option(WITH_PRISM - "use PRISM system in YAP" ON) #TODO: -option(WITH_YAP_DLL - "compile YAP as a DLL" ON) -#TODO: - -option(WITH_YAP_STATIC - "compile YAP statically" OFF) -#TODO: - -option(WITH_YAP_CONDOR - "allow YAP to be used from condor" OFF) - -if (WITH_YAP_CONDOR) - # use default allocator - set(YAP_STATIC ON) - set(YAP_DLL OFF) -endif () - #TODO: detect arch before allow this option # OPTION(WIN64 # "compile YAP for win64" OFF) @@ -930,11 +963,11 @@ endif () if (WIN32) - if (MSVC) - set(MSVC_RUNTIME "dynamic") - ENDIF (MSVC) + if (MSVC) + set(MSVC_RUNTIME "dynamic") + ENDIF (MSVC) - target_link_libraries(libYap wsock32 ws2_32 shlwapi) + target_link_libraries(libYap wsock32 ws2_32 shlwapi) endif (WIN32) @@ -946,42 +979,34 @@ set_target_properties(yap-bin PROPERTIES OUTPUT_NAME yap) target_link_libraries(yap-bin libYap) install(TARGETS libYap yap-bin - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - ) + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + ) -CMAKE_DEPENDENT_OPTION(WITH_SYSTEM_MMAP "Use MMAP for shared memory allocation" ON - "NOT WITH_YAPOR_THOR" OFF) +if (WITH_MPI) -CMAKE_DEPENDENT_OPTION(WITH_SYSTEM_SHM "Use SHM for shared memory allocation" ON - "NOT WITH_YAPOR_THOR; NOT WITH_SYSTEM_MMAP" OFF) + add_subDIRECTORY(library/lammpi) -if (NOT ANDROID) + if (MPI_C_FOUND) -add_subDIRECTORY(library/lammpi) - -if (MPI_C_FOUND) - - CMAKE_DEPENDENT_OPTION(WITH_MPI ON "Interface to OpenMPI/MPICH" - "MPI_C_FOUND" OFF) macro_optional_add_subDIRECTORY(library/mpi) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${MPI_C_COMPILE_FLAGS} ") include_directories(${MPI_C_INCLUDE_PATH}) target_link_libraries(yap-bin ${MPI_C_LIBRARIES}) if (MPI_C_COMPILE_FLAGS) - set_target_properties(yap-bin PROPERTIES - COMPILE_FLAGS "${MPI_C_COMPILE_FLAGS}") + set_target_properties(yap-bin PROPERTIES + COMPILE_FLAGS "${MPI_C_COMPILE_FLAGS}") endif (MPI_C_COMPILE_FLAGS) if (MPI_C_LINK_FLAGS) - set_target_properties(yap-bin PROPERTIES - LINK_FLAGS "${MPI_C_LINK_FLAGS}") + set_target_properties(yap-bin PROPERTIES + LINK_FLAGS "${MPI_C_LINK_FLAGS}") endif () -endif (MPI_C_FOUND) + endif (MPI_C_FOUND) -endif(NOT ANDROID) +endif(WITH_MPI) ## add_subDIRECTORY(utils) @@ -993,7 +1018,7 @@ install(FILES ${INCLUDE_HEADERS} ${CONFIGURATION_HEADERS} DESTINATION ${included macro_display_feature_log() if (POLICY CMP0058) - cmake_policy(SET CMP0058 NEW) + cmake_policy(SET CMP0058 NEW) endif (POLICY CMP0058) include(Config ) @@ -1001,7 +1026,7 @@ include(Config ) feature_summary(DESCRIPTION "Packages found:" WHAT PACKAGES_FOUND - ) + ) feature_summary(DESCRIPTION "Packages not found:" WHAT PACKAGES_NOT_FOUND - ) + ) diff --git a/configure b/configure index 5962f82d6..64511cd43 100755 --- a/configure +++ b/configure @@ -165,7 +165,7 @@ print_help() { --mandir=DIR man documentation [DATAROOTDIR/man] --docdir=DIR documentation root [DATAROOTDIR/doc/PROJECT_NAME] - --generator=Generator Specify the tool used to send callss + --generator=GENERATOR Specify the tool used to send callss EOF first=y @@ -220,6 +220,8 @@ EOF exit 0 } + + while [ $# != 0 ]; do case "$1" in "--cmake="*) @@ -291,10 +293,10 @@ while [ $# != 0 ]; do "--docdir") CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_DOCDIR=$(quote "$2")"; shift;; - "-G="|"--generator="*) - CMAKE_ARGS+="-G"${1#*=};; - "-G"|"--generator") - CMAKE_ARGS+="-G$"$2; shift;; + "--generator="*) + CMAKE_ARGS="$CMAKE_ARGS -G ${1#*=}";; + "-G") + CMAKE_ARGS="$CMAKE_ARGS -G $2"; shift;; "CC="*) CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_C_COMPILER=$(quote "${1#*=}")";; diff --git a/os/sysbits.c b/os/sysbits.c index 1c326e769..a211b7ed6 100644 --- a/os/sysbits.c +++ b/os/sysbits.c @@ -769,11 +769,11 @@ static Int real_path(USES_REGS1) { int lvl = push_text_stack(); rc0 = myrealpath(cmd PASS_REGS); if (!rc0) { + pop_text_stack(lvl); PlIOError(SYSTEM_ERROR_OPERATING_SYSTEM, ARG1, NULL); } bool out = Yap_unify(MkAtomTerm(Yap_LookupAtom(rc0)), ARG2); - pop_output_text_stack(lvl, rc0); - + pop_text_stack(lvl); return out; } diff --git a/packages/ProbLog/problog_lbdd.yap b/packages/ProbLog/problog_lbdd.yap index 6663cfbf9..0a3f5a9d2 100644 --- a/packages/ProbLog/problog_lbdd.yap +++ b/packages/ProbLog/problog_lbdd.yap @@ -24,6 +24,7 @@ problog_low_lbdd(_, _, Prob, ok, bdd(Dir, Tree, MapList)) :- bind_maplist(MapList, BoundVars), bdd_tree(BDD, bdd(Dir, Tree, _Vars)), bdd_to_probability_sum_product(BDD, BoundVars, Prob), + bdd_close(BDD), (problog_flag(verbose, true)-> problog_statistics ; @@ -37,7 +38,8 @@ problog_low_lbdd(_, _, Prob, ok, bdd(Dir, Tree, MapList)) :- problog_kbest_bdd(Goal, K, Prob, ok) :- problog_kbest_to_bdd(Goal, K, BDD, MapList), bind_maplist(MapList, BoundVars), - bdd_to_probability_sum_product(BDD, BoundVars, Prob). + bdd_to_probability_sum_product(BDD, BoundVars, Prob), +bdd_close(BDD). problog_kbest_as_bdd(Goal, K, bdd(Dir, Tree, MapList)) :- problog_kbest_to_bdd(Goal, K, BDD, MapList), @@ -70,6 +72,7 @@ problog_fl_bdd(_,Prob) :- bind_maplist(MapList, BoundVars), bdd_to_probability_sum_product(BDD, BoundVars, Prob), (problog_flag(retain_tables, true) -> retain_tabling; true), + bdd_close(BDD), clear_tabling. problog_full_bdd(Goal,_K, _) :- @@ -86,6 +89,7 @@ problog_full_bdd(_,Prob) :- tabled_trie_to_bdd(Trie_Completed_Proofs, BDD, MapList), bind_maplist(MapList, BoundVars), bdd_to_probability_sum_product(BDD, BoundVars, Prob), + bdd_close(BDD), (problog_flag(retain_tables, true) -> retain_tabling; true), clear_tabling. diff --git a/packages/ProbLog/problog_lbfgs.yap b/packages/ProbLog/problog_lbfgs.yap index 4a0ae9057..9b0d6b8f9 100644 --- a/packages/ProbLog/problog_lbfgs.yap +++ b/packages/ProbLog/problog_lbfgs.yap @@ -431,7 +431,7 @@ do_learning_intern(Iterations,Epsilon) :- true ), -% update_values, + update_values, ( last_mse(Last_MSE) @@ -450,15 +450,11 @@ do_learning_intern(Iterations,Epsilon) :- ), ( - (problog_flag(rebuild_bdds,BDDFreq),BDDFreq>0,0 =:= CurrentIteration mod BDDFreq) - -> - ( retractall(values_correct), retractall(query_is_similar(_,_)), retractall(query_md5(_,_,_)), empty_bdd_directory, init_queries - ); true ), @@ -491,10 +487,47 @@ init_learning :- init_learning :- check_examples, + retractall(current_iteration(_)), + assert(current_iteration(0)), % empty_output_directory, logger_write_header, - format_learning(1,'Initializing everything~n',[]), + + succeeds_n_times(user:test_example(_,_,_,_),TestExampleCount), + format_learning(3,'~q test examples~n',[TestExampleCount]), + + succeeds_n_times(user:example(_,_,_,_),TrainingExampleCount), + assertz(example_count(TrainingExampleCount)), + format_learning(3,'~q training examples~n',[TrainingExampleCount]), + + + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + % build BDD script for every example + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + once(init_queries), + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + % done + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + assertz(current_iteration(-1)), + assertz(learning_initialized), + + format_learning(1,'~n',[]). + +%======================================================================== +%= Updates all values of query_probability/2 and query_gradient/4 +%= should be called always before these predicates are accessed +%= if the old values are still valid, nothing happens +%======================================================================== + +update_values :- + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + % delete old values + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + retractall(query_probability_intern(_,_)), + retractall(query_gradient_intern(_,_,_,_)). + @@ -502,8 +535,8 @@ init_learning :- % Check, if continuous facts are used. % if yes, switch to problog_exact % continuous facts are not supported yet. - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - set_default_gradient_method, + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +set_default_gradient_method :- ( problog_flag(continuous_facts, true ) -> problog_flag(init_method,(_,_,_,_,OldCall)), @@ -527,31 +560,11 @@ init_learning :- set_problog_flag(init_method,(Query,Probability,BDDFile,ProbFile,problog_exact_save(Query,Probability,_Status,BDDFile,ProbFile))) ); true - ), - - succeeds_n_times(user:test_example(_,_,_,_),TestExampleCount), - format_learning(3,'~q test examples~n',[TestExampleCount]), - - succeeds_n_times(user:example(_,_,_,_),TrainingExampleCount), - assertz(example_count(TrainingExampleCount)), - format_learning(3,'~q training examples~n',[TrainingExampleCount]), + ). + - - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - % build BDD script for every example - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - once(init_queries), - - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - % done - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - assertz(current_iteration(0)), - assertz(learning_initialized), - - format_learning(1,'~n',[]). - - empty_bdd_directory :- +empty_bdd_directory :- current_key(_,I), integer(I), recorded(I,bdd(_,_,_),R), @@ -560,21 +573,6 @@ init_learning :- empty_bdd_directory. -set_default_gradient_method :- - problog_flag(continuous_facts, true), - !, - % problog_flag(init_method,OldMethod), - format_learning(2,'Theory uses continuous facts.~nWill use problog_exact/3 as initalization method.~2n',[]), - set_problog_flag(init_method,(Query,Probability,BDDFile,ProbFile,problog_exact_save(Query,Probability,_Status,BDDFile,ProbFile))). -set_default_gradient_method :- - problog_tabled(_), problog_flag(fast_proofs,false), - !, - format_learning(2,'Theory uses tabling.~nWill use problog_exact/3 as initalization method.~2n',[]), - set_problog_flag(init_method,(Query,Probability,BDDFile,ProbFile,problog_exact_save(Query,Probability,_Status,BDDFile,ProbFile))). -%set_default_gradient_method :- -% problog_flag(init_method,(gene(X,Y),N,Bdd,graph2bdd(X,Y,N,Bdd))), -% !. -set_default_gradient_method. %======================================================================== %= This predicate goes over all training and test examples, @@ -584,6 +582,7 @@ set_default_gradient_method. init_queries :- + empty_bdd_directory, format_learning(2,'Build BDDs for examples~n',[]), forall(user:test_example(ID,Query,_Prob,_),init_one_query(ID,Query,test)), forall(user:example(ID,Query,_Prob,_),init_one_query(ID,Query,training)). @@ -703,28 +702,56 @@ ground_truth_difference :- %= -Float %======================================================================== -mse_trainingset_only_for_linesearch(MSE, FX) :- +mse_trainingset :- + current_iteration(Iteration), + create_training_predictions_file_name(Iteration,File_Name), + open(File_Name, write,Handle), + format_learning(2,'MSE_Training ',[]), update_values, + findall(t(LogCurrentProb,SquaredError), + (user:training_example(QueryID,Query,TrueQueryProb,_Type), + once(update_query(QueryID,'+',probability)), + query_probability(QueryID,CurrentProb), + format(Handle,'ex(~q,training,~q,~q,~10f,~10f).~n',[Iteration,QueryID,Query,TrueQueryProb,CurrentProb]), - example_count(Example_Count), + once(update_query_cleanup(QueryID)), + SquaredError is (CurrentProb-TrueQueryProb)**2, + LogCurrentProb is log(CurrentProb) + ), + All), + maplist(tuple, All, AllLogs, AllSquaredErrors), + sum_list( AllLogs, LLH_Training_Queries), + close(Handle), - bb_put(error_train_line_search,0.0), - forall(user:example(QueryID,_Query,QueryProb,Type), - ( - once(update_query(QueryID,'.',probability)), - once(update_query_cleanup(QueryID)), - ), - format_learning(3,' (~8f)~n',[MSE]), - retractall(values_correct). + length(AllSquaredErrors,Length), + + ( + Length>0 + -> + ( + sum_list(AllSquaredErrors,SumAllSquaredErrors), + min_list(AllSquaredErrors,MinError), + max_list(AllSquaredErrors,MaxError), + MSE is SumAllSquaredErrors/Length + );( + MSE=0.0, + MinError=0.0, + MaxError=0.0 + ) + ), + + logger_set_variable(mse_trainingset,MSE), + logger_set_variable(mse_min_trainingset,MinError), + logger_set_variable(mse_max_trainingset,MaxError), + logger_set_variable(llh_training_queries,LLH_Training_Queries), + format_learning(2,' (~8f)~n',[MSE]). + +tuple(t(X,Y),X,Y). mse_testset :- current_iteration(Iteration), create_test_predictions_file_name(Iteration,File_Name), - open(File_Name,'write',Handle), - format(Handle,"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%~n",[]), - format(Handle,"% Iteration, train/test, QueryID, Query, GroundTruth, Prediction %~n",[]), - format(Handle,"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%~n",[]), - + open(File_Name, write,Handle), format_learning(2,'MSE_Test ',[]), update_values, bb_put(llh_test_queries,0.0), @@ -732,7 +759,7 @@ mse_testset :- (user:test_example(QueryID,Query,TrueQueryProb,Type), once(update_query(QueryID,'+',probability)), query_probability(QueryID,CurrentProb), - format(Handle,'ex(~q,test,~q,~q,~10f,~10f).~n',[Iteration,QueryID,Query,TrueQueryProb,CurrentProb]), + format(Handle,'ex(~q,test,~q,~q,~10f,~10f).~n',[Iteration,QueryID,Query,TrueQueryProb,CurrentProb]), once(update_query_cleanup(QueryID)), ( @@ -808,11 +835,6 @@ save_old_probabilities :- gradient_descent :- problog_flag(sigmoid_slope,Slope), % current_iteration(Iteration), - % create_training_predictions_file_name(Iteration,File_Name), - Handle = user_error, - format(Handle,"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%~n",[]), - format(Handle,"% Iteration, train/test, QueryID, Query, GroundTruth, Prediction %~n",[]), - format(Handle,"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%~n",[]), findall(FactID,tunable_fact(FactID,GroundTruth),L), length(L,N), % leash(0),trace, lbfgs_initialize(N,X,0,Solver), @@ -839,20 +861,20 @@ user:evaluate(LLH_Training_Queries, X,Grad,N,_,_) :- N1 is N-1, forall(between(0,N1,I), (Grad[I] <== 0.0, S <== X[I], sigmoid(S,Slope, P), Probs[I] <== P) - ), nl, + ), forall( full_example(QueryID,QueryProb,BDD), compute_grad(QueryID, BDD, QueryProb,Grad, Probs, Slope,LLs) ), - LLH_Training_Queries <== sum(LLs), - writeln(LLH_Training_Queries). + LLH_Training_QueriesSum <== sum(LLs), +LLH_Training_Queries is LLH_Training_QueriesSum/TrainingExampleCount . %wrap(X, Grad, GradCount). full_example(QueryID,QueryProb,BDD) :- user:example(QueryID,_Query,QueryProb,_), recorded(QueryID,BDD,_), - BDD = bdd(_Dir, _GradTree, MapList), - MapList = [_|_]. + BDD = bdd(_Dir, _GradTree, MapList), + MapList = [_|_]. compute_grad(QueryID,BDD,QueryProb, Grad, Probs, Slope, LLs) :- BDD = bdd(_Dir, _GradTree, MapList), @@ -863,7 +885,7 @@ compute_grad(QueryID,BDD,QueryProb, Grad, Probs, Slope, LLs) :- LLs[QueryID] <== LL, %writeln( qprobability(BDD,Slope,BDDProb) ), forall( - member(I-_, MapList), + member(I-_, MapList), gradientpair(I, BDD,Slope,BDDProb, QueryProb, Grad, Probs) ). @@ -971,7 +993,7 @@ user:progress(FX,X,_G,X_Norm,G_Norm,Step,_N,Iteration,Ls,0) :- NextIteration is CurrentIteration+1, assertz(current_iteration(NextIteration)), save_model, - set_problog_flag(mse_trainingset, FX), + logger_set_variable(mse_trainingset, FX), X0 <== X[0], sigmoid(X0,Slope,P0), X1 <== X[1], sigmoid(X1,Slope,P1), format('~d. Iteration : (x0,x1)=(~4f,~4f) f(X)=~4f |X|=~4f |X\'|=~4f Step=~4f Ls=~4f~n',[Iteration,P0 ,P1,FX,X_Norm,G_Norm,Step,Ls]). diff --git a/packages/bdd/cudd.c b/packages/bdd/cudd.c index f5d183623..077ce460e 100644 --- a/packages/bdd/cudd.c +++ b/packages/bdd/cudd.c @@ -863,6 +863,9 @@ static YAP_Bool p_cudd_print_with_names(void) { static YAP_Bool p_cudd_die(void) { DdManager *manager = (DdManager *)YAP_IntOfTerm(YAP_ARG1); + //Cudd_FreeTree(manager); + //cuddFreeTable(manager); + Cudd_CheckZeroRef(manager); Cudd_Quit(manager); return TRUE; } diff --git a/packages/myddas/mysql/CMakeLists.txt b/packages/myddas/mysql/CMakeLists.txt index a4b43401a..ec188b0e0 100644 --- a/packages/myddas/mysql/CMakeLists.txt +++ b/packages/myddas/mysql/CMakeLists.txt @@ -1,4 +1,6 @@ +if (WITH_MYSQL) + set(MYSQL_SOURCES myddas_mysql.c myddas_util.c @@ -51,3 +53,5 @@ "enable the MYDDAS top-level (REPL) support for MySQL" OFF 'USE_MYDDAS AND MYSQL_FOUND' OFF) #TODO: + +endif() diff --git a/packages/myddas/odbc/CMakeLists.txt b/packages/myddas/odbc/CMakeLists.txt index 3e0be1ad7..cc9319d2d 100644 --- a/packages/myddas/odbc/CMakeLists.txt +++ b/packages/myddas/odbc/CMakeLists.txt @@ -1,39 +1,42 @@ - -set( YAPODBC_SOURCES - myddas_odbc.c -) - -set(SO_MAJOR 1) -set(SO_MINOR 0) -set(SO_PATCH 0) - -macro_optional_find_package(ODBC ON) - -if (ODBC_FOUND) - # ODBC_INCLUDE_DIRECTORIES, where to find sql.h - # ODBC_LIBRARIES, the libraries to link against to use ODBC - # ODBC_FOUND. If false, you cannot build anything that requires Odbc. -add_lib(YAPodbc ${YAPODBC_SOURCES}) -target_link_libraries(YAPodbc libYap ${ODBC_LIBRARIES}) -include_directories (${ODBC_INCLUDE_DIRECTORIES} ..) - -set_target_properties (YAPodbc PROPERTIES - POSITION_INDEPENDENT_CODE ON - PREFIX "" - ) - - list (APPEND MYDDAS_FLAGS -DMYDDAS_ODBC=1) - set (MYDDAS_FLAGS ${MYDDAS_FLAGS} ON PARENT_SCOPE) - set_property(GLOBAL APPEND PROPERTY COMPILE_DEFINITIONS - -DMYDDAS_ODBC=1) - - - install(TARGETS YAPodbc - LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR} - RUNTIME DESTINATION ${YAP_INSTALL_DLLDIR} - ARCHIVE DESTINATION ${YAP_INSTALL_DLLDIR} +if (WITH_ODBC) + + set( YAPODBC_SOURCES + myddas_odbc.c ) -else() - add_definitions (-DMYDDAS_ODBC=0) + set(SO_MAJOR 1) + set(SO_MINOR 0) + set(SO_PATCH 0) + + macro_optional_find_package(ODBC ON) + + if (ODBC_FOUND) + # ODBC_INCLUDE_DIRECTORIES, where to find sql.h + # ODBC_LIBRARIES, the libraries to link against to use ODBC + # ODBC_FOUND. If false, you cannot build anything that requires Odbc. + add_lib(YAPodbc ${YAPODBC_SOURCES}) + target_link_libraries(YAPodbc libYap ${ODBC_LIBRARIES}) + include_directories (${ODBC_INCLUDE_DIRECTORIES} ..) + + set_target_properties (YAPodbc PROPERTIES + POSITION_INDEPENDENT_CODE ON + PREFIX "" + ) + + list (APPEND MYDDAS_FLAGS -DMYDDAS_ODBC=1) + set (MYDDAS_FLAGS ${MYDDAS_FLAGS} ON PARENT_SCOPE) + set_property(GLOBAL APPEND PROPERTY COMPILE_DEFINITIONS + -DMYDDAS_ODBC=1) + + + install(TARGETS YAPodbc + LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR} + RUNTIME DESTINATION ${YAP_INSTALL_DLLDIR} + ARCHIVE DESTINATION ${YAP_INSTALL_DLLDIR} + ) + + else() + add_definitions (-DMYDDAS_ODBC=0) endif (ODBC_FOUND) + +endif() diff --git a/packages/myddas/postgres/CMakeLists.txt b/packages/myddas/postgres/CMakeLists.txt index e591ed865..edca3cfe6 100644 --- a/packages/myddas/postgres/CMakeLists.txt +++ b/packages/myddas/postgres/CMakeLists.txt @@ -1,35 +1,39 @@ -set( YAPPOSTGRES_SOURCES - myddas_postgres.c -) +if (WITH_POSTGRES) -set(SO_MAJOR 1) -set(SO_MINOR 0) -set(SO_PATCH 0) - -macro_optional_find_package(PostgreSQL ON) - -if (PostgreSQL_FOUND) -# PostgreSQL_FOUND - Set to true when PostgreSQL is found. -# PostgreSQL_INCLUDE_DIRS - Include directories for PostgreSQL -# PostgreSQL_LIBRARY_DIRS - Link directories for PostgreSQL libraries -# PostgreSQL_LIBRARIES - The PostgreSQL libraries. - add_lib(YAPpostgres ${YAPPOSTGRES_SOURCES}) - target_link_libraries(YAPpostgres libYap ${PostgreSQL_LIBRARIES}) - include_directories (${PostgreSQL_INCLUDE_DIRS} ..) - set_target_properties (YAPpostgres PROPERTIES - POSITION_INDEPENDENT_CODE ON - PREFIX "" - ) - -list (APPEND MYDDAS_FLAGS -DMYDDAS_POSTGRES=1) -set (MYDDAS_FLAGS ${MYDDAS_FLAGS} ON PARENT_SCOPE) -set_property(GLOBAL APPEND PROPERTY COMPILE_DEFINITIONS - -DMYDDAS_POSTGRES=1) - -install(TARGETS YAPpostgres - LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR} - RUNTIME DESTINATION ${YAP_INSTALL_DLLDIR} - ARCHIVE DESTINATION ${YAP_INSTALL_DLLDIR} + set( YAPPOSTGRES_SOURCES + myddas_postgres.c ) -endif (PostgreSQL_FOUND) + + set(SO_MAJOR 1) + set(SO_MINOR 0) + set(SO_PATCH 0) + + macro_optional_find_package(PostgreSQL ON) + + if (PostgreSQL_FOUND) + # PostgreSQL_FOUND - Set to true when PostgreSQL is found. + # PostgreSQL_INCLUDE_DIRS - Include directories for PostgreSQL + # PostgreSQL_LIBRARY_DIRS - Link directories for PostgreSQL libraries + # PostgreSQL_LIBRARIES - The PostgreSQL libraries. + add_lib(YAPpostgres ${YAPPOSTGRES_SOURCES}) + target_link_libraries(YAPpostgres libYap ${PostgreSQL_LIBRARIES}) + include_directories (${PostgreSQL_INCLUDE_DIRS} ..) + set_target_properties (YAPpostgres PROPERTIES + POSITION_INDEPENDENT_CODE ON + PREFIX "" + ) + + list (APPEND MYDDAS_FLAGS -DMYDDAS_POSTGRES=1) + set (MYDDAS_FLAGS ${MYDDAS_FLAGS} ON PARENT_SCOPE) + set_property(GLOBAL APPEND PROPERTY COMPILE_DEFINITIONS + -DMYDDAS_POSTGRES=1) + + install(TARGETS YAPpostgres + LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR} + RUNTIME DESTINATION ${YAP_INSTALL_DLLDIR} + ARCHIVE DESTINATION ${YAP_INSTALL_DLLDIR} + ) + endif (PostgreSQL_FOUND) + +endif() diff --git a/packages/myddas/sqlite3/CMakeLists.txt b/packages/myddas/sqlite3/CMakeLists.txt index 8d3634e6e..b78cb4501 100644 --- a/packages/myddas/sqlite3/CMakeLists.txt +++ b/packages/myddas/sqlite3/CMakeLists.txt @@ -1,68 +1,72 @@ -message( " * Sqlite3 Data-Base (http://www.sqlite3.org), distributed with MYDDAS" ) +if (WITH_SQLITE3) -set (SQLITE_EXTRA - chinook.db - sqlitest.yap) + message( " * Sqlite3 Data-Base (http://www.sqlite3.org), distributed with MYDDAS" ) -set( YAPSQLITE3_SOURCES - myddas_sqlite3.c - src/sqlite3.h - src/sqlite3ext.h - ) + set (SQLITE_EXTRA + chinook.db + sqlitest.yap) + + set( YAPSQLITE3_SOURCES + myddas_sqlite3.c + src/sqlite3.h + src/sqlite3ext.h + ) -#sqlite3 is now in the system + #sqlite3 is now in the system -set (SQLITE3_FOUND ON CACHE PRIVATE "") + set (SQLITE3_FOUND ON CACHE PRIVATE "") -include_directories ( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/..) + include_directories ( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/..) -if (ANDROID) - add_definitions(-DSQLITE_FCNTL_MMAP_SIZE=0 ) + if (ANDROID) + add_definitions(-DSQLITE_FCNTL_MMAP_SIZE=0 ) + + endif() + + add_definitions(-DSQLITE_ENABLE_COLUMN_METADATA=1 ) + + add_definitions(-DSQLITE_ENABLE_JSON1=1 ) + + add_definitions(-DSQLITE_ENABLE_RBU=1 ) + + add_definitions(-DSQLITE_ENABLE_RTREE=1 ) + add_definitions(-DSQLITE_ENABLE_FTS5=1 ) + + SET_PROPERTY(DIRECTORY PROPERTY COMPILE_DEFINITIONS YAP_KERNEL=1 ) + + + if (ANDROID ) + add_library( YAPsqlite3 OBJECT + ${YAPSQLITE3_SOURCES} ) + + else() + + list(APPEND YAPSQLITE3_SOURCES src/sqlite3.c) + + + add_library( YAPsqlite3 SHARED + ${YAPSQLITE3_SOURCES}) + + target_link_libraries(YAPsqlite3 libYap ) + + set_target_properties(YAPsqlite3 + PROPERTIES + # RPATH ${libdir} VERSION ${LIBYAPTAI_FULL_VERSION} + # SOVERSION ${LIBYAPTAI_MAJOR_VERSION}.${LIBYAPTAI_MINOR_VERSION} + POSITION_INDEPENDENT_CODE ON + PREFIX "" + ) + + install(TARGETS YAPsqlite3 + RUNTIME DESTINATION ${YAP_INSTALL_DLLDIR} + ARCHIVE DESTINATION ${YAP_INSTALL_DLLDIR} + LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR} + ) + endif() + + install(FILES ${SQLITE_EXTRA} + DESTINATION ${libpl} + ) endif() - -add_definitions(-DSQLITE_ENABLE_COLUMN_METADATA=1 ) - -add_definitions(-DSQLITE_ENABLE_JSON1=1 ) - -add_definitions(-DSQLITE_ENABLE_RBU=1 ) - -add_definitions(-DSQLITE_ENABLE_RTREE=1 ) -add_definitions(-DSQLITE_ENABLE_FTS5=1 ) - -SET_PROPERTY(DIRECTORY PROPERTY COMPILE_DEFINITIONS YAP_KERNEL=1 ) - - -if (ANDROID ) -add_library( YAPsqlite3 OBJECT - ${YAPSQLITE3_SOURCES} ) - -else() - - list(APPEND YAPSQLITE3_SOURCES src/sqlite3.c) - - -add_library( YAPsqlite3 SHARED - ${YAPSQLITE3_SOURCES}) - - target_link_libraries(YAPsqlite3 libYap ) - - set_target_properties(YAPsqlite3 - PROPERTIES - # RPATH ${libdir} VERSION ${LIBYAPTAI_FULL_VERSION} - # SOVERSION ${LIBYAPTAI_MAJOR_VERSION}.${LIBYAPTAI_MINOR_VERSION} - POSITION_INDEPENDENT_CODE ON - PREFIX "" - ) - -install(TARGETS YAPsqlite3 - RUNTIME DESTINATION ${YAP_INSTALL_DLLDIR} - ARCHIVE DESTINATION ${YAP_INSTALL_DLLDIR} - LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR} - ) -endif() - - install(FILES ${SQLITE_EXTRA} - DESTINATION ${libpl} - ) diff --git a/packages/python/pybips.c b/packages/python/pybips.c index 8fbed2b3b..ded76ada8 100644 --- a/packages/python/pybips.c +++ b/packages/python/pybips.c @@ -591,7 +591,8 @@ static long get_len_of_range(long lo, long hi, long step) { } #if PY_MAJOR_VERSION >= 3 -static PyStructSequence_Field pnull[] = { +/* + static PyStructSequence_Field pnull[] = { {"A1", NULL}, {"A2", NULL}, {"A3", NULL}, {"A4", NULL}, {"A5", NULL}, {"A6", NULL}, {"A7", NULL}, {"A8", NULL}, {"A9", NULL}, {"A9", NULL}, {"A10", NULL}, {"A11", NULL}, {"A12", NULL}, {"A13", NULL}, {"A14", NULL}, @@ -600,7 +601,8 @@ static PyStructSequence_Field pnull[] = { {"A24", NULL}, {"A25", NULL}, {"A26", NULL}, {"A27", NULL}, {"A28", NULL}, {"A29", NULL}, {"A29", NULL}, {"A30", NULL}, {"A31", NULL}, {"A32", NULL}, {NULL, NULL}}; - +*/ + static PyObject *structseq_str(PyObject *iobj) { /* buffer and type size were chosen well considered. */ @@ -763,7 +765,7 @@ PyObject *term_to_nametuple(const char *s, arity_t arity, PyObject *tuple) { PyStructSequence_Desc *desc = calloc(sizeof(PyStructSequence_Desc), 1); desc->name = PyMem_Malloc(strlen(s) + 1); desc->doc = "YAPTerm"; - desc->fields = pnull; + desc->fields = NULL; desc->n_in_sequence = arity; if (PyStructSequence_InitType2(typp, desc) < 0) return NULL;