<commit_before>// __BEGIN_LICENSE__
// Copyright (C) 2006, 2007 United States Government as represented by
// the Administrator of the National Aeronautics and Space Administration.
// All Rights Reserved.
// __END_LICENSE__


/// \file Matrix.h
///
/// Provides the core Matrix<> mathematical matrix template classes.  
///
/// Currently I believe we support:
///   Element access via m(i,j) and m[i][j]
///   Seamless conversion between compatibile matrix types
///   Matrix addition, subtraction, and negation
///   Scalar multiplication and division
///   Matrix*matrix, matrix*vector, and vector*matrix products
///   Sum of elements via sum()
///   Trace via trace()
///   Determinant via det()
///   Transpose via transpose()
///   Inverse via inverse(), not particularly robust to singularity
///   Matrix norms via norm_1(), norm_inf(), and norm_frobenius()
///   Scalar addition and subtraction via elem_sum() and elem_dif()
///   Elementwise multiplication and division via elem_prod() and elem_quot()
///   One-line creation of identity matrices using identity_matrix()
///
/// We intentionally do *not* define matrix division using inverse(),
/// since users should probably avoid using inverse() anyway unless
/// they know what they are doing.  It's easy enough and preferable
/// for them to write an extra line of code to be explicit about what
/// they want, using e.g. the SVD.
///
#ifndef __VW_MATH_MATRIX_H__
#define __VW_MATH_MATRIX_H__

#include <boost/type_traits.hpp>
#include <boost/mpl/if.hpp>
#include <boost/utility/result_of.hpp>

#include <stack>

#include <vw/Core/Exception.h>
#include <vw/Math/Vector.h>

namespace vw {
namespace math {

  /// A type function to compute the number of rows of a matrix
  /// expression at compile time (or zero for dynamically-sized
  /// vectors).
  template <class MatrixT>
  struct MatrixRows {
    const static int value = 0;
  };

  /// A type function to compute the number of columns of a matrix
  /// expression at compile time (or zero for dynamically-sized
  /// vectors).
  template <class MatrixT>
  struct MatrixCols {
    const static int value = 0;
  };


  template <class MatrixT> class MatrixRow;
  template <class MatrixT> class MatrixCol;

  // *******************************************************************
  // class MatrixBase<MatrixT>
  // A CRTP matrix base class.
  // *******************************************************************

  /// A CRTP base class for matrices and matrix expressions.  
  /// Provides a mechanism for restricting function arguments to 
  /// matrices, and provides the various arithmetic assignment 
  /// operators and other member functions.
  template <class MatrixT>
  struct MatrixBase {

    /// Returns the derived implementation type.
    MatrixT& impl() { return *static_cast<MatrixT*>(this); }

    /// Returns the derived implementation type.
    MatrixT const& impl() const { return *static_cast<MatrixT const*>(this); }

    /// Sum-assignment operator
    template <class T>
    MatrixT& operator+=( T const& m ) {
      return impl() = impl() + m;
    }

    /// Difference-assignment operator
    template <class T>
    MatrixT& operator-=( T const& m ) {
      return impl() = impl() - m;
    }

    /// Product-assignment operator
    template <class T>
    MatrixT& operator*=( T s ) {
      return impl() = impl() * s;
    }

    /// Quotient-assignment operator
    template <class T>
    MatrixT& operator/=( T s ) {
      return impl() = impl() / s;
    }

    /// Access an individual matrix row, for further access using a second operator[].
    MatrixRow<MatrixT> operator[]( unsigned row ) {
      return MatrixRow<MatrixT>( impl(), row );
    }

    /// Access an individual matrix row, for further access using a second operator[].
    MatrixRow<const MatrixT> operator[]( unsigned row ) const {
      return MatrixRow<const MatrixT>( impl(), row );
    }

    /// Set the matrix to the identity matrix with the same dimensions.
    void set_identity() {
      VW_ASSERT( impl().rows()==impl().cols(), LogicErr() << "Only square matrices can be identity matrices." );
      int n=impl().rows();
      for( int i=0; i<n; ++i )
        for( int j=0; j<n; ++j )
          impl()(i,j)=(i==j)?(typename MatrixT::value_type(1)):(typename MatrixT::value_type(0));
    }

    /// Set the matrix to the identity matrix with the given dimensions.
    void set_identity( unsigned size ) {
      impl().set_size( size, size );
      set_identity();
    }

    /// Set the matrix to the identity matrix with the same dimensions.
    void set_zero() {
      int n=impl().rows();
      int m=impl().cols();
      for( int i=0; i<n; ++i )
        for( int j=0; j<m; ++j )
          impl()(i,j) = (typename MatrixT::value_type(0));
    }
  };
<commit_msg>Set all ones options for matrices. Matlab has it, why can't we?<commit_after>// __BEGIN_LICENSE__
// Copyright (C) 2006, 2007 United States Government as represented by
// the Administrator of the National Aeronautics and Space Administration.
// All Rights Reserved.
// __END_LICENSE__


/// \file Matrix.h
///
/// Provides the core Matrix<> mathematical matrix template classes.  
///
/// Currently I believe we support:
///   Element access via m(i,j) and m[i][j]
///   Seamless conversion between compatibile matrix types
///   Matrix addition, subtraction, and negation
///   Scalar multiplication and division
///   Matrix*matrix, matrix*vector, and vector*matrix products
///   Sum of elements via sum()
///   Trace via trace()
///   Determinant via det()
///   Transpose via transpose()
///   Inverse via inverse(), not particularly robust to singularity
///   Matrix norms via norm_1(), norm_inf(), and norm_frobenius()
///   Scalar addition and subtraction via elem_sum() and elem_dif()
///   Elementwise multiplication and division via elem_prod() and elem_quot()
///   One-line creation of identity matrices using identity_matrix()
///
/// We intentionally do *not* define matrix division using inverse(),
/// since users should probably avoid using inverse() anyway unless
/// they know what they are doing.  It's easy enough and preferable
/// for them to write an extra line of code to be explicit about what
/// they want, using e.g. the SVD.
///
#ifndef __VW_MATH_MATRIX_H__
#define __VW_MATH_MATRIX_H__

#include <boost/type_traits.hpp>
#include <boost/mpl/if.hpp>
#include <boost/utility/result_of.hpp>

#include <stack>

#include <vw/Core/Exception.h>
#include <vw/Math/Vector.h>

namespace vw {
namespace math {

  /// A type function to compute the number of rows of a matrix
  /// expression at compile time (or zero for dynamically-sized
  /// vectors).
  template <class MatrixT>
  struct MatrixRows {
    const static int value = 0;
  };

  /// A type function to compute the number of columns of a matrix
  /// expression at compile time (or zero for dynamically-sized
  /// vectors).
  template <class MatrixT>
  struct MatrixCols {
    const static int value = 0;
  };


  template <class MatrixT> class MatrixRow;
  template <class MatrixT> class MatrixCol;

  // *******************************************************************
  // class MatrixBase<MatrixT>
  // A CRTP matrix base class.
  // *******************************************************************

  /// A CRTP base class for matrices and matrix expressions.  
  /// Provides a mechanism for restricting function arguments to 
  /// matrices, and provides the various arithmetic assignment 
  /// operators and other member functions.
  template <class MatrixT>
  struct MatrixBase {

    /// Returns the derived implementation type.
    MatrixT& impl() { return *static_cast<MatrixT*>(this); }

    /// Returns the derived implementation type.
    MatrixT const& impl() const { return *static_cast<MatrixT const*>(this); }

    /// Sum-assignment operator
    template <class T>
    MatrixT& operator+=( T const& m ) {
      return impl() = impl() + m;
    }

    /// Difference-assignment operator
    template <class T>
    MatrixT& operator-=( T const& m ) {
      return impl() = impl() - m;
    }

    /// Product-assignment operator
    template <class T>
    MatrixT& operator*=( T s ) {
      return impl() = impl() * s;
    }

    /// Quotient-assignment operator
    template <class T>
    MatrixT& operator/=( T s ) {
      return impl() = impl() / s;
    }

    /// Access an individual matrix row, for further access using a second operator[].
    MatrixRow<MatrixT> operator[]( unsigned row ) {
      return MatrixRow<MatrixT>( impl(), row );
    }

    /// Access an individual matrix row, for further access using a second operator[].
    MatrixRow<const MatrixT> operator[]( unsigned row ) const {
      return MatrixRow<const MatrixT>( impl(), row );
    }

    /// Set the matrix to the identity matrix with the same dimensions.
    void set_identity() {
      VW_ASSERT( impl().rows()==impl().cols(), LogicErr() << "Only square matrices can be identity matrices." );
      int n=impl().rows();
      for( int i=0; i<n; ++i )
        for( int j=0; j<n; ++j )
          impl()(i,j)=(i==j)?(typename MatrixT::value_type(1)):(typename MatrixT::value_type(0));
    }

    /// Set the matrix to the identity matrix with the given dimensions.
    void set_identity( unsigned size ) {
      impl().set_size( size, size );
      set_identity();
    }

    /// Set the matrix to entirely zeros.
    void set_zero() {
      int n=impl().rows();
      int m=impl().cols();
      for( int i=0; i<n; ++i )
        for( int j=0; j<m; ++j )
          impl()(i,j) = (typename MatrixT::value_type(0));
    }

    // Set the entire matrix to ones
    void set_ones() {
      for( int i=0; i<impl().rows(); ++i )
	for( int j=0; j<impl().cols(); ++j )
	  impl()(i,j) = (typename MatrixT::value_type(1));
    }
  };

{'fraction_non_alphanumeric': 0.15054530628885945, 'fraction_numerical': 0.0039751299561716445, 'mean_word_length': 2.962843295638126, 'pattern_counts': {'":': 0, '<': 63, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7180676', 'n_tokens_mistral': 2853, 'n_tokens_neox': 2724, 'n_words': 1037}