pybind / pybind/pybind11

[QUESTION] Return class instance, but the class function get the wrong data

Open
#2,648 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
18k
Forks
2.3k
Avg merge
5d 17h
Merged PRs (30d)
10

Description

def atest():
      my_BTD = py_cc.BTD(Nd, Np, sizebw, type)   # construct a c++ class
      a = my_BTD.get_array()                                  # this function get right data
      b = btest(my_BTD)                                        # this will get the right data      
                                                                             # a is same with b
     print(a)
     print(b)

return my_BTD 

a = atest()
c = a.get_array()                                        #this functtion get wrong data, sometimes get wrong data, sometime get right data 
print(c)

def btest(BTD):
      b = BTD.get_array()                                   # this function get right data

who can tell me why??? thanks a lot!

EDIT (@YannickJadoul): surround code with ```

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the atest and btest examples in the issue and reproduce the differing get_array() results after returning BTD. Inspect the BTD binding and get_array entry points, which are not included here; done requires a minimal reproducible case and an identified explanation or regression test for the inconsistent returned data.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, python
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
18/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.