Skip to content

Commit

Permalink
Merge pull request #1882 from cmastalli/topic/enable-copy
Browse files Browse the repository at this point in the history
Enabled copy and deepcopy
  • Loading branch information
jcarpent authored Jul 13, 2023
2 parents fc10553 + 28bda82 commit d2c1904
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/macos-linux-conda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ jobs:
runs-on: ${{ matrix.os }}
env:
CCACHE_DIR: ${{ matrix.CCACHE_DIR }}
BUILD_ADVANCED_TESTING: ${{ matrix.BUILD_ADVANCED_TESTING }}

strategy:
fail-fast: false
Expand All @@ -18,8 +19,10 @@ jobs:
include:
- os: ubuntu-latest
CCACHE_DIR: /home/runner/.ccache
BUILD_ADVANCED_TESTING: OFF
- os: macos-latest
CCACHE_DIR: /Users/runner/.ccache
BUILD_ADVANCED_TESTING: ON

steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -54,7 +57,7 @@ jobs:
mkdir build
cd build
cmake .. -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DBUILD_WITH_COLLISION_SUPPORT=ON -DBUILD_ADVANCED_TESTING=ON -DBUILD_WITH_CASADI_SUPPORT=OFF -DPYTHON_EXECUTABLE=$(which python3) -DBUILD_WITH_OPENMP_SUPPORT=ON -DINSTALL_DOCUMENTATION=ON -DOpenMP_ROOT=$CONDA_PREFIX
cmake .. -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DBUILD_WITH_COLLISION_SUPPORT=ON -DBUILD_ADVANCED_TESTING=${{ env.BUILD_ADVANCED_TESTING }} -DBUILD_WITH_CASADI_SUPPORT=OFF -DPYTHON_EXECUTABLE=$(which python3) -DBUILD_WITH_OPENMP_SUPPORT=ON -DINSTALL_DOCUMENTATION=ON -DOpenMP_ROOT=$CONDA_PREFIX
make
make build_tests
CTEST_OUTPUT_ON_FAILURE=1 make test
Expand Down
11 changes: 8 additions & 3 deletions bindings/python/utils/copyable.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2016-2021 CNRS INRIA
// Copyright (c) 2016-2023 CNRS INRIA
//

#ifndef __pinocchio_python_utils_copyable_hpp__
Expand All @@ -13,7 +13,7 @@ namespace pinocchio
{

namespace bp = boost::python;

///
/// \brief Add the Python method copy to allow a copy of this by calling the copy constructor.
///
Expand All @@ -23,10 +23,15 @@ namespace pinocchio
{
template<class PyClass>
void visit(PyClass & cl) const
{ cl.def("copy",&copy,bp::arg("self"),"Returns a copy of *this."); }
{
cl.def("copy",&copy,bp::arg("self"),"Returns a copy of *this.");
cl.def("__copy__", &copy,bp::arg("self"),"Returns a copy of *this.");
cl.def("__deepcopy__", &deepcopy,bp::args("self","memo"),"Returns a deep copy of *this.");
}

private:
static C copy(const C & self) { return C(self); }
static C deepcopy(const C & self, bp::dict) { return C(self); }
};
} // namespace python
} // namespace pinocchio
Expand Down
13 changes: 13 additions & 0 deletions unittest/python/bindings_SE3.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import pinocchio as pin
import numpy as np
from pinocchio.utils import eye,zero,rand
from copy import deepcopy, copy

ones = lambda n: np.ones([n, 1] if isinstance(n, int) else n)

Expand Down Expand Up @@ -158,5 +159,17 @@ def test_several_init(self):
s = r.__str__()
self.assertTrue(s != '')

def test_copy(self):
M = pin.SE3.Random()
Mc = copy(M)
Mdc = deepcopy(M)
self.assertTrue(M == Mc)
self.assertTrue(M == Mdc)

Mc.setRandom()
self.assertFalse(M == Mc)
Mdc.setRandom()
self.assertFalse(M == Mc)

if __name__ == '__main__':
unittest.main()

0 comments on commit d2c1904

Please sign in to comment.