Bug #1641

Feature #1290: === Core: framework ===

Feature #1572: == Python ==

histogram2d test fails under certain configurations

Added by jmfisher about 1 year ago. Updated 12 months ago.

Status:ResolvedStart date:16 Nov 2016
Priority:NormalDue date:
Assignee:pospelov% Done:

0%

Category:-
Target version:Sprint 33

Description

The test histogram2d.py fails under certain configurations (see buildbot). On my Arch setup it fails for clang+Python3 (but passes for gcc+Python3). It is also failing in the Ubuntu Yakkety clang nightly build. The problem is caused by the swig array to std::vector automatic conversion. For some reason clang treats the swig generated code differently and the conversion fails, giving a runtime error. (Possibly due to stricter casting rules? I did a bit of investigating but the problem is not immediately clear.)

History

#1 Updated by jmfisher about 1 year ago

I have just tested clang+Python2 on Yakkety and there seems to be no problem. So the issue is restricted clang+Python3.

#2 Updated by wuttke about 1 year ago

  • Parent task set to #1572

#3 Updated by jmfisher about 1 year ago

On a fresh Arch installation I re-encountered this problem with gcc+Python3 so it may not be limited to clang.

#4 Updated by pospelov 12 months ago

  • Status changed from New to Sprint
  • Target version set to Sprint 33

From the discussion with Jonathan and my wage remembering, it will be enough to use

Histogram2D(vector<vector<double>> data)

// instead of current
Histogram2D(const vector<vector<double>> &data)

So having a copy on the way from Python-numpy array transformation.

#5 Updated by pospelov 12 months ago

  • Assignee set to pospelov

#6 Updated by pospelov 12 months ago

  • Status changed from Sprint to Resolved

Test was fixed by requiring numpy array to be of type dtype=float64.

Also we've discovered, that there is no 'automatic-swig-way' to pass arbitrary numpy array into BornAgain, except float64 type.

The code below works for Python 2 and Python 3

// on C++ side
void fun(const std::vector<double>& data)

# on Python side
array = numpy.array([1, 2, 3], dtype=float64)
ba.fun(array)

The code below doesnt' work for both, Python2 and Python3.

// on C++ side
void fun(const std::vector<int>& data)

# on Python side
array = numpy.array([1, 2, 3], dtype=int32)
ba.fun(array)

The code below works for Python 2, but not for Python 3

// on C++ side
void fun(const std::vector<double>& data)

# on Python side
array = numpy.array([1, 2, 3], dtype=int64)
ba.fun(array)

In the future we will have to return to the subject. Typical use case: define numpy array of dtype=bool to represent detector masks, and pass it inside BornAgain.

Useful links

seems having very sophisticated swig bindings

Also available in: Atom PDF