Skip to content

Commit

Permalink
Restore operator().
Browse files Browse the repository at this point in the history
  • Loading branch information
pleroy committed Jan 10, 2024
1 parent ec2423a commit 00fc37c
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
7 changes: 7 additions & 0 deletions numerics/fixed_arrays.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ class FixedMatrix final {
bool operator==(FixedMatrix const& right) const;
bool operator!=(FixedMatrix const& right) const;

// Applies the matrix as a bilinear form. Present for compatibility with
// |SymmetricBilinearForm|. Prefer to use |TransposedView| and |operator*|.
template<typename LScalar, typename RScalar>
Product<Scalar, Product<LScalar, RScalar>>
operator()(FixedVector<LScalar, columns_> const& left,
FixedVector<RScalar, rows_> const& right) const;

static FixedMatrix Identity();

private:
Expand Down
9 changes: 9 additions & 0 deletions numerics/fixed_arrays_body.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,15 @@ bool FixedMatrix<Scalar, rows_, columns_>::operator!=(
return data_ != right.data_;
}

template<typename Scalar, int rows_, int columns_>
template<typename LScalar, typename RScalar>
Product<Scalar, Product<LScalar, RScalar>>
FixedMatrix<Scalar, rows_, columns_>::operator()(
FixedVector<LScalar, columns_> const& left,
FixedVector<RScalar, rows_> const& right) const {
return TransposedView{left} * (*this * right);

Check warning on line 205 in numerics/fixed_arrays_body.hpp

View workflow job for this annotation

GitHub Actions / check-cpp

whitespace/braces

Missing space before {
}

template<typename Scalar, int rows_, int columns_>
FixedMatrix<Scalar, rows_, columns_>
FixedMatrix<Scalar, rows_, columns_>::Identity() {
Expand Down
8 changes: 3 additions & 5 deletions numerics/gradient_descent_body.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "geometry/symmetric_bilinear_form.hpp"
#include "numerics/fixed_arrays.hpp"
#include "numerics/hermite2.hpp"
#include "numerics/transposed_view.hpp"
#include "quantities/elementary_functions.hpp"

namespace principia {
Expand All @@ -25,7 +24,6 @@ using namespace principia::geometry::_point;
using namespace principia::geometry::_symmetric_bilinear_form;
using namespace principia::numerics::_fixed_arrays;
using namespace principia::numerics::_hermite2;
using namespace principia::numerics::_transposed_view;
using namespace principia::quantities::_elementary_functions;

template<typename Scalar, typename S, int s>
Expand Down Expand Up @@ -333,9 +331,9 @@ absl::StatusOr<Argument> BroydenFletcherGoldfarbShanno(
// The formula (6.17) from [NW06] is inconvenient because it uses external
// products. Elementary transformations yield the formula below.
auto const ρ = 1 / sₖyₖ;
auto const Hₖ₊₁ = Hₖ + ρ * ((ρ * (TransposedView{yₖ} * (Hₖ * yₖ)) + 1) *
SymmetricSquare(sₖ) -
2 * SymmetricProduct(Hₖ * yₖ, sₖ));
auto const Hₖ₊₁ =
Hₖ + ρ * ((ρ * Hₖ(yₖ, yₖ) + 1) * SymmetricSquare(sₖ) -
2 * SymmetricProduct(Hₖ * yₖ, sₖ));

xₖ = xₖ₊₁;
grad_f_xₖ = grad_f_xₖ₊₁;
Expand Down
7 changes: 7 additions & 0 deletions numerics/unbounded_arrays.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ class UnboundedMatrix final {
bool operator==(UnboundedMatrix const& right) const;
bool operator!=(UnboundedMatrix const& right) const;

// Applies the matrix as a bilinear form. Present for compatibility with
// |SymmetricBilinearForm|. Prefer to use |TransposedView| and |operator*|.
template<typename LScalar, typename RScalar>
Product<Scalar, Product<LScalar, RScalar>>
operator()(UnboundedVector<LScalar> const& left,
UnboundedVector<RScalar> const& right) const;

static UnboundedMatrix Identity(int rows, int columns);

private:
Expand Down
9 changes: 9 additions & 0 deletions numerics/unbounded_arrays_body.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,15 @@ bool UnboundedMatrix<Scalar>::operator!=(UnboundedMatrix const& right) const {
return !(*this == right);
}

template<typename Scalar>
template<typename LScalar, typename RScalar>
Product<Scalar, Product<LScalar, RScalar>>
UnboundedMatrix<Scalar>::operator()(
UnboundedVector<LScalar> const& left,
UnboundedVector<RScalar> const& right) const {
return TransposedView{left} * (*this * right);

Check warning on line 221 in numerics/unbounded_arrays_body.hpp

View workflow job for this annotation

GitHub Actions / check-cpp

whitespace/braces

Missing space before {
}

template<typename Scalar>
UnboundedMatrix<Scalar>
UnboundedMatrix<Scalar>::Identity(int const rows, int const columns) {
Expand Down

0 comments on commit 00fc37c

Please sign in to comment.