fixes
This commit is contained in:
parent
a079139060
commit
f8d0703983
@ -91,15 +91,19 @@ static char *send_tracer_message(char *start, char *name, arity_t arity,
|
||||
Quote_illegal_f | Handle_vars_f);
|
||||
size_t sz;
|
||||
if (sn == NULL) {
|
||||
sn = "<* error *>";
|
||||
sn = malloc(strlen("<* error *>")+1);
|
||||
strcpy((char*)sn, "<* error *>");
|
||||
}
|
||||
sz = strlen(sn);
|
||||
if (max <= sz) {
|
||||
min = sz + 1024;
|
||||
expand = true;
|
||||
free((void*)sn);
|
||||
continue;
|
||||
}
|
||||
strcpy(s, sn);
|
||||
free((void*)sn);
|
||||
sn = NULL;
|
||||
s += sz;
|
||||
max -= sz;
|
||||
}
|
||||
|
@ -204,8 +204,6 @@ int Yap_open_buf_write_stream(encoding_t enc, memBufSource src) {
|
||||
|
||||
st = GLOBAL_Stream + sno;
|
||||
st->status = Output_Stream_f | InMemory_Stream_f;
|
||||
if (src)
|
||||
st->status |= FreeOnClose_Stream_f;
|
||||
st->linepos = 0;
|
||||
st->charcount = 0;
|
||||
st->linecount = 1;
|
||||
@ -269,7 +267,7 @@ FILE *f = GLOBAL_Stream[sno].file;
|
||||
memcpy(buf, s, len);
|
||||
// s[fseek(GLOBAL_Stream[sno].file, 0, SEEK_END)] = '\0';
|
||||
#else
|
||||
fread(buf, sz, 1, GLOBAL_Stream[sno].file);
|
||||
fread(buf, len, 1, GLOBAL_Stream[sno].file);
|
||||
#endif
|
||||
buf[len] = '\0';
|
||||
return buf;
|
||||
|
@ -90,7 +90,10 @@ else if (PyUnicode_Check(pVal)) {
|
||||
rc = rc && PL_unify_atom_chars(t, s);
|
||||
else
|
||||
#endif
|
||||
if (pyStringToString)
|
||||
return MkStringTerm(s);
|
||||
else
|
||||
return MkAtomTerm(Yap_LookupAtom(s));
|
||||
}
|
||||
else if (PyByteArray_Check(pVal)) {
|
||||
return MkStringTerm(PyByteArray_AsString(pVal));
|
||||
|
@ -93,6 +93,7 @@ extern PyObject *py_Sys;
|
||||
#define py_Builtin PyEval_GetBuiltins()
|
||||
|
||||
extern X_API bool python_in_python;
|
||||
extern bool pyStringToString;
|
||||
|
||||
extern bool python_release_GIL(term_t gstate);
|
||||
extern term_t python_acquire_GIL(void);
|
||||
|
@ -231,6 +231,24 @@ static foreign_t assign_python(term_t exp, term_t name) {
|
||||
pyErrorAndReturn(b);
|
||||
}
|
||||
|
||||
|
||||
static foreign_t python_string_to(term_t f) {
|
||||
if (PL_is_atom(f)) {
|
||||
char *s = NULL;
|
||||
if (!PL_get_chars(f, &s, CVT_ALL | CVT_EXCEPTION | REP_UTF8)) {
|
||||
pyErrorAndReturn(false);
|
||||
}
|
||||
if (!strcmp(s,"atom"))
|
||||
pyStringToString = false;
|
||||
if (!strcmp(s,"string"))
|
||||
pyStringToString = true;
|
||||
else
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static foreign_t python_builtin_eval(term_t caller, term_t dict, term_t out) {
|
||||
PyErr_Clear();
|
||||
PyObject *pI, *pArgs, *pOut;
|
||||
@ -759,6 +777,7 @@ install_t install_pypreds(void) {
|
||||
PL_register_foreign("python_access", 3, python_access, 0);
|
||||
PL_register_foreign("python_threaded", 0, p_python_threaded, 0);
|
||||
PL_register_foreign("python_clear_errors", 0, python_clear_errors, 0);
|
||||
PL_register_foreign("python_string_to", 0, python_string_to, 1);
|
||||
|
||||
init_python_vfs();
|
||||
}
|
||||
|
@ -28,6 +28,8 @@ PyObject *py_Context;
|
||||
|
||||
X_API PyObject *Py_f2p;
|
||||
|
||||
bool pyStringToString;
|
||||
|
||||
extern X_API bool python_in_python;
|
||||
|
||||
static void add_modules(void) {
|
||||
|
@ -28,6 +28,7 @@
|
||||
array_to_python_tuple/4,
|
||||
array_to_python_view/5,
|
||||
python/2,
|
||||
python_string_to/1,
|
||||
acquire_GIL/0,
|
||||
release_GIL/0,
|
||||
python_threaded/0,
|
||||
|
@ -20,9 +20,11 @@ ENDIF (NOT YAP_FOUND)
|
||||
|
||||
)
|
||||
|
||||
SET ( LBFGS_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/${LBFGS_SRC}/lib/arithmetic_ansi.h ${CMAKE_CURRENT_SOURCE_DIR}/${LBFGS_SRC}/lib/arithmetic_sse_double.h ${CMAKE_CURRENT_SOURCE_DIR}/${LBFGS_SRC}/lib/arithmetic_sse_float.h )
|
||||
|
||||
SET ( LBFGS_SOURCES
|
||||
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/${LBFGS_SRC}/lib/arithmetic_ansi.h ${CMAKE_CURRENT_SOURCE_DIR}/${LBFGS_SRC}/lib/arithmetic_sse_double.h ${CMAKE_CURRENT_SOURCE_DIR}/${LBFGS_SRC}/lib/arithmetic_sse_float.h ${CMAKE_CURRENT_SOURCE_DIR}/${LBFGS_SRC}/lib/lbfgs.c ${CMAKE_CURRENT_SOURCE_DIR}/yap_lbfgs.c)
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/${LBFGS_SRC}/lib/lbfgs.c ${CMAKE_CURRENT_SOURCE_DIR}/yap_lbfgs.c)
|
||||
|
||||
add_library(LBFGS
|
||||
${LBFGS_SOURCES})
|
||||
|
@ -40,7 +40,8 @@ progress(FX,X,G,X_Norm,G_Norm,Step,_N,Iteration,Ls, 0) :-
|
||||
|
||||
|
||||
demo :-
|
||||
format('Optimizing the function f(x0) = sin(x0)~n',[]),
|
||||
start_low_level_trace,
|
||||
format('Optimizing the function f(x0) = sin(x0)~n',[]),
|
||||
optimizer_initialize(1,X,Status),
|
||||
|
||||
|
||||
|
@ -239,17 +239,15 @@ meaning.
|
||||
static YAP_Bool optimizer_run(void) {
|
||||
int ret = 0;
|
||||
int n = YAP_IntOfTerm(YAP_ARG1);
|
||||
YAP_Term t2 = YAP_ARG2;
|
||||
YAP_Int s1, s2;
|
||||
lbfgsfloatval_t fx;
|
||||
lbfgsfloatval_t *temp_x = ( lbfgsfloatval_t *) YAP_IntOfTerm(YAP_ARG2),
|
||||
*temp_ox = ( lbfgsfloatval_t *) YAP_IntOfTerm(YAP_ARG4);
|
||||
lbfgsfloatval_t *temp_x = ( lbfgsfloatval_t *)YAP_IntOfTerm( YAP_ArgOfTerm(1, YAP_ARG2)),
|
||||
*temp_ox = ( lbfgsfloatval_t *) YAP_IntOfTerm(YAP_ArgOfTerm(1,YAP_ARG4));
|
||||
lbfgs_parameter_t *temp_p = (lbfgs_parameter_t * ) YAP_IntOfTerm(YAP_ARG6);
|
||||
|
||||
//optimizer_status = OPTIMIZER_STATUS_RUNNING;
|
||||
ret = lbfgs(n, temp_x, &fx, evaluate, progress, temp_ox, temp_p);
|
||||
|
||||
return YAP_Unify(YAP_MkIntTerm(ret), YAP_ARG5);
|
||||
return YAP_Unify(YAP_MkIntTerm(ret), YAP_ARG5) &&
|
||||
YAP_Unify(YAP_MkFloatTerm(fx), YAP_ARG3);
|
||||
}
|
||||
|
||||
|
||||
|
@ -311,7 +311,7 @@ load_files(Files0,Opts) :-
|
||||
( LC > 0
|
||||
->
|
||||
'__NB_getval__'('$lf_status', OldTOpts, fail),
|
||||
nonvar(OldTOpts),
|
||||
nonvar(OldTOpts), functor( OldTOpts, opt, LastOpt ),
|
||||
'$lf_opt'(autoload, OldTOpts, OldAutoload),
|
||||
'$lf_opt'('$context_module', OldTOpts, OldContextModule)
|
||||
;
|
||||
|
@ -257,15 +257,14 @@ location(style_check(A,LN,FileName,B ), Level , LC) -->
|
||||
display_consulting( FileName, Level,style_check(A,LN,FileName,B ), LC ),
|
||||
[ '~a:~d:0 ~a ' - [FileName,LN,Level] ] .
|
||||
location( error(_,Info), Level, LC ) -->
|
||||
|
||||
{ '$error_descriptor'(Info, Desc) },
|
||||
{
|
||||
query_exception(prologPredFile, Desc, File),
|
||||
{
|
||||
query_exception(prologPredFile, Desc, File),
|
||||
query_exception(prologPredLine, Desc, FilePos),
|
||||
query_exception(prologPredModule, Desc, M),
|
||||
query_exception(prologPredName, Desc, Na),
|
||||
query_exception(prologPredArity, Desc, Ar)
|
||||
},
|
||||
},
|
||||
!,
|
||||
display_consulting( File, Level, Info, LC ),
|
||||
{simplify_pred(M:Na/Ar,FF)},
|
||||
@ -358,7 +357,7 @@ display_consulting( F, Level, Info, LC) -->
|
||||
{ LC > 0,
|
||||
'$error_descriptor'(Info, Desc),
|
||||
query_exception(prologParserFile, Desc, F0),
|
||||
query_exception(prologarserLine, Desc, L),
|
||||
query_exception(prologParserLine, Desc, L),
|
||||
F \= F0
|
||||
}, !,
|
||||
[ '~a:~d:0: ~a raised at:'-[F0,L,Level], nl ].
|
||||
|
Reference in New Issue
Block a user