hi,
For some reason iterating over restraints like: for(Restraints::iterator it = opt_mdl->get_restraints().begin(); it != opt_mdl->get_restraints().end(); it++) { } fails as *it == NULL, even though it contains data. The problem is solved if iterating like: for(unsigned int i =0;i<opt_mdl->get_restraints().size();i++){}
Keren.
Keren Lasker wrote: > For some reason iterating over restraints like: > for(Restraints::iterator it = opt_mdl->get_restraints().begin(); > it != opt_mdl->get_restraints().end(); it++) { > }
Don't do that! At best, that's going to make a copy of your restraints vector, then iterate over that. (But since you call get_restraints twice, you're going to get two different copies, and the iteration probably won't work at all.) Instead, do:
for(Model::RestraintIterator it = opt_mdl->restraints_begin(); it != opt_mdl->restraints_end(); ++it) {
to iterate over the original vector.
Daniel added get_restraints() for the Python interface, but you shouldn't use it for C++ code. Eventually I will get rid of it entirely, and have the Python interface access the original vector (not a copy) as well.
Ben
On Aug 13, 2008, at 8:41 AM, Ben Webb wrote:
> Keren Lasker wrote: >> For some reason iterating over restraints like: >> for(Restraints::iterator it = opt_mdl->get_restraints().begin(); >> it != opt_mdl->get_restraints().end(); it++) { >> } > > Don't do that! At best, that's going to make a copy of your restraints > vector, then iterate over that. (But since you call get_restraints > twice, you're going to get two different copies, and the iteration > probably won't work at all.) Instead, do: > > for(Model::RestraintIterator it = opt_mdl->restraints_begin(); > it != opt_mdl->restraints_end(); ++it) { > > to iterate over the original vector. > > Daniel added get_restraints() for the Python interface, but you > shouldn't use it for C++ code. Eventually I will get rid of it > entirely, > and have the Python interface access the original vector (not a > copy) as > well. As Ben said, don't do that. That said, it sounds like a bug may have worked its way in there. I'll look into it.
As ben said, don't do it. That said, it is a bug and I'll fix it.
On Aug 13, 2008, at 8:41 AM, Ben Webb ben@salilab.org wrote:
> Keren Lasker wrote: >> For some reason iterating over restraints like: >> for(Restraints::iterator it = opt_mdl->get_restraints().begin(); >> it != opt_mdl->get_restraints().end(); it++) { >> } > > Don't do that! At best, that's going to make a copy of your restraints > vector, then iterate over that. (But since you call get_restraints > twice, you're going to get two different copies, and the iteration > probably won't work at all.) Instead, do: > > for(Model::RestraintIterator it = opt_mdl->restraints_begin(); > it != opt_mdl->restraints_end(); ++it) { > > to iterate over the original vector. > > Daniel added get_restraints() for the Python interface, but you > shouldn't use it for C++ code. Eventually I will get rid of it > entirely, > and have the Python interface access the original vector (not a > copy) as > well. > > Ben > -- > ben@salilab.org http://salilab.org/~ben/ > "It is a capital mistake to theorize before one has data." > - Sir Arthur Conan Doyle > _______________________________________________ > IMP-dev mailing list > IMP-dev@salilab.org > https://salilab.org/mailman/listinfo/imp-dev
I can't think of any way to catch that usage. The functions probably should be added through %extend in IMP.i rather than in the c++ source. I think it would be hard to expose the problem in python.
At least the docs should be fixed.
On Aug 13, 2008, at 8:41 AM, Ben Webb ben@salilab.org wrote:
> Keren Lasker wrote: >> For some reason iterating over restraints like: >> for(Restraints::iterator it = opt_mdl->get_restraints().begin(); >> it != opt_mdl->get_restraints().end(); it++) { >> } > > Don't do that! At best, that's going to make a copy of your restraints > vector, then iterate over that. (But since you call get_restraints > twice, you're going to get two different copies, and the iteration > probably won't work at all.) Instead, do: > > for(Model::RestraintIterator it = opt_mdl->restraints_begin(); > it != opt_mdl->restraints_end(); ++it) { > > to iterate over the original vector. > > Daniel added get_restraints() for the Python interface, but you > shouldn't use it for C++ code. Eventually I will get rid of it > entirely, > and have the Python interface access the original vector (not a > copy) as > well. > > Ben > -- > ben@salilab.org http://salilab.org/~ben/ > "It is a capital mistake to theorize before one has data." > - Sir Arthur Conan Doyle > _______________________________________________ > IMP-dev mailing list > IMP-dev@salilab.org > https://salilab.org/mailman/listinfo/imp-dev
Daniel Russel wrote: > I can't think of any way to catch that usage. The functions probably > should be added through %extend in IMP.i rather than in the c++ > source. I think it would be hard to expose the problem in python. > > At least the docs should be fixed.
Agreed - my thoughts exactly. I'll take a look at this later today.
Ben
participants (3)
-
Ben Webb
-
Daniel Russel
-
Keren Lasker