Git Product home page Git Product logo

Comments (10)

valentjn avatar valentjn commented on May 31, 2024

In GitLab by @valentjn on May 7, 2016, 10:58

"Good" version of _wrap_OptScalarFunction_eval:

SWIGINTERN PyObject *_wrap_OptScalarFunction_eval(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
  PyObject *resultobj = 0;
  sgpp::optimization::ScalarFunction *arg1 = (sgpp::optimization::ScalarFunction *) 0 ;
  sgpp::base::DataVector *arg2 = 0 ;
  void *argp1 = 0 ;
  int res1 = 0 ;
  void *argp2 = 0 ;
  int res2 = 0 ;
  PyObject * obj0 = 0 ;
  PyObject * obj1 = 0 ;
  Swig::Director *director = 0;
  bool upcall = false;
  double result;
  
  if (!PyArg_ParseTuple(args,(char *)"OO:OptScalarFunction_eval",&obj0,&obj1)) SWIG_fail;
  res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_sgpp__optimization__ScalarFunction, 0 |  0 );
  if (!SWIG_IsOK(res1)) {
    SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "OptScalarFunction_eval" "', argument " "1"" of type '" "sgpp::optimization::ScalarFunction *""'"); 
  }
  arg1 = reinterpret_cast< sgpp::optimization::ScalarFunction * >(argp1);
  res2 = SWIG_ConvertPtr(obj1, &argp2, SWIGTYPE_p_sgpp__base__DataVector,  0  | 0);
  if (!SWIG_IsOK(res2)) {
    SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "OptScalarFunction_eval" "', argument " "2"" of type '" "sgpp::base::DataVector const &""'"); 
  }
  if (!argp2) {
    SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "OptScalarFunction_eval" "', argument " "2"" of type '" "sgpp::base::DataVector const &""'"); 
  }
  arg2 = reinterpret_cast< sgpp::base::DataVector * >(argp2);
  director = SWIG_DIRECTOR_CAST(arg1);
  upcall = (director && (director->swig_get_self()==obj0));
  try {
    {
      try {
        if (upcall) {
          Swig::DirectorPureVirtualException::raise("sgpp::optimization::ScalarFunction::eval");
        } else {
          result = (double)(arg1)->eval((sgpp::base::DataVector const &)*arg2);
        }
      } catch (const std::exception& e) {
        SWIG_exception(SWIG_RuntimeError, e.what());
      }
    }
  } catch (Swig::DirectorException&) {
    SWIG_fail;
  }
  resultobj = SWIG_From_double(static_cast< double >(result));
  return resultobj;
fail:
  return NULL;
}

from sgpp.

valentjn avatar valentjn commented on May 31, 2024

In GitLab by @valentjn on May 7, 2016, 10:59

"Bad" version of _wrap_OptScalarFunction_eval:

SWIGINTERN PyObject *_wrap_OptScalarFunction_eval(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
  PyObject *resultobj = 0;
  sgpp::optimization::ScalarFunction *arg1 = (sgpp::optimization::ScalarFunction *) 0 ;
  sgpp::base::DataVector *arg2 = 0 ;
  void *argp1 = 0 ;
  int res1 = 0 ;
  void *argp2 = 0 ;
  int res2 = 0 ;
  std::shared_ptr< sgpp::base::DataVector const > tempshared2 ;
  PyObject * obj0 = 0 ;
  PyObject * obj1 = 0 ;
  Swig::Director *director = 0;
  bool upcall = false;
  double result;
  
  if (!PyArg_ParseTuple(args,(char *)"OO:OptScalarFunction_eval",&obj0,&obj1)) SWIG_fail;
  res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_sgpp__optimization__ScalarFunction, 0 |  0 );
  if (!SWIG_IsOK(res1)) {
    SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "OptScalarFunction_eval" "', argument " "1"" of type '" "sgpp::optimization::ScalarFunction *""'"); 
  }
  arg1 = reinterpret_cast< sgpp::optimization::ScalarFunction * >(argp1);
  {
    int newmem = 0;
    res2 = SWIG_ConvertPtrAndOwn(obj1, &argp2, SWIGTYPE_p_std__shared_ptrT_sgpp__base__DataVector_t,  0 , &newmem);
    if (!SWIG_IsOK(res2)) {
      SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "OptScalarFunction_eval" "', argument " "2"" of type '" "sgpp::base::DataVector const &""'"); 
    }
    if (!argp2) {
      SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "OptScalarFunction_eval" "', argument " "2"" of type '" "sgpp::base::DataVector const &""'"); 
    }
    if (newmem & SWIG_CAST_NEW_MEMORY) {
      tempshared2 = *reinterpret_cast< std::shared_ptr< const sgpp::base::DataVector > * >(argp2);
      delete reinterpret_cast< std::shared_ptr< const sgpp::base::DataVector > * >(argp2);
      arg2 = const_cast< sgpp::base::DataVector * >(tempshared2.get());
    } else {
      arg2 = const_cast< sgpp::base::DataVector * >(reinterpret_cast< std::shared_ptr< const sgpp::base::DataVector > * >(argp2)->get());
    }
  }
  director = SWIG_DIRECTOR_CAST(arg1);
  upcall = (director && (director->swig_get_self()==obj0));
  try {
    {
      try {
        if (upcall) {
          Swig::DirectorPureVirtualException::raise("sgpp::optimization::ScalarFunction::eval");
        } else {
          result = (double)(arg1)->eval((sgpp::base::DataVector const &)*arg2);
        }
      } catch (const std::exception& e) {
        SWIG_exception(SWIG_RuntimeError, e.what());
      }
    }
  } catch (Swig::DirectorException&) {
    SWIG_fail;
  }
  resultobj = SWIG_From_double(static_cast< double >(result));
  return resultobj;
fail:
  return NULL;
}

from sgpp.

valentjn avatar valentjn commented on May 31, 2024

In GitLab by @valentjn on May 14, 2016, 09:03

Confirmed on current master.

from sgpp.

valentjn avatar valentjn commented on May 31, 2024

In GitLab by @valentjn on May 15, 2016, 16:15

diff -ub (ignoring whitespace) of the two versions above:

--- /home/valentjn/swig_bad.cpp 2016-05-15 15:46:12.444554848 +0200
+++ /home/valentjn/swig_good.cpp        2016-05-15 15:46:20.700535665 +0200
@@ -6,7 +6,6 @@
   int res1 = 0 ;
   void *argp2 = 0 ;
   int res2 = 0 ;
-  std::shared_ptr< sgpp::base::DataVector const > tempshared2 ;
   PyObject * obj0 = 0 ;
   PyObject * obj1 = 0 ;
   Swig::Director *director = 0;
@@ -19,23 +18,14 @@
     SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "OptScalarFunction_eval" "', argument " "1"" of type '" "sgpp::optimization::ScalarFunction *""'"); 
   }
   arg1 = reinterpret_cast< sgpp::optimization::ScalarFunction * >(argp1);
-  {
-    int newmem = 0;
-    res2 = SWIG_ConvertPtrAndOwn(obj1, &argp2, SWIGTYPE_p_std__shared_ptrT_sgpp__base__DataVector_t,  0 , &newmem);
+  res2 = SWIG_ConvertPtr(obj1, &argp2, SWIGTYPE_p_sgpp__base__DataVector,  0  | 0);
     if (!SWIG_IsOK(res2)) {
       SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "OptScalarFunction_eval" "', argument " "2"" of type '" "sgpp::base::DataVector const &""'"); 
     }
     if (!argp2) {
       SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "OptScalarFunction_eval" "', argument " "2"" of type '" "sgpp::base::DataVector const &""'"); 
     }
-    if (newmem & SWIG_CAST_NEW_MEMORY) {
-      tempshared2 = *reinterpret_cast< std::shared_ptr< const sgpp::base::DataVector > * >(argp2);
-      delete reinterpret_cast< std::shared_ptr< const sgpp::base::DataVector > * >(argp2);
-      arg2 = const_cast< sgpp::base::DataVector * >(tempshared2.get());
-    } else {
-      arg2 = const_cast< sgpp::base::DataVector * >(reinterpret_cast< std::shared_ptr< const sgpp::base::DataVector > * >(argp2)->get());
-    }
-  }
+  arg2 = reinterpret_cast< sgpp::base::DataVector * >(argp2);
   director = SWIG_DIRECTOR_CAST(arg1);
   upcall = (director && (director->swig_get_self()==obj0));
   try {

I don't really understand what this function is really doing. It seems to be called from OptScalarFunction.eval in pysgpp_swig.py... Fixing this would be great as this bug prevents one of the core examples from working. Not only that, it basically renders the complete optimization module unusable from Python :frowning2:

from sgpp.

valentjn avatar valentjn commented on May 31, 2024

In GitLab by @valentjn on May 15, 2016, 16:32

The director class SwigDirector_OptScalarFunction in pysgpp_wrap.h/pysgpp_wrap.cc (in particular the eval function) seems to be identical...

from sgpp.

valentjn avatar valentjn commented on May 31, 2024

In GitLab by @valentjn on May 15, 2016, 16:53

What I'm not getting right now is what _wrap_OptScalarFunction_eval has to do with anything. That bug occurs when calling the abstract eval method within C++ code, and that should trigger SwigDirector_OptScalarFunction::eval which should call the user-defined Python code, which sees the wrong type of argument like described above.

On the other side, _wrap_OptScalarFunction_eval is called (from my point of view) when executing eval on the Python side for an object inheriting from pysgpp.OptScalarFunction like that one at the very top.

So in my mind, these two are different pairs of shoes. I cannot be understanding it correctly...

from sgpp.

valentjn avatar valentjn commented on May 31, 2024

In GitLab by @valentjn on May 15, 2016, 16:55

Since this is a major bug in my eyes (and since I'm clueless), I will revert the relevant part of 9514d92 if we don't find another workaround. @fabianfranzelin Any ideas?

from sgpp.

valentjn avatar valentjn commented on May 31, 2024

In GitLab by @valentjn on May 17, 2016, 16:41

Status changed to closed by commit 711dc8c

from sgpp.

valentjn avatar valentjn commented on May 31, 2024

In GitLab by @valentjn on May 17, 2016, 16:45

After talking to @fabianfranzelin, we temporarily commented out that functionality, removing the SWIG support of LearnerSGDE as well.

At the next coding days, we definitely have to look into the consistent use of smart pointers within SG++ and how to correctly propagate them with SWIG.

from sgpp.

valentjn avatar valentjn commented on May 31, 2024

In GitLab by @valentjn on May 18, 2016, 10:24

mentioned in commit 711dc8c

from sgpp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.