techoe / ceres-solver

Automatically exported from code.google.com/p/ceres-solver
Other
0 stars 0 forks source link

AutoDiffCostFunction not working with more than 6 params #78

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
problem.AddResidualBlock(
  new ceres::AutoDiffCostFunction<ConformalResidual, 8, 1, 1, 1, 1, 1, 1, 1, 1>(
    new TestResidual), NULL, &x0, &y0, &x1, &y1, &x2, &y2, &x3, &y3);

With for instance:

class TestResidual{
public:
  TestResidual() {}
  template <typename T> bool operator()(const T* const x0, const T* const y0,
                                        const T* const x1, const T* const y1,
                                        const T* const x2, const T* const y2,
                                        const T* const x3, const T* const y3,
                                        T* residuals) const {
    double weight_ = 1;
    residuals[0] = weight_ * (x1[0] - x0[0] - 2);
    residuals[1] = weight_ * (y1[0] - y0[0]);
    residuals[2] = weight_ * (x3[0] - x2[0] - 2);
    residuals[3] = weight_ * (y3[0] - y2[0]);
    residuals[4] = weight_ * (x2[0] - x1[0] + 2);
    residuals[5] = weight_ * (y2[0] - y1[0] - 3);
    residuals[6] = weight_ * (x0[0] - x3[0] + 2);
    residuals[7] = weight_ * (y0[0] - y3[0] + 3);

    std::cout << "0: " << x0[0] << " " << y0[0] << "\n";
    std::cout << "1: " << x1[0] << " " << y1[0] << "\n";
    std::cout << "2: " << x2[0] << " " << y2[0] << "\n";
    std::cout << "3: " << x3[0] << " " << y3[0] << "\n";
    return true;
  }
};

What is the expected output? What do you see instead?

Expected
0: [x0;  1 0 0 0 0 0 0 0] [y0; 0 1 0 0 0 0 0 0]
1: [x1;  0 0 1 0 0 0 0 0] [y1; 0 0 0 1 0 0 0 0]
2: [x2;  0 0 0 0 1 0 0 0] [y2; 0 0 0 0 0 1 0 0]
3: [x3;  0 0 0 0 0 0 1 0] [y3; 0 0 0 0 0 0 0 1]

Having this instead
0: [x0;  1 0 0 0 0 0 0 0] [y0; 0 1 0 0 0 0 0 0]
1: [x1;  0 0 1 0 0 0 0 0] [y1; 0 0 0 1 0 0 0 0]
2: [x2;  0 0 0 0 1 0 0 0] [y2; 0 0 0 0 0 1 0 0]
3: [0; -1 0 1 0 0 0 0 0]  [0; 0 -1  0  1  0  0  0  0]

What version of the product are you using? On what operating system?
1.4.0

Please provide any additional information below.

Original issue reported on code.google.com by julien.michot.fr@gmail.com on 28 Nov 2012 at 10:27

GoogleCodeExporter commented 9 years ago
Btw, it was on Windows using msvc 2008 x86 and 
ceres::AutoDiffCostFunction<TestResidual not  
ceres::AutoDiffCostFunction<ConformalResidual

Original comment by julien.michot.fr@gmail.com on 28 Nov 2012 at 12:03

GoogleCodeExporter commented 9 years ago
thanks for reporting this.
this looks like a serious bug indeed.
looking now.

Original comment by sameerag...@google.com on 28 Nov 2012 at 6:58

GoogleCodeExporter commented 9 years ago
Fixed and sent in for review.
You can follow the progress at 

https://ceres-solver-review.googlesource.com/#/c/2130/

Original comment by sameerag...@google.com on 28 Nov 2012 at 8:02

GoogleCodeExporter commented 9 years ago
fixed and pushed to master.

Original comment by sameerag...@google.com on 28 Nov 2012 at 11:48

GoogleCodeExporter commented 9 years ago
very good, thx!

Original comment by julien.michot.fr@gmail.com on 29 Nov 2012 at 8:17