Add tensor classes for higher order singular value decomposition.
2nd, 3rd, 4th, and 5th order tensors are available.

git-svn-id: 3507153f7f2a502978d43a270f21b34bb2e07470@1332 b31369ee-dac5-0310-8161-cccb92f82ee5

error: pathspec 'mist/tensor.h' did not match any file(s) known to git

--- mist/tensor.h
+++ mist/tensor.h
@@ -0,0 +1,1265 @@
+//
+// Copyright (c) 2003-2009, MIST Project, Intelligent Media Integration COE, Nagoya University
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification,
+// are permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+// this list of conditions and the following disclaimer in the documentation
+// and/or other materials provided with the distribution.
+//
+// 3. Neither the name of the Nagoya University nor the names of its contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
+// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+// IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+
+
+
+/// @file mist/tensor.h
+//!
+//! @brief Tensor classes for higher-order singular value decomposition
+//!
+//! 2nd, 3rd, 4th, and 5th order tensors are available.
+//!
+#ifndef __INCLUDE_MIST_TENSOR__
+#define __INCLUDE_MIST_TENSOR__
+
+#ifndef __INCLUDE_MIST_H__
+#include "mist.h"
+#endif
+
+#ifndef __INCLUDE_MIST_MATRIX__
+#include "matrix.h"
+#endif
+
+#ifndef __INCLUDE_NUMERIC__
+#include "numeric.h"
+#endif
+
+#include <numeric>
+#include <functional>
+
+
+// beginning of mist namespace
+_MIST_BEGIN
+
+
+template< int M, typename V, typename A >
+class tensor;
+
+namespace __tensor__
+{
+	template< int M, typename V, typename A >
+	class _base_
+	{
+	protected:
+		typedef V value_type;
+		typedef A allocator;
+		typedef typename array< value_type, allocator >::size_type size_type;
+		typedef matrix< V, A > matrix_type;
+
+		size_type _mode;
+		array< size_type > _ranks;
+		array< value_type, allocator > _data;
+
+		template< typename MV, typename MA >
+		void _fold( const size_type &m, const matrix< MV, MA > &mat )
+		{
+			array< size_type > i( _mode ), d( _mode );
+			for( size_type ii = 0 ; ii < _mode ; d[ ii ] = _diff( ii ), ii ++ );
+			for( typename matrix_type::size_type c = 0 ; c < mat.cols( ) ; c ++ )
+			{
+				for( typename matrix_type::size_type r = i[ m - 1 ] = 0 ; r < mat.rows( ) ; r ++, i[ m - 1 ] ++ )
+				{
+					operator [ ]( ::std::inner_product( &i[ 0 ], &i[ 0 ] + i.size( ), &d[ 0 ], 0 ) ) = mat( r, c );
+				}
+				_inc( m % _mode, m - 1, i );
+			}
+		}
+
+	private:
+		size_type _diff( const size_type &i  ) const
+		{
+			return i == 0 ? 1 : _ranks[ i - 1 ] * _diff( i - 1 );
+		}
+		void _inc( const size_type &m, const size_type &em, array< size_type > &i ) const
+		{
+			if( m != em && ++ i[ m ] == _ranks[ m ] )
+			{
+				i[ m ] = 0;
+				_inc( ( m + 1 ) % _mode, em, i );
+			}
+		}
+		void _out( ::std::ostream &o, const array< size_type > &d, array< size_type > &i, const size_type &m  ) const
+		{
+			for( i[ m ] = 0 ; i[ m ] < _ranks[ m ] ; i[ m ] ++ )
+			{
+				if( m != 0 )
+				{
+					i[ m ] != 0 ? o << std::endl : o;
+					for( size_type ii = 0 ; ii < _mode - m - 1 ; o << "  ", ii ++ );
+					m > 1 ?  o << i[ m ] + 1 << " ----------" << ::std::endl : o;
+					_out( o, d, i, m - 1 );
+				}
+				else
+				{
+					o << operator [ ]( ::std::inner_product( &i[ 0 ], &i[ 0 ] + _mode, &d[ 0 ], 0 ) );
+					i[ m ] != _ranks[ m ] - 1 ? o << ", " : o;
+				}
+			}
+		}
+
+	protected:
+		const size_type mode( ) const
+		{
+			return  _mode;
+		}
+		const size_type rank( const size_type &m ) const
+		{
+			return _ranks[ m - 1 ];
+		}
+		const size_type size( ) const
+		{
+			return _data.size( );
+		}
+		value_type &operator [ ]( const size_type &i )
+		{
+			return _data[ i ];
+		}
+		const value_type &operator [ ]( const size_type &i ) const
+		{
+			return _data[ i ];
+		}
+		matrix_type unfold( const size_type &m ) const
+		{
+			array< size_type > i( _mode ), d( _mode );
+			for( size_type ii = 0 ; ii < _mode ; d[ ii ] = _diff( ii ), ii ++ );
+			matrix_type mat( _ranks[ m - 1 ], _data.size( ) / _ranks[ m - 1 ] );
+			for( typename matrix_type::size_type c = 0 ; c < mat.cols( ) ; c ++ )
+			{
+				for( typename matrix_type::size_type r = i[ m - 1 ] = 0 ; r < mat.rows( ) ; r ++, i[ m - 1 ] ++ )
+				{
+					mat( r, c ) = operator [ ]( ::std::inner_product( &i[ 0 ], &i[ 0 ] + i.size( ), &d[ 0 ], 0 ) );
+				}
+				_inc( m % _mode, m - 1, i );
+			}
+			return mat;
+		}
+		void out( ::std::ostream &o ) const
+		{
+			array< size_type > i( _mode ), d( _mode );
+			for( size_type ii = 0 ; ii < _mode ; d[ ii ] = _diff( ii ), ii ++ );
+			_out( o, d, i, _mode - 1 );
+		}
+
+		_base_( ) : _mode( M ), _ranks( array< size_type >( M ) )
+		{
+		}
+	};
+
+	template< int M, typename V, typename A >
+	class _data_ : public _base_< M, V, A >
+	{
+		_data_( )
+		{
+		}
+	};
+
+	/*******************************************/
+	/*                                         */
+	/*          for 2nd order tensor           */
+	/*                                         */
+	/*******************************************/
+	template< typename V, typename A >
+	class _data_< 2, V, A >
+	{
+		template< int FM, typename FV, typename FA >
+		friend class tensor;
+
+		typedef V value_type;
+		typedef A allocator;
+		typedef matrix< V, A > matrix_type;
+		typedef typename matrix_type::size_type size_type;
+
+		matrix_type _mat;
+
+		const size_type mode( ) const
+		{
+			return  2;
+		}
+		const size_type rank( const size_type &m ) const
+		{
+			return m == 1 ? _mat.rows( ) : _mat.cols( );
+		}
+		const size_type size( ) const
+		{
+			return _mat.size( );
+		}
+		void _resize( const size_type &r1, const size_type &r2 )
+		{
+			_mat.resize( r1, r2 );
+		}
+		void resize( const size_type &r1, const size_type &r2 )
+		{
+			_resize( r1, r2 );
+			_mat.fill( );
+		}
+		value_type &operator [ ]( const size_type &i )
+		{
+			return _mat[ i ];
+		}
+		const value_type &operator [ ]( const size_type &i ) const
+		{
+			return _mat[ i ];
+		}
+		value_type &operator ( )( const size_type &i1, const size_type &i2 )
+		{
+			return _mat( i1, i2 );
+		}
+		const value_type &operator ( )( const size_type &i1, const size_type &i2 ) const
+		{
+			return _mat( i1, i2 );
+		}
+		template< typename MV, typename MA >
+		_data_< 2, V, A > fold( const size_type &m, const matrix< MV, MA > &mat ) const
+		{
+			return _data_< 2, V, A >( m == 1 ? mat : mat.t( ) );
+		}
+		matrix_type unfold( const size_type &m ) const
+		{
+			return m == 1 ? _mat : _mat.t( );
+		}
+		void out( ::std::ostream &o ) const
+		{
+			o << _mat.t( );
+		}
+		template< typename AV, typename AA >
+		_data_< 2, V, A >( const size_t &r1, const size_t &r2, const array< AV, AA > &data ) : _mat( matrix_type( r1, r2 ) )
+		{
+			::std::copy( &data[ 0 ], &data[ 0 ] + data.size( ), &_mat[ 0 ] );
+		}
+		template< typename AV, typename AA >
+		_data_< 2, V, A >( const array2< AV, AA > &img ) : _mat( matrix_type( img.width( ), img.height( ) ) )
+		{
+			::std::copy( &img[ 0 ], &img[ 0 ] + img.size( ), &_mat[ 0 ] );
+		}
+		template< typename MV, typename MA >
+		_data_< 2, V, A >( const matrix< MV, MA > &mat ) : _mat( mat )
+		{
+		}
+		_data_< 2, V, A >( const size_type &r1, const size_type &r2 ) : _mat( matrix_type( r1, r2 ) )
+		{
+		}
+		_data_< 2, V, A >( ) : _mat( matrix_type( ) )
+		{
+		}
+	};
+
+	/*******************************************/
+	/*                                         */
+	/*          for 3rd order tensor           */
+	/*                                         */
+	/*******************************************/
+	template< typename V, typename A >
+	class _data_< 3, V, A > : public _base_< 3, V, A >
+	{
+		template< int FM, typename FV, typename FA >
+		friend class tensor;
+
+		typedef _base_< 3, V, A > base;
+		typedef typename base::value_type value_type;
+		typedef typename base::size_type size_type;
+
+		void _resize( const size_type &r1, const size_type &r2, const size_type &r3 )
+		{
+			if( base::_ranks[ 0 ] != r1 || base::_ranks[ 1 ] != r2 || base::_ranks[ 2 ] != r3 )
+			{
+				base::_ranks[ 0 ] = r1;
+				base::_ranks[ 1 ] = r2;
+				base::_ranks[ 2 ] = r3;
+				base::_data.resize( r1 * r2 * r3 );
+			}
+		}
+		void resize( const size_type &r1, const size_type &r2, const size_type &r3 )
+		{
+			_resize( r1, r2, r3 );
+			base::_data.fill( );
+		}
+		value_type &operator ( )( const size_type &i1, const size_type &i2, const size_type &i3 )
+		{
+			return base::_data[ i1 + i2 * base::_ranks[ 0 ] + i3 * base::_ranks[ 0 ] * base::_ranks[ 1 ] ];
+		}
+		const value_type &operator ( )( const size_type &i1, const size_type &i2, const size_type &i3 ) const
+		{
+			return base::_data[ i1 + i2 * base::_ranks[ 0 ] + i3 * base::_ranks[ 0 ] * base::_ranks[ 1 ] ];
+		}
+		template< typename MV, typename MA >
+		_data_< 3, V, A > fold( const size_type &m, const matrix< MV, MA > &mat ) const
+		{
+			_data_< 3, V, A > ret( base::_ranks[ 0 ], base::_ranks[ 1 ], base::_ranks[ 2 ] );
+			ret._ranks[ m - 1 ] = mat.rows( );
+			ret._resize( base::_ranks[ 0 ], base::_ranks[ 1 ], base::_ranks[ 2 ] );
+			ret._fold( m, mat );
+			return ret;
+		}
+		template< typename AV, typename AA >
+		_data_< 3, V, A >( const size_type &r1, const size_type &r2, const size_type &r3, const array< AV, AA > &data )
+		{
+			_resize( r1, r2, r3 );
+			::std::copy( &data[ 0 ], &data[ 0 ] + data.size( ), &base::_data[ 0 ] );
+		}
+		_data_< 3, V, A >( const size_type &r1, const size_type &r2, const size_type &r3 )
+		{
+			_resize( r1, r2, r3 );
+		}
+		template< typename TV, typename TA, typename AA >
+		_data_< 3, V, A >( const array< tensor< 2, TV, TA >, AA > &ts )
+		{
+			_resize( ts[ 0 ].rank( 1 ), ts[ 0 ].rank( 2 ), ts.size( ) );
+			for( size_type i = 0 ; i < ts.size( ) ; i ++ )
+			{
+				::std::copy( &ts[ i ][ 0 ], &ts[ i ][ 0 ] + ts[ 0 ].size( ), &base::_data[ i * ts[ 0 ].size( ) ] );
+			}
+		}
+		_data_< 3, V, A >( )
+		{
+		}
+	};
+
+	/*******************************************/
+	/*                                         */
+	/*          for 4th order tensor           */
+	/*                                         */
+	/*******************************************/
+	template< typename V, typename A >
+	class _data_< 4, V, A > : public _base_< 4, V, A >
+	{
+		template< int FM, typename FV, typename FA >
+		friend class tensor;
+
+		typedef _base_< 4, V, A > base;
+		typedef typename base::value_type value_type;
+		typedef typename base::size_type size_type;
+
+		void _resize( const size_type &r1, const size_type &r2, const size_type &r3, const size_type &r4 )
+		{
+			if( base::_ranks[ 0 ] != r1 || base::_ranks[ 1 ] != r2 || base::_ranks[ 2 ] != r3 || base::_ranks[ 3 ] != r4 )
+			{
+				base::_ranks[ 0 ] = r1;
+				base::_ranks[ 1 ] = r2;
+				base::_ranks[ 2 ] = r3;
+				base::_ranks[ 3 ] = r4;
+				base::_data.resize( r1 * r2 * r3 * r4 );
+			}
+		}
+		void resize( const size_type &r1, const size_type &r2, const size_type &r3, const size_type &r4 )
+		{
+			_resize( r1, r2, r3, r4 );
+			base::_data.fill( );
+		}
+		value_type &operator ( )( const size_type &i1, const size_type &i2, const size_type &i3, const size_type &i4 )
+		{
+			return base::_data[ i1 + i2 * base::_ranks[ 0 ] + i3 * base::_ranks[ 0 ] * base::_ranks[ 1 ] + i4 * base::_ranks[ 0 ] * base::_ranks[ 1 ] * base::_ranks[ 2 ] ];
+		}
+		const value_type &operator ( )( const size_type &i1, const size_type &i2, const size_type &i3, const size_type &i4 ) const
+		{
+			return base::_data[ i1 + i2 * base::_ranks[ 0 ] + i3 * base::_ranks[ 0 ] * base::_ranks[ 1 ] + i4 * base::_ranks[ 0 ] * base::_ranks[ 1 ] * base::_ranks[ 2 ] ];
+		}
+		template< typename MV, typename MA >
+		_data_< 4, V, A > fold( const size_type &m, const matrix< MV, MA > &mat ) const
+		{
+			_data_< 4, V, A > ret( base::_ranks[ 0 ], base::_ranks[ 1 ], base::_ranks[ 2 ], base::_ranks[ 3 ] );
+			ret.base::_ranks[ m - 1 ] = mat.rows( );
+			ret._resize( base::_ranks[ 0 ], base::_ranks[ 1 ], base::_ranks[ 2 ], base::_ranks[ 3 ] );
+			ret._fold( m, mat );
+			return ret;
+		}
+		template< typename AV, typename AA >
+		_data_< 4, V, A >( const size_type &r1, const size_type &r2, const size_type &r3, const size_type &r4, const array< AV, AA > &data )
+		{
+			_resize( r1, r2, r3, r4 );
+			::std::copy( &data[ 0 ], &data[ 0 ] + data.size( ), &base::_data[ 0 ] );
+		}
+		_data_< 4, V, A >( const size_type &r1, const size_type &r2, const size_type &r3, const size_type &r4 )
+		{
+			_resize( r1, r2, r3, r4 );
+		}
+		template< typename TV, typename TA, typename AA >
+		_data_< 4, V, A >( const array< tensor< 3, TV, TA >, AA > &ts )
+		{
+			_resize( ts[ 0 ].rank( 1 ), ts[ 0 ].rank( 2 ), ts[ 0 ].rank( 3 ), ts.size( ) );
+			for( size_type i = 0 ; i < ts.size( ) ; i ++ )
+			{
+				::std::copy( &ts[ i ][ 0 ], &ts[ i ][ 0 ] + ts[ 0 ].size( ), &base::_data[ i * ts[ 0 ].size( ) ] );
+			}
+		}
+		_data_< 4, V, A >( )
+		{
+		}
+	};
+
+	/*******************************************/
+	/*                                         */
+	/*          for 5th order tensor           */
+	/*                                         */
+	/*******************************************/
+	template< typename V, typename A >
+	class _data_< 5, V, A > : public _base_< 5, V, A >
+	{
+		template< int FM, typename FV, typename FA >
+		friend class tensor;
+
+		typedef _base_< 5, V, A > base;
+		typedef typename base::value_type value_type;
+		typedef typename base::size_type size_type;
+
+		void _resize( const size_type &r1, const size_type &r2, const size_type &r3, const size_type &r4, const size_type &r5 )
+		{
+			if( base::_ranks[ 0 ] != r1 || base::_ranks[ 1 ] != r2 || base::_ranks[ 2 ] != r3 || base::_ranks[ 3 ] != r4 || base::_ranks[ 4 ] != r5 )
+			{
+				base::_ranks[ 0 ] = r1;
+				base::_ranks[ 1 ] = r2;
+				base::_ranks[ 2 ] = r3;
+				base::_ranks[ 3 ] = r4;
+				base::_ranks[ 4 ] = r5;
+				base::_data.resize( r1 * r2 * r3 * r4 * r5 );
+			}
+		}
+		void resize( const size_type &r1, const size_type &r2, const size_type &r3, const size_type &r4, const size_type &r5 )
+		{
+			_resize( r1, r2, r3, r4, r5 );
+			base::_data.fill( );
+		}
+		value_type &operator ( )( const size_type &i1, const size_type &i2, const size_type &i3, const size_type &i4, const size_type &i5 )
+		{
+			return base::_data[ i1 + i2 * base::_ranks[ 0 ] + i3 * base::_ranks[ 0 ] * base::_ranks[ 1 ] + i4 * base::_ranks[ 0 ] * base::_ranks[ 1 ] * base::_ranks[ 2 ] + i5 * base::_ranks[ 0 ] * base::_ranks[ 1 ] * base::_ranks[ 2 ] * base::_ranks[ 3 ] ];
+		}
+		const value_type &operator ( )( const size_type &i1, const size_type &i2, const size_type &i3, const size_type &i4, const size_type &i5 ) const
+		{
+			return base::_data[ i1 + i2 * base::_ranks[ 0 ] + i3 * base::_ranks[ 0 ] * base::_ranks[ 1 ] + i4 * base::_ranks[ 0 ] * base::_ranks[ 1 ] * base::_ranks[ 2 ] + i5 * base::_ranks[ 0 ] * base::_ranks[ 1 ] * base::_ranks[ 2 ] * base::_ranks[ 3 ] ];
+		}
+		template< typename MV, typename MA >
+		_data_< 5, V, A > fold( const size_type &m, const matrix< MV, MA > &mat ) const
+		{
+			_data_< 5, V, A > ret( base::_ranks[ 0 ], base::_ranks[ 1 ], base::_ranks[ 2 ], base::_ranks[ 3 ], base::_ranks[ 4 ] );
+			ret.base::_ranks[ m - 1 ] = mat.rows( );
+			ret._resize( base::_ranks[ 0 ], base::_ranks[ 1 ], base::_ranks[ 2 ], base::_ranks[ 3 ], base::_ranks[ 4 ] );
+			ret._fold( m, mat );
+			return ret;
+		}
+		template< typename AV, typename AA >
+		_data_< 5, V, A >( const size_type &r1, const size_type &r2, const size_type &r3, const size_type &r4, const size_type &r5, const array< AV, AA > &data )
+		{
+			_resize( r1, r2, r3, r4, r5 );
+			::std::copy( &data[ 0 ], &data[ 0 ] + data.size( ), &base::_data[ 0 ] );
+		}
+		_data_< 5, V, A >( const size_type &r1, const size_type &r2, const size_type &r3, const size_type &r4, const size_type &r5 )
+		{
+			_resize( r1, r2, r3, r4, r5 );
+		}
+		template< typename TV, typename TA, typename AA >
+		_data_< 5, V, A >( const array< tensor< 4, TV, TA >, AA > &ts )
+		{
+			_resize( ts[ 0 ].rank( 1 ), ts[ 0 ].rank( 2 ), ts[ 0 ].rank( 3 ), ts[ 0 ].rank( 4 ), ts.size( ) );
+			for( size_type i = 0 ; i < ts.size( ) ; i ++ )
+			{
+				::std::copy( &ts[ i ][ 0 ], &ts[ i ][ 0 ] + ts[ 0 ].size( ), &base::_data[ i * ts[ 0 ].size( ) ] );
+			}
+		}
+		_data_< 5, V, A >( )
+		{
+		}
+	};
+}
+
+/// @brief Tensor class
+//!
+//! An N-th order tensor T has mode-ranks I_1, I_2, ..., I_N
+//! and belongs to the product space R^{I_1 \times I_2 \times ... \times I_N}.
+//!
+//! @param M  integer parameter to assign tensor's order (number of modes)
+//! @param V  data type parameter used as tensor's element type
+//! @param A  allocator type paramerter used by mist containers
+//!
+template< int M, typename V, typename A = ::std::allocator< V > >
+class tensor
+{
+	typedef matrix< V, A > matrix_type;
+	typedef typename __tensor__::_data_< M, V, A > data_type;
+
+public:
+	typedef V value_type;   ///< @brief data type of tensor's elements
+	typedef A allocator;    ///< @brief allocator type of mist containers
+	typedef typename data_type::size_type size_type;   ///< @brief unsigned integer type used for contener size or data index (same as size_t)
+
+private:
+	data_type _d;
+
+	bool _is_valid( const size_type &m ) const
+	{
+		return 0 < m && m <= mode( );
+	}
+	template< typename TV, typename TA >
+	bool _is_same_size( const tensor< M, TV, TA > &t ) const
+	{
+		for( size_type i = 1 ; i <= mode( ) ; i ++ )
+		{
+			if( rank( i ) != t.rank( i ) )
+			{
+				return false;
+			}
+		}
+		return true;
+	}
+	template< typename MV, typename MA >
+	tensor< M, V, A > _fold( const size_type &m, const matrix< MV, MA > &mat ) const
+	{
+		tensor< M, V, A > ret;
+		ret._d = _d.fold( m, mat );
+		return ret;
+	}
+	matrix_type _unfold( const size_type &m ) const
+	{
+		return _d.unfold( m );
+	}
+	template< typename MV, typename MA >
+	tensor< M, V, A > _x( const size_type &m, const matrix< MV, MA > &mat ) const
+	{
+		return _fold( m, mat * _unfold( m ) );
+	}
+
+public:
+	/// @brief return the number of tensor's modes
+	const size_type mode( ) const
+	{
+		return _d.mode( );
+	}
+	/// @brief return a mode rank of the tensor for each mode
+	//!
+	//! @param[in] mode  mode value to obtain the corresponding tensor's rank
+	//! @return          the tensor's rank corresponding to the mode
+	//!
+	const size_type rank( const size_type &mode ) const
+	{
+		if( _is_valid( mode ) )
+		{
+			return _d.rank( mode );
+		}
+		else
+		{
+			::std::cerr << "can't obtain rank" << ::std::endl;
+			return 0;
+		}
+	}
+	/// @brief return the number of tensor's elements
+	const size_type size( ) const
+	{
+		return _d.size( );
+	}
+	/// @brief return the i-th element of the tensor without depending on the number of modes
+	//!
+	//! @param[in] i  index to specify tensor's element
+	//! @return       the i-th element of the tensor
+	//!
+	value_type &operator [ ]( const size_type &i )
+	{
+		return _d[ i ];
+	}
+	/// @brief return the i-th element of the tensor without depending on the number of modes
+	//!
+	//! @param[in] i  index to specify tensor's element
+	//! @return       the i-th element of the tensor
+	//!
+	const value_type &operator [ ]( const size_type &i ) const
+	{
+		return _d[ i ];
+	}
+	/// @brief return a matrix form of the tensor obtained by unfolding it for each mode
+	//!
+	//! For a tensor T in R^{I_1 \times I_2 \times ... \times I_N},
+	//! n-mode-unfolding means constructing a matrix T_n from T
+	//! so that T_n consits of I_n dimensional column vectors
+	//! and the number of vectors is I_1 \times I_2 \times ... \times I_{n-1} \times I_{n+1} \times ... \times I_N.
+	//!
+	//! @param[in] mode  mode value to unfold the tensor
+	//! @return          the the matrix obtained by unfolding the tensor
+	//!
+	matrix_type unfold( const size_type &mode ) const
+	{
+		if( _is_valid( mode ) )
+		{
+			return _unfold( mode );
+		}
+		else
+		{
+			::std::cerr << "can't unfold tensor" << ::std::endl;
+			return matrix_type( );
+		}
+	}
+	/// @brief return a mode-product between the tensor and a matrix
+	//!
+	//! An n-mode-product between a tensor T and a matrix M is denoted as T \times_n M.
+	//! Using n-mode-unfolding matrix T_n, elements of the mode-product are calculated by M T_n.
+	//!
+	//! @param[in] mode  mode value to determine the direction of multiplication
+	//! @return          the mode-product
+	//!
+	template< typename MV, typename MA >
+	tensor< M, V, A > x( const size_type &mode, const matrix< MV, MA > &mat ) const
+	{
+		if( _is_valid( mode ) )
+		{
+			return _x( mode, mat );
+		}
+		else
+		{
+			::std::cerr << "can't obtain n-mode product" << ::std::endl;
+			return tensor< M, V, A >( );
+		}
+	}
+	void out( ::std::ostream &o ) const
+	{
+		_d.out( o );
+	}
+	/// @brief equivalence operator
+	template< typename TV, typename TA >
+	bool operator ==( const tensor< M, TV, TA > &t ) const
+	{
+		if( !_is_same_size( t ) )
+		{
+			return false;
+		}
+		else
+		{
+			for( size_type i = 0 ; i < size( ) ; i ++ )
+			{
+				if( operator [ ]( i ) != t[ i ] )
+				{
+					return false;
+				}
+			}
+			return true;
+		}
+	}
+	/// @brief non-equivalence operator
+	template< typename TV, typename TA >
+	bool operator !=( const tensor< M, TV, TA > &t ) const
+	{
+		return !operator ==( t );
+	}
+	/// @brief addision assignment operator to add a tensor to the tensor
+	template< typename TV, typename TA >
+	const tensor< M, V, A > &operator +=( const tensor< M, TV, TA > &t )
+	{
+		if( _is_same_size( t ) )
+		{
+			::std::transform( &operator [ ]( 0 ), &operator [ ]( 0 ) + size( ), &t[ 0 ], &operator [ ]( 0 ), ::std::plus< value_type >( ) );
+		}
+		else
+		{
+			::std::cerr << "can't add tensors" << ::std::endl;
+		}
+		return *this;
+	}
+	/// @brief subtraction assignment operator to subtract a tensor from the tensor
+	template< typename TV, typename TA >
+	const tensor< M, V, A > &operator -=( const tensor< M, TV, TA > &t )
+	{
+		if( _is_same_size( t ) )
+		{
+			::std::transform( &operator [ ]( 0 ), &operator [ ]( 0 ) + size( ), &t[ 0 ], &operator [ ]( 0 ), ::std::minus< value_type >( ) );
+		}
+		else
+		{
+			::std::cerr << "can't subtract tensors" << ::std::endl;
+		}
+		return *this;
+	}
+	/// @brief multiplication assignment operator to multiply the tensor by a value
+	template< typename VV >
+	const tensor< M, V, A > &operator *=( const VV &v )
+	{
+		::std::transform( &operator [ ]( 0 ), &operator [ ]( 0 ) + size( ), &operator [ ]( 0 ), ::std::bind2nd( ::std::multiplies< value_type >( ), v ) );
+		return *this;
+	}
+	/// @brief division assignment operator to divide the tensor by a value
+	template< typename VV >
+	const tensor< M, V, A > &operator /=( const VV &v )
+	{
+		::std::transform( &operator [ ]( 0 ), &operator [ ]( 0 ) + size( ), &operator [ ]( 0 ), ::std::bind2nd( ::std::divides< value_type >( ), v ) );
+		return *this;
+	}
+	/// @brief construct a tensor (default constructer)
+	tensor< M, V, A >( ) : _d( )
+	{
+	}
+
+
+	/*******************************************/
+	/*                                         */
+	/*          for 2nd order tensor           */
+	/*                                         */
+	/*******************************************/
+
+	/// @brief resize the 2nd order tensor
+	//!
+	//! @param[in] rank1  1st mode rank after this operation
+	//! @param[in] rank2  2nd mode rank after this operation
+	//!
+	void resize( const size_type &rank1, const size_type &rank2 )
+	{
+		_d.resize( rank1, rank2 );
+	}
+	/// @brief return a element of the 2nd order tensor for each pair of indices
+	//!
+	//! @param[in] i1  index for the 1st mode
+	//! @param[in] i2  index for the 2nd mode
+	//! @return        the element corresponding to the indices
+	//!
+	value_type &operator ( )( const size_type &i1, const size_type &i2 )
+	{
+		return _d( i1, i2 );
+	}
+	/// @brief return a element of the 2nd order tensor for each pair of indices
+	//!
+	//! @param[in] i1  index for the 1st mode
+	//! @param[in] i2  index for the 2nd mode
+	//! @return        the element corresponding to the indices
+	//!
+	const value_type &operator ( )( const size_type &i1, const size_type &i2 ) const
+	{
+		return _d( i1, i2 );
+	}
+	/// @brief apply higher order singular value decomposition (HOSVD) to the 2nd order tensor
+	//!
+	//! HOSVD decomposes a 2nd order tensor T as T = Z \times_1 U_1 \times_2 U_2.
+	//! Here U_1 and U_2 are unitary matrices and a 2nd order tensor Z is called as a core tensor.
+	//! Using 1-mode-unfolding matrix of T, this is described like SVD of a matrix as T_1 = U1 S U2^t
+	//! Here S is a singular value matrix.
+	//!
+	//! @param[in,out] z   core tensor of the tensor
+	//! @param[in,out] u1  unitary matrix corresponding to the 1st mode
+	//! @param[in,out] u2  unitary matrix corresponding to the 2nd mode
+	//!
+	template< typename MV, typename MA >
+	void hosvd( tensor< M, V, A > &z, matrix< MV, MA > &u1, matrix< MV, MA > &u2 ) const
+	{
+		matrix< MV, MA > s;
+		svd( _unfold( 1 ), u1, s, u2 );
+		z = _x( 1, u1.dagger( ) )._x( 2, u2 );
+		u2 = u2.dagger( );
+	}
+	/// @brief construct a 2nd order tensor
+	//!
+	//! @param[in] rank1  1st mode rank
+	//! @param[in] rank2  2nd mode rank
+	//! @param[in] data   data to assign initial values to elements of the tensor
+	//!
+	template< typename AV, typename AA >
+	tensor< M, V, A >( const size_type &rank1, const size_type &rank2, const array< AV, AA > &data ) : _d( rank1, rank2, data )
+	{
+	}
+	/// @brief construct a 2nd order tensor from an image
+	//!
+	//! Width and height of the image are assigned to the 1st and 2nd mode ranks respectively.
+	//!
+	//! @param[in] img  image to assign initial values to elements of the tensor
+	//!
+	template< typename AV, typename AA >
+	tensor< M, V, A >( const array2< AV, AA > &img ) : _d( img.width( ), img.height( ), img )
+	{
+	}
+	/// @brief construct a 2nd order tensor from a matrix
+	//!
+	//! Numbers of rows and cols of the matrix are assigned to the 1st and 2nd mode ranks respectively.
+	//!
+	//! @param[in] mat  matrix to assign initial values to elements of the tensor
+	//!
+	template< typename MV, typename MA >
+	tensor< M, V, A >( const matrix< MV, MA > &mat ) : _d( mat )
+	{
+	}
+	/// @brief construct a 2nd order tensor
+	//!
+	//! @param[in] rank1  1st mode rank
+	//! @param[in] rank2  2nd mode rank
+	//!
+	tensor< M, V, A >( const size_type &rank1, const size_type &rank2 ) : _d( rank1, rank2 )
+	{
+	}
+
+
+	/*******************************************/
+	/*                                         */
+	/*          for 3rd order tensor           */
+	/*                                         */
+	/*******************************************/
+
+	/// @brief resize the 3rd order tensor
+	//!
+	//! @param[in] rank1  1st mode rank after this operation
+	//! @param[in] rank2  2nd mode rank after this operation
+	//! @param[in] rank3  3rd mode rank after this operation
+	//!
+	void resize( const size_type &rank1, const size_type &rank2, const size_type &rank3 )
+	{
+		_d.resize( rank1, rank2, rank3 );
+	}
+	/// @brief return a element of the 3rd order tensor for each set of indices
+	//!
+	//! @param[in] i1  index of the 1st mode
+	//! @param[in] i2  index of the 2nd mode
+	//! @param[in] i3  index of the 3rd mode
+	//! @return        the element corresponding to the indices
+	//!
+	value_type &operator ( )( const size_type &i1, const size_type &i2, const size_type &i3 )
+	{
+		return _d( i1, i2, i3 );
+	}
+	/// @brief return a element of the 3rd order tensor for each set of indices
+	//!
+	//! @param[in] i1  index of the 1st mode
+	//! @param[in] i2  index of the 2nd mode
+	//! @param[in] i3  index of the 3rd mode
+	//! @return        the element corresponding to the indices
+	//!
+	const value_type &operator ( )( const size_type &i1, const size_type &i2, const size_type &i3 ) const
+	{
+		return _d( i1, i2, i3 );
+	}
+	/// @brief apply higher order singular value decomposition (HOSVD) to the 3rd order tensor
+	//!
+	//! HOSVD decomposes a 3rd order tensor T as T = Z \times_1 U_1 \times_2 U_2 \times_3 U_3.
+	//! Here U_1, U_2, and U_3 are unitary matrices and a 3rd order tensor Z is called as a core tensor.
+	//!
+	//! @param[in,out] z   core tensor of the tensor
+	//! @param[in,out] u1  unitary matrix corresponding to the 1st mode
+	//! @param[in,out] u2  unitary matrix corresponding to the 2nd mode
+	//! @param[in,out] u3  unitary matrix corresponding to the 3rd mode
+	//!
+	template< typename MV, typename MA >
+	void hosvd( tensor< M, V, A > &z, matrix< MV, MA > &u1, matrix< MV, MA > &u2, matrix< MV, MA > &u3 ) const
+	{
+		matrix< MV, MA > s, tmp;
+		svd( _unfold( 1 ), u1, s, tmp );
+		svd( _unfold( 2 ), u2, s, tmp );
+		svd( _unfold( 3 ), u3, s, tmp );
+		z = _x( 1, u1.dagger( ) )._x( 2, u2.dagger( ) )._x( 3, u3.dagger( ) );
+	}
+	/// @brief construct a 3rd order tensor
+	//!
+	//! @param[in] rank1  1st mode rank
+	//! @param[in] rank2  2nd mode rank
+	//! @param[in] rank3  3rd mode rank
+	//! @param[in] data   data to assign initial values to elements of the tensor
+	//!
+	template< typename AV, typename AA >
+	tensor< M, V, A >( const size_type &rank1, const size_type &rank2, const size_type &rank3, const array< AV, AA > &data ) : _d( rank1, rank2, rank3, data )
+	{
+	}
+	/// @brief construct a 3rd order tensor
+	//!
+	//! @param[in] rank1  1st mode rank
+	//! @param[in] rank2  2nd mode rank
+	//! @param[in] rank3  3rd mode rank
+	//!
+	tensor< M, V, A >( const size_type &rank1, const size_type &rank2, const size_type &rank3 ) : _d( rank1, rank2, rank3 )
+	{
+	}
+	/// @brief construct a 3rd order tensor from an array of 2nd order tensors
+	//!
+	//! @param[in] ts  array of 2nd order tensors
+	//!
+	template< typename TV, typename TA, typename AA >
+	tensor< M, V, A >( const array< tensor< 2, TV, TA >, AA > &ts ) : _d( ts )
+	{
+	}
+
+
+	/*******************************************/
+	/*                                         */
+	/*          for 4th order tensor           */
+	/*                                         */
+	/*******************************************/
+
+	/// @brief resize the 4th order tensor
+	//!
+	//! @param[in] rank1  1st mode rank after this operation
+	//! @param[in] rank2  2nd mode rank after this operation
+	//! @param[in] rank3  3rd mode rank after this operation
+	//! @param[in] rank4  4th mode rank after this operation
+	//!
+	void resize( const size_type &rank1, const size_type &rank2, const size_type &rank3, const size_type &rank4 )
+	{
+		_d.resize( rank1, rank2, rank3, rank4 );
+	}
+	/// @brief return a element of the 4th order tensor for each set of indices
+	//!
+	//! @param[in] i1  index of the 1st mode
+	//! @param[in] i2  index of the 2nd mode
+	//! @param[in] i3  index of the 3rd mode
+	//! @param[in] i4  index of the 4th mode
+	//! @return        the element corresponding to the indices
+	//!
+	value_type &operator ( )( const size_type &i1, const size_type &i2, const size_type &i3, const size_type &i4 )
+	{
+		return _d( i1, i2, i3, i4 );
+	}
+	/// @brief return a element of the 4th order tensor for each set of indices
+	//!
+	//! @param[in] i1  index of the 1st mode
+	//! @param[in] i2  index of the 2nd mode
+	//! @param[in] i3  index of the 3rd mode
+	//! @param[in] i4  index of the 4th mode
+	//! @return        the element corresponding to the indices
+	//!
+	const value_type &operator ( )( const size_type &i1, const size_type &i2, const size_type &i3, const size_type &i4 ) const
+	{
+		return _d( i1, i2, i3, i4 );
+	}
+	/// @brief apply higher order singular value decomposition (HOSVD) to the 4th order tensor
+	//!
+	//! HOSVD decomposes a 4th order tensor T as T = Z \times_1 U_1 \times_2 U_2 \times_3 U_3 \times_4 U_4.
+	//! Here U_1, U_2, U_3, and U_4 are unitary matrices and a 4th order tensor Z is called as a core tensor.
+	//!
+	//! @param[in,out] z   core tensor of the tensor
+	//! @param[in,out] u1  unitary matrix corresponding to the 1st mode
+	//! @param[in,out] u2  unitary matrix corresponding to the 2nd mode
+	//! @param[in,out] u3  unitary matrix corresponding to the 3rd mode
+	//! @param[in,out] u4  unitary matrix corresponding to the 4th mode
+	//!
+	template< typename MV, typename MA >
+	void hosvd( tensor< M, V, A > &z, matrix< MV, MA > &u1, matrix< MV, MA > &u2, matrix< MV, MA > &u3, matrix< MV, MA > &u4 ) const
+	{
+		matrix< MV, MA > s, tmp;
+		svd( _unfold( 1 ), u1, s, tmp );
+		svd( _unfold( 2 ), u2, s, tmp );
+		svd( _unfold( 3 ), u3, s, tmp );
+		svd( _unfold( 4 ), u4, s, tmp );
+		z = _x( 1, u1.dagger( ) )._x( 2, u2.dagger( ) )._x( 3, u3.dagger( ) )._x( 4, u4.dagger( ) );
+	}
+	/// @brief construct a 4th order tensor
+	//!
+	//! @param[in] rank1  1st mode rank
+	//! @param[in] rank2  2nd mode rank
+	//! @param[in] rank3  3rd mode rank
+	//! @param[in] rank4  4th mode rank
+	//! @param[in] data   data to assign initial values to elements of the tensor
+	//!
+	template< typename AV, typename AA >
+	tensor< M, V, A >( const size_type &rank1, const size_type &rank2, const size_type &rank3, const size_type &rank4, const array< AV, AA > &data ) : _d( rank1, rank2, rank3, rank4, data )
+	{
+	}
+	/// @brief construct a 4th order tensor
+	//!
+	//! @param[in] rank1  1st mode rank
+	//! @param[in] rank2  2nd mode rank
+	//! @param[in] rank3  3rd mode rank
+	//! @param[in] rank4  4th mode rank
+	//!
+	tensor< M, V, A >( const size_type &rank1, const size_type &rank2, const size_type &rank3, const size_type &rank4 ) : _d( rank1, rank2, rank3, rank4 )
+	{
+	}
+	/// @brief construct a 4th order tensor from an array of 3rd order tensors
+	//!
+	//! @param[in] ts  array of 3rd order tensors
+	//!
+	template< typename TV, typename TA, typename AA >
+	tensor< M, V, A >( const array< tensor< 3, TV, TA >, AA > &ts ) : _d( ts )
+	{
+	}
+
+
+	/*******************************************/
+	/*                                         */
+	/*          for 5th order tensor           */
+	/*                                         */
+	/*******************************************/
+
+	/// @brief resize the 5th order tensor
+	//!
+	//! @param[in] rank1  1st mode rank after this operation
+	//! @param[in] rank2  2nd mode rank after this operation
+	//! @param[in] rank3  3rd mode rank after this operation
+	//! @param[in] rank4  4th mode rank after this operation
+	//! @param[in] rank5  5th mode rank after this operation
+	//!
+	void resize( const size_type &rank1, const size_type &rank2, const size_type &rank3, const size_type &rank4, const size_type &rank5 )
+	{
+		_d.resize( rank1, rank2, rank3, rank4, rank5 );
+	}
+	/// @brief return a element of the 5th order tensor for each set of indices
+	//!
+	//! @param[in] i1  index of the 1st mode
+	//! @param[in] i2  index of the 2nd mode
+	//! @param[in] i3  index of the 3rd mode
+	//! @param[in] i4  index of the 4th mode
+	//! @param[in] i5  index of the 5th mode
+	//! @return        the element corresponding to the indices
+	//!
+	tensor< M, V, A > &operator ( )( const size_type &i1, const size_type &i2, const size_type &i3, const size_type &i4, const size_type &i5 )
+	{
+		return _d( i1, i2, i3, i4, i5 );
+	}
+	/// @brief return a element of the 5th order tensor for each set of indices
+	//!
+	//! @param[in] i1  index of the 1st mode
+	//! @param[in] i2  index of the 2nd mode
+	//! @param[in] i3  index of the 3rd mode
+	//! @param[in] i4  index of the 4th mode
+	//! @param[in] i5  index of the 5th mode
+	//! @return        the element corresponding to the indices
+	//!
+	const tensor< M, V, A > &operator ( )( const size_type &i1, const size_type &i2, const size_type &i3, const size_type &i4, const size_type &i5 ) const
+	{
+		return _d( i1, i2, i3, i4, i5 );
+	}
+	/// @brief apply higher order singular value decomposition (HOSVD) to the 5th order tensor
+	//!
+	//! HOSVD decomposes a 5th order tensor T as T = Z \times_1 U_1 \times_2 U_2 \times_3 U_3 \times_4 U_4 \times_5 U_5.
+	//! Here U_1, U_2, U_3, U_4, and U_5 are unitary matrices and a 5th order tensor Z is called as a core tensor.
+	//!
+	//! @param[in,out] z   core tensor of the tensor
+	//! @param[in,out] u1  unitary matrix corresponding to the 1st mode
+	//! @param[in,out] u2  unitary matrix corresponding to the 2nd mode
+	//! @param[in,out] u3  unitary matrix corresponding to the 3rd mode
+	//! @param[in,out] u4  unitary matrix corresponding to the 4th mode
+	//! @param[in,out] u5  unitary matrix corresponding to the 5th mode
+	//!
+	template< typename MV, typename MA >
+	void hosvd( tensor< M, V, A > &z, matrix< MV, MA > &u1, matrix< MV, MA > &u2, matrix< MV, MA > &u3, matrix< MV, MA > &u4, matrix< MV, MA > &u5 ) const
+	{
+		matrix< MV, MA > s, tmp;
+		svd( _unfold( 1 ), u1, s, tmp );
+		svd( _unfold( 2 ), u2, s, tmp );
+		svd( _unfold( 3 ), u3, s, tmp );
+		svd( _unfold( 4 ), u4, s, tmp );
+		svd( _unfold( 5 ), u5, s, tmp );
+		z = _x( 1, u1.dagger( ) )._x( 2, u2.dagger( ) )._x( 3, u3.dagger( ) )._x( 4, u4.dagger( ) )._x( 5, u5.dagger( ) );
+	}
+	/// @brief construct a 5th order tensor
+	//!
+	//! @param[in] rank1  1st mode rank
+	//! @param[in] rank2  2nd mode rank
+	//! @param[in] rank3  3rd mode rank
+	//! @param[in] rank4  4th mode rank
+	//! @param[in] rank5  5th mode rank
+	//! @param[in] data   data to assign initial values to elements of the tensor
+	//!
+	template< typename AV, typename AA >
+	tensor< M, V, A >( const size_type &rank1, const size_type &rank2, const size_type &rank3, const size_type &rank4, const size_type &rank5, const array< AV, AA > &data ) : _d( rank1, rank2, rank3, rank4, rank5, data )
+	{
+	}
+	/// @brief construct a 5th order tensor
+	//!
+	//! @param[in] rank1  1st mode rank
+	//! @param[in] rank2  2nd mode rank
+	//! @param[in] rank3  3rd mode rank
+	//! @param[in] rank4  4th mode rank
+	//! @param[in] rank5  5th mode rank
+	//!
+	tensor< M, V, A >( const size_type &rank1, const size_type &rank2, const size_type &rank3, const size_type &rank4, const size_type &rank5 ) : _d( rank1, rank2, rank3, rank4, rank5 )
+	{
+	}
+	/// @brief construct a 5th order tensor from an array of 4th order tensors
+	//!
+	//! @param[in] ts  array of 4th order tensors
+	//!
+	template< typename TV, typename TA, typename AA >
+	tensor< M, V, A >( const array< tensor< 4, TV, TA >, AA > &ts ) : _d( ts )
+	{
+	}
+};
+
+
+/// @brief addition operator to calculate summation of two tensors
+//!
+//! @param[in] t1  1st tensor
+//! @param[in] t2  2nd tensor
+//! @return        summation of the 1st tensor and the 2nd tensor
+//!
+template< int M, typename V, typename A >
+inline tensor< M, V, A > operator +( const tensor< M, V, A > &t1, const tensor< M, V, A > &t2 )
+{
+	return tensor< M, V, A >( t1 ) += t2;
+}
+
+/// @brief subtraction operator to calculate difference betwwen two tensors
+//!
+//! @param[in] t1  1st tensor
+//! @param[in] t2  2nd tensor
+//! @return        difference between the 1st tensor and the 2nd tensor
+//!
+template< int M, typename V, typename A >
+inline tensor< M, V, A > operator -( const tensor< M, V, A > &t1, const tensor< M, V, A > &t2 )
+{
+	return tensor< M, V, A >( t1 ) -= t2;
+}
+
+/// @brief multiplication operator to calculate product of a tensor and a value
+//!
+//! @param[in] t  tensor
+//! @param[in] v  value
+//! @return       product of the tensor and the value
+//!
+template< int M, typename V, typename A >
+inline tensor< M, V, A > operator *( const tensor< M, V, A > &t, const typename type_trait< V >::value_type &v )
+{
+	return tensor< M, V, A >( t ) *= v;
+}
+
+/// @brief multiplication operator to calculate product of a value and a tensor
+//!
+//! @param[in] v  value
+//! @param[in] t  tensor
+//! @return       product of the value and the tensor
+//!
+template< int M, typename V, typename A >
+inline tensor< M, V, A > operator *( const typename type_trait< V >::value_type &v, const tensor< M, V, A > &t )
+{
+	return tensor< M, V, A >( t ) *= v;
+}
+
+/// @brief division operator to calculate quotient of a tensor and a value
+//!
+//! @param[in] t  tensor
+//! @param[in] v  value
+//! @return       quotient of the tensor and the value
+//!
+template< int M, typename V, typename A >
+inline tensor< M, V, A > operator /( const tensor< M, V, A > &t, const typename type_trait< V >::value_type &v )
+{
+	return tensor< M, V, A >( t ) /= v;
+}
+
+/// @brief output stream operator
+//!
+//! @param[in,out] o  output stream
+//! @param[in]     t  tensor
+//! @return           output stream
+//!
+template < int M, typename V, typename A >
+inline ::std::ostream &operator <<( ::std::ostream &o, const tensor< M, V, A > &t )
+{
+	t.out( o );
+	return o;
+}
+
+
+	/*******************************************/
+	/*                                         */
+	/*          for 2nd order tensor           */
+	/*                                         */
+	/*******************************************/
+
+/// @brief apply higher order singular value decomposition (HOSVD) to a 2nd order tensor
+//!
+//! HOSVD decomposes a 2nd order tensor T as T = Z \times_1 U_1 \times_2 U_2.
+//! Here U_1 and U_2 are unitary matrices and a 2nd order tensor Z is called as a core tensor.
+//! Using 1-mode-unfolding matrix of T, this is described like SVD of a matrix as T_1 = U_1 S U_2^t
+//! Here S is a singular value matrix.
+//!
+//! @param[in]     t   tensor to be decomposed
+//! @param[in,out] z   core tensor of the tensor
+//! @param[in,out] u1  unitary matrix corresponding to the 1st mode
+//! @param[in,out] u2  unitary matrix corresponding to the 2nd mode
+//!
+template< typename TV, typename TA, typename MV, typename MA >
+inline void hosvd( const tensor< 2, TV, TA > &t, tensor< 2, TV, TA > &z, matrix< MV, MA > &u1, matrix< MV, MA > &u2 )
+{
+	t.hosvd( z, u1, u2 );
+}
+
+
+	/*******************************************/
+	/*                                         */
+	/*          for 3rd order tensor           */
+	/*                                         */
+	/*******************************************/
+
+/// @brief apply higher order singular value decomposition (HOSVD) to a 3rd order tensor
+//!
+//! HOSVD decomposes a 3rd order tensor T as T = Z \times_1 U_1 \times_2 U_2 \times_3 U_3.
+//! Here U_1, U_2, and U_3 are unitary matrices and a 3rd order tensor Z is called as a core tensor.
+//!
+//! @param[in]     z   tensorto be decomposed
+//! @param[in,out] z   core tensor of the tensor
+//! @param[in,out] u1  unitary matrix corresponding to the 1st mode
+//! @param[in,out] u2  unitary matrix corresponding to the 2nd mode
+//! @param[in,out] u3  unitary matrix corresponding to the 3rd mode
+//!
+template< typename TV, typename TA, typename MV, typename MA >
+inline void hosvd( const tensor< 3, TV, TA > &t, tensor< 3, TV, TA > &z, matrix< MV, MA > &u1, matrix< MV, MA > &u2, matrix< MV, MA > &u3 )
+{
+	t.hosvd( z, u1, u2, u3 );
+}
+
+
+	/*******************************************/
+	/*                                         */
+	/*          for 4th order tensor           */
+	/*                                         */
+	/*******************************************/
+
+/// @brief apply higher order singular value decomposition (HOSVD) to a 4th order tensor
+//!
+//! HOSVD decomposes a 4th order tensor T as T = Z \times_1 U_1 \times_2 U_2 \times_3 U_3 \times_4 U_4.
+//! Here U_1, U_2, U_3 and U_4 are unitary matrices and a 4th order tensor Z is called as a core tensor.
+//!
+//! @param[in]     z   tensorto be decomposed
+//! @param[in,out] z   core tensor of the tensor
+//! @param[in,out] u1  unitary matrix corresponding to the 1st mode
+//! @param[in,out] u2  unitary matrix corresponding to the 2nd mode
+//! @param[in,out] u3  unitary matrix corresponding to the 3rd mode
+//! @param[in,out] u4  unitary matrix corresponding to the 4th mode
+//!
+template< typename TV, typename TA, typename MV, typename MA >
+inline void hosvd( const tensor< 4, TV, TA > &t, tensor< 4, TV, TA > &z, matrix< MV, MA > &u1, matrix< MV, MA > &u2, matrix< MV, MA > &u3, matrix< MV, MA > &u4 )
+{
+	t.hosvd( z, u1, u2, u3, u4 );
+}
+
+
+	/*******************************************/
+	/*                                         */
+	/*          for 5th order tensor           */
+	/*                                         */
+	/*******************************************/
+
+/// @brief apply higher order singular value decomposition (HOSVD) to a 5th order tensor
+//!
+//! HOSVD decomposes a 5th order tensor T as T = Z \times_1 U_1 \times_2 U_2 \times_3 U_3 \times_4 U_4 \times_5 U_5.
+//! Here U_1, U_2, U_3 and U_4 are unitary matrices and a 5th order tensor Z is called as a core tensor.
+//!
+//! @param[in]     z   tensorto be decomposed
+//! @param[in,out] z   core tensor of the tensor
+//! @param[in,out] u1  unitary matrix corresponding to the 1st mode
+//! @param[in,out] u2  unitary matrix corresponding to the 2nd mode
+//! @param[in,out] u3  unitary matrix corresponding to the 3rd mode
+//! @param[in,out] u4  unitary matrix corresponding to the 4th mode
+//! @param[in,out] u5  unitary matrix corresponding to the 5th mode
+//!
+template< typename TV, typename TA, typename MV, typename MA >
+inline void hosvd( const tensor< 5, TV, TA > &t, tensor< 5, TV, TA > &z, matrix< MV, MA > &u1, matrix< MV, MA > &u2, matrix< MV, MA > &u3, matrix< MV, MA > &u4, matrix< MV, MA > &u5 )
+{
+	t.hosvd( z, u1, u2, u3, u4, u5 );
+}
+
+
+// closing of mist namespace
+_MIST_END
+
+#endif // __INCLUDE_MIST_TENSOR__


Sizes should be with type uintmax_t. size_t can be 32-bit apparently on Windows.

--- wallet/util.h
+++ wallet/util.h
@@ -44,9 +44,9 @@
 static const int64_t COIN = 100000000;
 static const int64_t CENT = 1000000;

-static const std::size_t ONE_KB = (static_cast<uint64_t>(1) << 10);
-static const std::size_t ONE_MB = (static_cast<uint64_t>(1) << 20);
-static const std::size_t ONE_GB = (static_cast<uint64_t>(1) << 30);
+static const std::uintmax_t ONE_KB = (static_cast<uint64_t>(1) << 10);
+static const std::uintmax_t ONE_MB = (static_cast<uint64_t>(1) << 20);
+static const std::uintmax_t ONE_GB = (static_cast<uint64_t>(1) << 30);

 // option to erase the blockchain and resync
 const std::string SC_SCHEDULE_ON_RESTART_OPNAME__RESYNC = "resync";
@@ -744,7 +744,7 @@

 template <typename HashCalculatorClass>
 std::string CalculateHashOfFile(const boost::filesystem::path& PathToFile,
-                                const std::size_t              ChunkSize = ONE_MB)
+                                const std::uintmax_t           ChunkSize = ONE_MB)
 {
     if (!boost::filesystem::exists(PathToFile)) {
         throw std::runtime_error("While attempting to calculate hash of file, it does not exist: " +


Protected typedef uchar under __alpha for bogus OSF C compiler.

--- cpp/cpp.h
+++ cpp/cpp.h
@@ -1,3 +1,4 @@
+/* $Id$ */
 #define	INS	32768		/* input buffer */
 #define	OBS	4096		/* outbut buffer */
 #define	NARG	32		/* Max number arguments to a macro */
@@ -10,7 +11,9 @@
 #define NULL	0
 #endif

+#ifndef __alpha
 typedef unsigned char uchar;
+#endif

 enum toktype { END, UNCLASS, NAME, NUMBER, STRING, CCON, NL, WS, DSHARP,
 		EQ, NEQ, LEQ, GEQ, LSH, RSH, LAND, LOR, PPLUS, MMINUS,


souphttpsrc: Extract redirection uri on libsoup's restarted callback

Let libsoup handle redirection automatically.
And then, to figure out redirection uri, extract it on "restarted"
callback which will be fired before soup_session_send() is returned.

https://bugzilla.gnome.org/show_bug.cgi?id=778428

--- ext/soup/gstsouphttpsrc.c
+++ ext/soup/gstsouphttpsrc.c
@@ -1038,20 +1038,6 @@
     return GST_FLOW_OK;
   }

-  if (src->automatic_redirect &&
-      soup_session_would_redirect (src->session, msg) &&
-      soup_session_redirect_message (src->session, msg)) {
-    src->redirection_uri =
-        soup_uri_to_string (soup_message_get_uri (msg), FALSE);
-    src->redirection_permanent =
-        (msg->status_code == SOUP_STATUS_MOVED_PERMANENTLY);
-    GST_DEBUG_OBJECT (src, "%u redirect to \"%s\" (permanent %d)",
-        msg->status_code, src->redirection_uri, src->redirection_permanent);
-
-    /* force a retry with the updated message */
-    return GST_FLOW_CUSTOM_ERROR;
-  }
-
   if (msg->status_code == SOUP_STATUS_UNAUTHORIZED) {
     /* force an error */
     return gst_soup_http_src_parse_status (msg, src);
@@ -1371,6 +1357,19 @@
   return GST_FLOW_OK;
 }

+static void
+gst_soup_http_src_restarted_cb (SoupMessage * msg, GstSoupHTTPSrc * src)
+{
+  if (soup_session_would_redirect (src->session, msg)) {
+    src->redirection_uri =
+        soup_uri_to_string (soup_message_get_uri (msg), FALSE);
+    src->redirection_permanent =
+        (msg->status_code == SOUP_STATUS_MOVED_PERMANENTLY);
+    GST_DEBUG_OBJECT (src, "%u redirect to \"%s\" (permanent %d)",
+        msg->status_code, src->redirection_uri, src->redirection_permanent);
+  }
+}
+
 static gboolean
 gst_soup_http_src_build_message (GstSoupHTTPSrc * src, const gchar * method)
 {
@@ -1400,7 +1399,13 @@
   }

   soup_message_set_flags (src->msg, SOUP_MESSAGE_OVERWRITE_CHUNKS |
-      SOUP_MESSAGE_NO_REDIRECT);
+      (src->automatic_redirect ? 0 : SOUP_MESSAGE_NO_REDIRECT));
+
+  if (src->automatic_redirect) {
+    g_signal_connect (src->msg, "restarted",
+        G_CALLBACK (gst_soup_http_src_restarted_cb), src);
+  }
+
   gst_soup_http_src_add_range_header (src, src->request_position,
       src->stop_position);


tests/examples/playlist.c: add option to print avail. transitions/patterns. update help strings

--- tests/examples/playlist.c
+++ tests/examples/playlist.c
@@ -238,6 +238,44 @@
   }
 }

+void
+print_transition_list (void)
+{
+  GEnumClass *smpte_class;
+  GESTimelineTransition *tr;
+  GESTimelineTransitionClass *klass;
+  GParamSpec *pspec;
+  int i;
+
+  tr = ges_timeline_transition_new (VTYPE_CROSSFADE);
+  klass = GES_TIMELINE_TRANSITION_GET_CLASS (tr);
+
+  pspec = g_object_class_find_property (G_OBJECT_CLASS (klass), "vtype");
+
+  smpte_class = G_ENUM_CLASS (g_type_class_ref (pspec->value_type));
+
+  g_print ("%p %d\n", smpte_class, smpte_class->n_values);
+
+  GEnumValue *v;
+
+  for (v = smpte_class->values; v->value != 0; v++) {
+    g_print ("%s\n", v->value_nick);
+  }
+
+  g_type_class_unref (smpte_class);
+  g_object_unref (tr);
+}
+
+void
+print_pattern_list (void)
+{
+  int i;
+
+  for (i = 0; i < N_PATTERNS; i++) {
+    g_print ("%s\n", patterns[i].name);
+  }
+}
+
 int
 main (int argc, gchar ** argv)
 {
@@ -249,6 +287,8 @@
   gchar *video_restriction = "ANY";
   static gboolean render = FALSE;
   static gboolean smartrender = FALSE;
+  static gboolean list_transitions = FALSE;
+  static gboolean list_patterns = FALSE;
   GOptionEntry options[] = {
     {"render", 'r', 0, G_OPTION_ARG_NONE, &render,
         "Render to outputuri", NULL},
@@ -264,8 +304,12 @@
         "Audio format", "<GstCaps>"},
     {"vrestriction", 'x', 0, G_OPTION_ARG_STRING, &video_restriction,
         "Video restriction", "<GstCaps>"},
-    {"repeat", 't', 0, G_OPTION_ARG_INT, &repeat,
+    {"repeat", 'l', 0, G_OPTION_ARG_INT, &repeat,
         "Number of time to repeat timeline", NULL},
+    {"list-transitions", 't', 0, G_OPTION_ARG_NONE, &list_transitions,
+        "List valid transition types and exit", NULL},
+    {"list-patterns", 'p', 0, G_OPTION_ARG_NONE, &list_patterns,
+        "List patterns and exit", NULL},
     {NULL}
   };
   GOptionContext *ctx;
@@ -278,9 +322,16 @@
   ctx = g_option_context_new ("- plays/render a list of files");
   g_option_context_set_summary (ctx,
       "If not specified, this example will playback the files\n" "\n"
-      "The files should be layed out in triplets of:\n" " * filename\n"
+      "The files should be layed out in triplets of:\n"
+      " * filename\n"
       " * inpoint (in seconds)\n"
-      " * duration (in seconds) If 0, full file length");
+      " * duration (in seconds) If 0, full file length\n\n"
+      "Solid patterns and transitions can be specified as follows:\n"
+      " * +pattern | +transition\n"
+      " * <type>\n"
+      " * duration (in seconds, must be greater than 0)\n"
+      "To get a list of valid transitions, use --transitions.\n"
+      "To get a list of valid patterns, use --patterns.\n");
   g_option_context_add_main_entries (ctx, options, NULL);
   g_option_context_add_group (ctx, gst_init_get_option_group ());

@@ -288,6 +339,16 @@
     g_print ("Error initializing: %s\n", err->message);
     g_option_context_free (ctx);
     exit (1);
+  }
+
+  if (list_transitions) {
+    print_transition_list ();
+    exit (0);
+  }
+
+  if (list_patterns) {
+    print_pattern_list ();
+    exit (0);
   }

   if ((argc < 4) || (outputuri && (!render && !smartrender))) {


unneeded--

unneeded--

--- src/kdeaccessibilityclient/accessibleobject.h
+++ src/kdeaccessibilityclient/accessibleobject.h
@@ -444,7 +444,6 @@
     QSharedPointer<AccessibleObjectPrivate> d;

     friend class RegistryPrivate;
-    friend class AtSpiDBus;
     friend QDebug KAccessibleClient::operator<<(QDebug, const AccessibleObject &);
 };


helpers.c: reformat

helpers.c: reformat

Do not use comment lines longer than 79 characters.


lib-index: Added missing NUL separator to attribute-update transaction log record.

--- src/lib-index/mail-index-transaction-export.c
+++ src/lib-index/mail-index-transaction-export.c
@@ -394,6 +394,7 @@
 				  MAIL_TRANSACTION_HEADER_UPDATE);
 	}
 	if (t->attribute_updates != NULL) {
+		buffer_append_c(t->attribute_updates, '\0');
 		/* need to have 32bit alignment */
 		if (t->attribute_updates->used % 4 != 0) {
 			buffer_append_zero(t->attribute_updates,


mdbox: If save fails due to lock failure, don't assert-crash

--- src/lib-storage/index/dbox-multi/mdbox-save.c
+++ src/lib-storage/index/dbox-multi/mdbox-save.c
@@ -287,8 +287,10 @@
 	i_assert(ctx->ctx.finished);

 	/* make sure the map gets locked */
-	if (mdbox_map_atomic_lock(ctx->atomic) < 0)
-		return -1;
+	if (mdbox_map_atomic_lock(ctx->atomic) < 0) {
+		mdbox_transaction_save_rollback(_ctx);
+		return -1;
+	}

 	/* assign map UIDs for newly saved messages. they're written to
 	   transaction log immediately within this function, but the map


fix return type of cpustats_subtract1

fix return type of cpustats_subtract1

--- cpubars.c
+++ cpubars.c
@@ -323,7 +323,7 @@
                 epanic("failed to seek %s/stat", proc_path);
 }

-static bool
+static void
 cpustats_subtract1(struct cpustat *out,
                    const struct cpustat *a, const struct cpustat *b)
 {


Use longer line wrapping with X-IMAP, X-IMAPbase and X-Keywords headers since UW-IMAP doesn't like the wrapping.

--- src/lib-storage/index/mbox/mbox-sync-update.c
+++ src/lib-storage/index/mbox/mbox-sync-update.c
@@ -8,6 +8,11 @@
 #include "index-storage.h"
 #include "mbox-storage.h"
 #include "mbox-sync-private.h"
+
+/* Line length when to wrap X-IMAP, X-IMAPbase and X-Keywords headers to next
+   line. Keep this pretty long, as after we wrap we lose compatibility with
+   UW-IMAP */
+#define KEYWORD_WRAP_LINE_LENGTH 1024

 static void status_flags_append(struct mbox_sync_mail_context *ctx,
 				const struct mbox_flag_type *flags_list)
@@ -130,9 +135,8 @@
 	for (i = 0, last_break = str_len(dest); i < idx_count; i++) {
 		i_assert(keyword_indexes[i] < keywords_count);

-		/* try avoid overly long lines but cutting them
-		   every 70 chars or so */
-		if (str_len(dest) - last_break < 70) {
+		/* wrap the line whenever it gets too long */
+		if (str_len(dest) - last_break < KEYWORD_WRAP_LINE_LENGTH) {
 			if (i > 0)
 				str_append_c(dest, ' ');
 		} else {
@@ -152,7 +156,7 @@
 	size_t last_break;

 	p = str_data(dest);
-	if (str_len(dest) < 70)
+	if (str_len(dest) < KEYWORD_WRAP_LINE_LENGTH)
 		last_break = 0;
 	else {
 		/* set last_break to beginning of line */
@@ -164,9 +168,8 @@

 	names = array_get(ctx->sync_ctx->mbox->ibox.keyword_names, &count);
 	for (i = 0; i < count; i++) {
-		/* try avoid overly long lines but cutting them
-		   every 70 chars or so */
-		if (str_len(dest) - last_break < 70)
+		/* wrap the line whenever it gets too long */
+		if (str_len(dest) - last_break < KEYWORD_WRAP_LINE_LENGTH)
 			str_append_c(dest, ' ');
 		else {
 			str_append(dest, "\n\t");


[FIX] Index: fixed view()

[FIX] Index: fixed view()

--- core/include/seqan/index/index_view.h
+++ core/include/seqan/index/index_view.h
@@ -729,7 +729,7 @@
 // Function view()                                                    [IndexSa]
 // ----------------------------------------------------------------------------

-template <typename TText, typename TSpec, typename TConfig>
+template <typename TText, typename TSpec>
 typename View<Index<TText, IndexSa<TSpec> > >::Type
 view(Index<TText, IndexSa<TSpec> > & index)
 {
@@ -745,7 +745,7 @@
 // Function view()                                                   [IndexEsa]
 // ----------------------------------------------------------------------------

-template <typename TText, typename TSpec, typename TConfig>
+template <typename TText, typename TSpec>
 typename View<Index<TText, IndexEsa<TSpec> > >::Type
 view(Index<TText, IndexEsa<TSpec> > & index)
 {


sockinfo call indentation fix

sockinfo call indentation fix

Signed-off-by: Pavel Emelyanov <c9a32589e048e044184536f7ac71ef92fe82df3e@parallels.com>

--- cr-dump.c
+++ cr-dump.c
@@ -1358,11 +1358,11 @@
 		goto err;
 	}

-       ret = parasite_dump_socket_info(parasite_ctl, cr_fdset, &sk_queue);
-       if (ret) {
-               pr_err("Can't dump socket info (pid: %d)\n", pid);
-               goto err;
-       }
+	ret = parasite_dump_socket_info(parasite_ctl, cr_fdset, &sk_queue);
+	if (ret) {
+		pr_err("Can't dump socket info (pid: %d)\n", pid);
+		goto err;
+	}

 	ret = parasite_cure_seized(parasite_ctl);
 	if (ret) {


Connect tab switcher to child web view key events

The parent view will do its best to forward the focus to the
child web view, so  the tab switcher should listen to it.

--- extensions/tab-switcher.c
+++ extensions/tab-switcher.c
@@ -248,12 +248,19 @@
                                  GtkWidget          *view,
                                  MidoriExtension    *extension)
 {
-    g_signal_connect (view, "key_press_event",
+    GtkWidget* web_view;
+    GList* list;
+
+    g_return_if_fail (MIDORI_IS_VIEW (view));
+
+    web_view = midori_view_get_web_view (MIDORI_VIEW(view));
+
+    g_signal_connect (web_view, "key_press_event",
             G_CALLBACK (tab_selector_handle_events), browser);
-    g_signal_connect (view, "key_release_event",
+    g_signal_connect (web_view, "key_release_event",
             G_CALLBACK (tab_selector_handle_events), browser);

-    GList *list = g_object_get_data(G_OBJECT(browser), "tab_selector_list");
+    list = g_object_get_data(G_OBJECT(browser), "tab_selector_list");
     list = g_list_append(list, view);
     g_object_set_data(G_OBJECT(browser), "tab_selector_list", list);
 }


lib-storage: Allow shared namespace prefix to use %variable modifiers.

--HG--
branch : HEAD

--- src/lib-storage/index/shared/shared-storage.c
+++ src/lib-storage/index/shared/shared-storage.c
@@ -31,7 +31,7 @@
 {
 	struct shared_storage *storage = (struct shared_storage *)_storage;
 	const char *driver, *p;
-	char *wildcardp;
+	char *wildcardp, key;
 	bool have_username;

 	/* location must begin with the actual mailbox driver */
@@ -61,11 +61,11 @@
 	for (p = storage->ns_prefix_pattern; *p != '\0'; p++) {
 		if (*p != '%')
 			continue;
-		if (*++p == '\0')
-			break;
-		if (*p == 'u' || *p == 'n')
+
+		key = var_get_key(p + 1);
+		if (key == 'u' || key == 'n')
 			have_username = TRUE;
-		else if (*p != '%' && *p != 'd')
+		else if (key != '%' && key != 'd')
 			break;
 	}
 	if (*p != '\0') {


dump: collect_mappings -- Fix message text

@vma_area_list::longest is in pages not bytes.

Signed-off-by: Cyrill Gorcunov <7a1ea01eee6961eb1e372e3508c2670446d086f4@openvz.org>
Signed-off-by: Pavel Emelyanov <c9a32589e048e044184536f7ac71ef92fe82df3e@parallels.com>

--- cr-dump.c
+++ cr-dump.c
@@ -135,7 +135,7 @@
 	if (ret < 0)
 		goto err;

-	pr_info("Collected, longest ares %lu bytes\n", vma_area_list->longest);
+	pr_info("Collected, longest area occupies %lu pages\n", vma_area_list->longest);
 	pr_info_vma_list(&vma_area_list->h);

 	pr_info("----------------------------------------\n");


[PATCH] swsusp: Fix swap_type_of

[PATCH] swsusp: Fix swap_type_of

There is a bug in mm/swapfile.c#swap_type_of() that makes swsusp only be
able to use the first active swap partition as the resume device.  Fix it.

Signed-off-by: Rafael J. Wysocki <a11f87183a953ab11f50fbafff689c5a7fa3506c@sisk.pl>
Cc: Hugh Dickins <a6c5230a10c458028ff1bd5985dd47c394028d47@veritas.com>
Acked-by: Pavel Machek <2375fa63e2908bb2df59f606483a3aa92321db7a@suse.cz>
Cc: <4fbacc2fa0ffdbb11bf1ad6925b886ebd08dd15f@kernel.org>
Signed-off-by: Andrew Morton <5c1e68b099950c134891f0b6e179498a8ebe9cf9@osdl.org>
Signed-off-by: Linus Torvalds <69652caca27c8b940640ad396ab71f93cacec34f@osdl.org>

--- mm/swapfile.c
+++ mm/swapfile.c
@@ -442,11 +442,12 @@

 		if (!(swap_info[i].flags & SWP_WRITEOK))
 			continue;
+
 		if (!device) {
 			spin_unlock(&swap_lock);
 			return i;
 		}
-		inode = swap_info->swap_file->f_dentry->d_inode;
+		inode = swap_info[i].swap_file->f_dentry->d_inode;
 		if (S_ISBLK(inode->i_mode) &&
 		    device == MKDEV(imajor(inode), iminor(inode))) {
 			spin_unlock(&swap_lock);


Allow building on 64 bit archs.  Hopefully the last cvs activity this stuff will see other than "delete".

--- extra/locale/gen_wctype.c
+++ extra/locale/gen_wctype.c
@@ -442,8 +442,8 @@
 			}
 			wct[c/2] |= d;

-			l = towlower(c) - c;
-			u = towupper(c) - c;
+			l = (long)(int) towlower(c) - c;
+			u = (long)(int) towupper(c) - c;
 			ult[c] = 0;
 			if (l || u) {
 				if ((l != (short)l) || (u != (short)u)) {


Very old option spelling mistake

Very old option spelling mistake

--- wand/import.c
+++ wand/import.c
@@ -1200,7 +1200,7 @@
       {
         if (LocaleCompare("taint",option+1) == 0)
           break;
-        if (LocaleCompare("thumnail",option+1) == 0)
+        if (LocaleCompare("thumbnail",option+1) == 0)
           {
             if (*option == '+')
               break;


crtools: Print error message with capital letter

We usually print error messages starting with capital letter.

Signed-off-by: Cyrill Gorcunov <7a1ea01eee6961eb1e372e3508c2670446d086f4@openvz.org>
Signed-off-by: Pavel Emelyanov <c9a32589e048e044184536f7ac71ef92fe82df3e@parallels.com>

--- crtools.c
+++ crtools.c
@@ -289,7 +289,7 @@

 	ret = open_image_dir();
 	if (ret < 0) {
-		pr_perror("can't open current directory");
+		pr_perror("Can't open current directory");
 		return -1;
 	}


crtools: Use %d format for pir_t

crtools: Use %d format for pir_t

Signed-off-by: Cyrill Gorcunov <7a1ea01eee6961eb1e372e3508c2670446d086f4@gmail.com>

--- crtools.c
+++ crtools.c
@@ -40,19 +40,19 @@

 	 /* info about file descriptiors */
 	[CR_FD_FDINFO] = {
-		.fmt	= "fdinfo-%li.img",
+		.fmt	= "fdinfo-%d.img",
 		.magic	= FDINFO_MAGIC,
 	},

 	/* private memory pages data */
 	[CR_FD_PAGES] = {
-		.fmt	= "pages-%li.img",
+		.fmt	= "pages-%d.img",
 		.magic	= PAGES_MAGIC,
 	},

 	/* shared memory pages data */
 	[CR_FD_PAGES_SHMEM] = {
-		.fmt	= "pages-shmem-%li.img",
+		.fmt	= "pages-shmem-%d.img",
 		.magic	= PAGES_MAGIC,
 	},

@@ -64,25 +64,25 @@
 	 * Thus this file contains the almost-ready for execve image.
 	 */
 	[CR_FD_CORE] = {
-		.fmt	= "core-%li.img",
+		.fmt	= "core-%d.img",
 		.magic	= CORE_MAGIC,
 	},

 	/* info about pipes - fds, pipe id and pipe data */
 	[CR_FD_PIPES] = {
-		.fmt	= "pipes-%li.img",
+		.fmt	= "pipes-%d.img",
 		.magic	= PIPES_MAGIC,
 	},

 	 /* info about process linkage */
 	[CR_FD_PSTREE] = {
-		.fmt	= "pstree-%li.img",
+		.fmt	= "pstree-%d.img",
 		.magic	= PSTREE_MAGIC,
 	},

 	/* info about which memory areas are shared */
 	[CR_FD_SHMEM] = {
-		.fmt	= "shmem-%li.img",
+		.fmt	= "shmem-%d.img",
 		.magic	= SHMEM_MAGIC,
 	},
 };
@@ -101,7 +101,7 @@
 		snprintf(cr_fdset->desc[i].name,
 			 sizeof(cr_fdset->desc[i].name),
 			 cr_fdset->desc[i].tmpl->fmt,
-			 (long)pid);
+			 pid);
 		cr_fdset->desc[i].fd = -1;
 	}


Add prepending

Add prepending

--- code/7/linked-soln.c
+++ code/7/linked-soln.c
@@ -1,9 +1,8 @@
-#include <assert.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>

-#define SIZE 10
+#define SIZE 5

 typedef struct node
 {
@@ -17,6 +16,18 @@

 // points to the first node in the linked list
 node* head = NULL;
+
+/**
+ * Prints out every element of the linked list that starts at `head`.
+ */
+void print_list()
+{
+    for (node*  ptr = head; ptr != NULL; ptr = ptr->next)
+    {
+        printf("%i ", ptr->n);
+    }
+    printf("\n");
+}

 /*
  * Returns the length of the linked list that starts at `head`.
@@ -33,6 +44,28 @@
     }

     return length;
+}
+
+/**
+ * Adds an element containing `i` to the front of the linked list that
+ * starts at `head`.
+ */
+void prepend(int i)
+{
+    // build new node
+    node* new = malloc(sizeof(node));
+
+    if (new == NULL)
+    {
+        exit(1);
+    }
+
+    // initialize new node
+    new->n = i;
+
+    // add new node to head of list
+    new->next = head;
+    head = new;
 }

 int main(int argc, char* argv[])
@@ -52,9 +85,17 @@
     }

     // test length function
-    printf("Making sure that list length is indeed %i...\n", SIZE);
-    assert(length() == SIZE);
-    printf("ok!\n");
+    printf("Length of list is %i (expected to be %i)", length(), SIZE);
+
+    // test prepending
+    int new = 50;
+    printf("Prepending %i to the list...\n", new);
+    printf("Before:\n");
+    print_list();
+    prepend(new);
+    printf("After:\n");
+    print_list();
+

     return 0;
 }


Documenting ActionPointManager

Documenting ActionPointManager

--- src/main/entity/managers/ActionPointManager.h
+++ src/main/entity/managers/ActionPointManager.h
@@ -6,6 +6,11 @@
 #include "entity/components/ActionPointComponent.h"

 /**
+ * ActionPointManager is the ComponentManager for action points.
+ *
+ * Entities have an action point pool which replenishes each game tick,
+ * and is consumed any time an action is taken; an Entity can only act
+ * when its action point total is at least 0.
  */
 class ActionPointManager : public LookupComponentManager<ActionPointComponent>
 {


use real emscripten.h

use real emscripten.h

--- wasm/runner.c
+++ wasm/runner.c
@@ -2,44 +2,43 @@
 #include "../token.h"
 #include "../parser.h"

-// this is just EMSCRIPTEN_KEEPALIVE from the actual source
-#define EXPORT __attribute__((used))
+#include <emscripten.h>

 static parserdef shared_parser;
 static token out;

-EXPORT
+EMSCRIPTEN_KEEPALIVE
 int prsr_setup(char *buf) {
   prsr_parser_init(&shared_parser, buf);
   return 0;
 }

-EXPORT
+EMSCRIPTEN_KEEPALIVE
 int prsr_run() {
   return prsr_next(&shared_parser, &out);
 }

-EXPORT
+EMSCRIPTEN_KEEPALIVE
 int prsr_get_at() {
   return out.p - shared_parser.td.buf;
 }

-EXPORT
+EMSCRIPTEN_KEEPALIVE
 int prsr_get_len() {
   return out.len;
 }

-EXPORT
+EMSCRIPTEN_KEEPALIVE
 int prsr_get_invalid() {
   return out.invalid;
 }

-EXPORT
+EMSCRIPTEN_KEEPALIVE
 int prsr_get_line_no() {
   return out.line_no;
 }

-EXPORT
+EMSCRIPTEN_KEEPALIVE
 int prsr_get_type() {
   return out.type;
 }


EscapeConfigFromString, FillDeviceInfo functions created device/list in progress

--- core/system/fsys/device_manager_web.c
+++ core/system/fsys/device_manager_web.c
@@ -1708,7 +1708,7 @@

 							FilesystemDeleteAll( fs );

-							DEBUG( "[DeviceMWebRequest] We now have information: %s (query: %s) - name: %s\n", rootdev->f_Config, query, rootdev->f_Name );
+							//DEBUG( "[DeviceMWebRequest] We now have information: %s (query: %s) - name: %s\n", rootdev->f_Config, query, rootdev->f_Name );
 						}
 						FFree( query );
 					}


some fixes

some fixes

--- cvd/esm.h
+++ cvd/esm.h
@@ -65,7 +65,7 @@
 };

 inline std::ostream & operator<<(std::ostream & out, const ESMResult & r ){
-    out << r.error << "\t" << r.pixels << "\t" << r.RMSE() << "\t" << "\t" << r.delta << "\t" << r.iterations;
+    out << r.error << "\t" << r.pixels << "\t" << r.RMSE() << "\t" << r.delta << "\t" << r.iterations;
     return out;
 }

@@ -468,7 +468,7 @@
     }

     const ESMResult & optimize( const SubImage<IMAGE> & from, const SubImage<IMAGE> & to ){
-        Image<GRADIENT> fromGradient = Internal::gradient<IMAGE, GRADIENT>(from);
+        Image<GRADIENT> fromGradient = Internal::gradient<GRADIENT>(from);
         return optimize( from, fromGradient, to );
     }

@@ -675,7 +675,7 @@
         }

         template <typename TRANSFORM, typename APPEARANCE, typename IMAGE, typename GRADIENT>
-        inline ESMResult esm_opt( TRANSFORM & T, APPEARANCE & A, const SubImage<IMAGE> & templateImage, const SubImage<GRADIENT> & templateGradient, const SubImage<IMAGE> & target, const int max_iterations = 40, const double min_delta = 1e-8, const double max_RMSE = 1.0 ){
+        inline ESMResult esm_opt( TRANSFORM & T, APPEARANCE & A, const SubImage<IMAGE> & templateImage, const SubImage<GRADIENT> & templateGradient, const SubImage<IMAGE> & target, const int max_iterations, const double min_delta, const double max_RMSE ){
             assert(templateImage.size() == templateGradient.size());

             const int dimensions = TRANSFORM::dimensions+APPEARANCE::dimensions;


Make a handy asset macro rt_assert() it logs and PAUSES on error

This makes it easy to attach a debugger and to study /proc for open
files etc if something isn't right.

--- cxbench.c
+++ cxbench.c
@@ -64,6 +64,18 @@
 		fprintf(stderr, format , ##args);	\
 	}						\
 } while(0)
+
+#define rt_assert(x)							\
+do {									\
+	if (!(x)) {							\
+		fprintf(stderr, "%s:%d %s ASSERT FAILURE %s - PAUSING\n", __FILE__, __LINE__, \
+			__PRETTY_FUNCTION__, #x);			\
+		while (1) {						\
+			pause();					\
+			sleep(1);					\
+		}							\
+	}								\
+} while (0);

 static int loop_mode = 0;
 static int random_mode = 0;


 Committing in .

 Modified Files:
 	Mesa/si-glu/libutil/glue.c

 added some type casts to silence compiler warnings.

----------------------------------------------------------------------

--- src/glu/sgi/libutil/glue.c
+++ src/glu/sgi/libutil/glue.c
@@ -31,52 +31,52 @@
 ** published by SGI, but has not been independently verified as being
 ** compliant with the OpenGL(R) version 1.2.1 Specification.
 **
-** $Date: 2001/09/20 21:50:53 $ $Revision: 1.2 $
-** $Header: /home/krh/git/sync/mesa-cvs-repo/Mesa/src/glu/sgi/libutil/glue.c,v 1.2 2001/09/20 21:50:53 kschultz Exp $
+** $Date: 2001/09/24 09:40:40 $ $Revision: 1.3 $
+** $Header: /home/krh/git/sync/mesa-cvs-repo/Mesa/src/glu/sgi/libutil/glue.c,v 1.3 2001/09/24 09:40:40 joukj Exp $
 */

 #include <stdlib.h>
 #include "gluint.h"

 static unsigned char *__gluNurbsErrors[] = {
-    " ",
-    "spline order un-supported",
-    "too few knots",
-    "valid knot range is empty",
-    "decreasing knot sequence knot",
-    "knot multiplicity greater than order of spline",
-    "gluEndCurve() must follow gluBeginCurve()",
-    "gluBeginCurve() must precede gluEndCurve()",
-    "missing or extra geometric data",
-    "can't draw piecewise linear trimming curves",
-    "missing or extra domain data",
-    "missing or extra domain data",
-    "gluEndTrim() must precede gluEndSurface()",
-    "gluBeginSurface() must precede gluEndSurface()",
-    "curve of improper type passed as trim curve",
-    "gluBeginSurface() must precede gluBeginTrim()",
-    "gluEndTrim() must follow gluBeginTrim()",
-    "gluBeginTrim() must precede gluEndTrim()",
-    "invalid or missing trim curve",
-    "gluBeginTrim() must precede gluPwlCurve()",
-    "piecewise linear trimming curve referenced twice",
-    "piecewise linear trimming curve and nurbs curve mixed",
-    "improper usage of trim data type",
-    "nurbs curve referenced twice",
-    "nurbs curve and piecewise linear trimming curve mixed",
-    "nurbs surface referenced twice",
-    "invalid property",
-    "gluEndSurface() must follow gluBeginSurface()",
-    "intersecting or misoriented trim curves",
-    "intersecting trim curves",
-    "UNUSED",
-    "unconnected trim curves",
-    "unknown knot error",
-    "negative vertex count encountered",
-    "negative byte-stride encounteed",
-    "unknown type descriptor",
-    "null control point reference",
-    "duplicate point on piecewise linear trimming curve",
+    (unsigned char*) " ",
+    (unsigned char*) "spline order un-supported",
+    (unsigned char*) "too few knots",
+    (unsigned char*) "valid knot range is empty",
+    (unsigned char*) "decreasing knot sequence knot",
+    (unsigned char*) "knot multiplicity greater than order of spline",
+    (unsigned char*) "gluEndCurve() must follow gluBeginCurve()",
+    (unsigned char*) "gluBeginCurve() must precede gluEndCurve()",
+    (unsigned char*) "missing or extra geometric data",
+    (unsigned char*) "can't draw piecewise linear trimming curves",
+    (unsigned char*) "missing or extra domain data",
+    (unsigned char*) "missing or extra domain data",
+    (unsigned char*) "gluEndTrim() must precede gluEndSurface()",
+    (unsigned char*) "gluBeginSurface() must precede gluEndSurface()",
+    (unsigned char*) "curve of improper type passed as trim curve",
+    (unsigned char*) "gluBeginSurface() must precede gluBeginTrim()",
+    (unsigned char*) "gluEndTrim() must follow gluBeginTrim()",
+    (unsigned char*) "gluBeginTrim() must precede gluEndTrim()",
+    (unsigned char*) "invalid or missing trim curve",
+    (unsigned char*) "gluBeginTrim() must precede gluPwlCurve()",
+    (unsigned char*) "piecewise linear trimming curve referenced twice",
+    (unsigned char*) "piecewise linear trimming curve and nurbs curve mixed",
+    (unsigned char*) "improper usage of trim data type",
+    (unsigned char*) "nurbs curve referenced twice",
+    (unsigned char*) "nurbs curve and piecewise linear trimming curve mixed",
+    (unsigned char*) "nurbs surface referenced twice",
+    (unsigned char*) "invalid property",
+    (unsigned char*) "gluEndSurface() must follow gluBeginSurface()",
+    (unsigned char*) "intersecting or misoriented trim curves",
+    (unsigned char*) "intersecting trim curves",
+    (unsigned char*) "UNUSED",
+    (unsigned char*) "unconnected trim curves",
+    (unsigned char*) "unknown knot error",
+    (unsigned char*) "negative vertex count encountered",
+    (unsigned char*) "negative byte-stride encounteed",
+    (unsigned char*) "unknown type descriptor",
+    (unsigned char*) "null control point reference",
+    (unsigned char*) "duplicate point on piecewise linear trimming curve",
 };

 const unsigned char *__gluNURBSErrorString( int errnum )
@@ -85,13 +85,13 @@
 }

 static unsigned char *__gluTessErrors[] = {
-    " ",
-    "gluTessBeginPolygon() must precede a gluTessEndPolygon()",
-    "gluTessBeginContour() must precede a gluTessEndContour()",
-    "gluTessEndPolygon() must follow a gluTessBeginPolygon()",
-    "gluTessEndContour() must follow a gluTessBeginContour()",
-    "a coordinate is too large",
-    "need combine callback",
+    (unsigned char*) " ",
+    (unsigned char*) "gluTessBeginPolygon() must precede a gluTessEndPolygon()",
+    (unsigned char*) "gluTessBeginContour() must precede a gluTessEndContour()",
+    (unsigned char*) "gluTessEndPolygon() must follow a gluTessBeginPolygon()",
+    (unsigned char*) "gluTessEndContour() must follow a gluTessBeginContour()",
+    (unsigned char*) "a coordinate is too large",
+    (unsigned char*) "need combine callback",
 };

 const unsigned char *__gluTessErrorString( int errnum )


Fix self assignment in GrGLShaderVar

Fix self assignment in GrGLShaderVar

R=robertphillips@google.com
Review URL: https://codereview.appspot.com/6776048

git-svn-id: e8541e15acce502a64c929015570ad1648e548cd@6127 2bbb7eff-a529-9590-31e7-b0007b416f81

--- src/gpu/gl/GrGLShaderVar.h
+++ src/gpu/gl/GrGLShaderVar.h
@@ -81,7 +81,7 @@
         , fName(var.fName)
         , fCount(var.fCount)
         , fPrecision(var.fPrecision)
-        , fOrigin(fOrigin)
+        , fOrigin(var.fOrigin)
         , fUseUniformFloatArrays(var.fUseUniformFloatArrays) {
         GrAssert(kVoid_GrSLType != var.fType);
     }


tests/zoap: Add simple test for retransmission

Change-Id: I3a552f10e02e3880bbeb00b31f31c31414c6f163
Signed-off-by: Vinicius Costa Gomes <540a5b73c8ed8ee3381dfb54c1949e767fadd754@intel.com>

--- tests/net/zoap/src/main.c
+++ tests/net/zoap/src/main.c
@@ -17,6 +17,7 @@
 #include <stdint.h>
 #include <stdbool.h>
 #include <stddef.h>
+#include <stdio.h>
 #include <string.h>
 #include <misc/printk.h>

@@ -34,13 +35,21 @@
 #define ZOAP_BUF_SIZE 128
 #define ZOAP_LIMITED_BUF_SIZE 9

+#define NUM_PENDINGS 3
+
 static struct nano_fifo zoap_fifo;
 static NET_BUF_POOL(zoap_pool, 1, ZOAP_BUF_SIZE,
 		    &zoap_fifo, NULL, sizeof(struct ip_buf));

+static struct nano_fifo zoap_incoming_fifo;
+static NET_BUF_POOL(zoap_incoming_pool, 1, ZOAP_BUF_SIZE,
+		    &zoap_incoming_fifo, NULL, sizeof(struct ip_buf));
+
 static struct nano_fifo zoap_limited_fifo;
 static NET_BUF_POOL(zoap_limited_pool, 1, ZOAP_LIMITED_BUF_SIZE,
 		    &zoap_limited_fifo, NULL, sizeof(struct ip_buf));
+
+static struct zoap_pending pendings[NUM_PENDINGS];

 static int test_build_empty_pdu(void)
 {
@@ -392,6 +401,107 @@
 	return result;
 }

+static int test_retransmit_second_round(void)
+{
+	struct zoap_packet resp;
+	struct zoap_pending *pending, *resp_pending;
+	struct zoap_packet pkt;
+	struct net_buf *buf, *resp_buf = NULL;
+	uint16_t id;
+	int result = TC_FAIL;
+	int r;
+
+	buf = net_buf_get(&zoap_fifo, 0);
+	if (!buf) {
+		TC_PRINT("Could not get buffer from pool\n");
+		goto done;
+	}
+	ip_buf_appdata(buf) = net_buf_tail(buf);
+	ip_buf_appdatalen(buf) = net_buf_tailroom(buf);
+
+	r = zoap_packet_init(&pkt, buf);
+	if (r) {
+		TC_PRINT("Could not initialize packet\n");
+		goto done;
+	}
+
+	id = zoap_next_id();
+
+	zoap_header_set_version(&pkt, 1);
+	zoap_header_set_type(&pkt, ZOAP_TYPE_CON);
+	zoap_header_set_code(&pkt, ZOAP_METHOD_GET);
+	zoap_header_set_id(&pkt, id);
+
+	pending = zoap_pending_next_unused(pendings, NUM_PENDINGS);
+	if (!pending) {
+		TC_PRINT("No free pending\n");
+		goto done;
+	}
+
+	r = zoap_pending_init(pending, &pkt);
+	if (r) {
+		TC_PRINT("Could not initialize packet\n");
+		goto done;
+	}
+
+	/* We "send" the packet the first time here */
+	if (!zoap_pending_cycle(pending)) {
+		TC_PRINT("Pending expired too early\n");
+		goto done;
+	}
+
+	/* We simulate that the first transmission got lost */
+
+	if (!zoap_pending_cycle(pending)) {
+		TC_PRINT("Pending expired too early\n");
+		goto done;
+	}
+
+	resp_buf = net_buf_get(&zoap_incoming_fifo, 0);
+	if (!resp_buf) {
+		TC_PRINT("Could not get buffer from pool\n");
+		goto done;
+	}
+	ip_buf_appdata(resp_buf) = net_buf_tail(resp_buf);
+	ip_buf_appdatalen(resp_buf) = net_buf_tailroom(resp_buf);
+
+	r = zoap_packet_init(&resp, resp_buf);
+	if (r) {
+		TC_PRINT("Could not initialize packet\n");
+		goto done;
+	}
+
+	zoap_header_set_version(&resp, 1);
+	zoap_header_set_type(&resp, ZOAP_TYPE_ACK);
+	zoap_header_set_id(&resp, id); /* So it matches the request */
+
+	/* Now we get the ack from the remote side */
+	resp_pending = zoap_pending_received(&resp, pendings, NUM_PENDINGS);
+	if (pending != resp_pending) {
+		TC_PRINT("Invalid pending %p should be %p\n",
+			 resp_pending, pending);
+		goto done;
+	}
+
+	resp_pending = zoap_pending_next_to_expire(pendings, NUM_PENDINGS);
+	if (resp_pending) {
+		TC_PRINT("There should be no active pendings\n");
+		goto done;
+	}
+
+	result = TC_PASS;
+
+done:
+	net_buf_unref(buf);
+	if (resp_buf) {
+		net_buf_unref(resp_buf);
+	}
+
+	TC_END_RESULT(result);
+
+	return result;
+}
+
 static const struct {
 	const char *name;
 	int (*func)(void);
@@ -401,6 +511,7 @@
 	{ "No size for options test", test_build_no_size_for_options, },
 	{ "Parse emtpy PDU test", test_parse_empty_pdu, },
 	{ "Parse simple PDU test", test_parse_simple_pdu, },
+	{ "Test retransmission", test_retransmit_second_round, },
 };

 int main(int argc, char *argv[])
@@ -411,6 +522,7 @@

 	net_buf_pool_init(zoap_pool);
 	net_buf_pool_init(zoap_limited_pool);
+	net_buf_pool_init(zoap_incoming_pool);

 	for (count = 0, pass = 0; count < ARRAY_SIZE(tests); count++) {
 		if (tests[count].func() == TC_PASS) {


possible fix for MinGW

possible fix for MinGW

git-svn-id: 6b1c4fe79111c0bc0cce83313250759594f8984b@8263 e128ff1e-fa79-4151-a8cb-522299a2c450

--- src/gsCore/gsJITCompiler.h
+++ src/gsCore/gsJITCompiler.h
@@ -297,7 +297,7 @@

         T *symbol;
 #if defined(_WIN32)
-        *(void **)(&symbol) = GetProcAddress(handle.get(), name );
+        *(void **)(&symbol) = (void*)GetProcAddress(handle.get(), name );
 #elif defined(__APPLE__) || defined(__linux__) || defined(__unix)
         *(void **)(&symbol) = ::dlsym( handle.get(), name );
 #endif


Revert "tests: qemucapsprobe: Fix output after switching to jansson"

This reverts commit 397447f80588438545994a86883792a5999cad15.

Jansson cannot parse QEMU's quirky JSON.
Revert back to yajl.

https://bugzilla.redhat.com/show_bug.cgi?id=1614569

Signed-off-by: Ján Tomko <4cab11cfb98d3c937327354a78eb07dbb6ee2bc6@redhat.com>
Reviewed-by: Daniel P. Berrangé <bb938cf255e055ff3507f2627d214e8e62118fcf@redhat.com>

--- tests/qemucapsprobemock.c
+++ tests/qemucapsprobemock.c
@@ -76,7 +76,6 @@
         printLineSkipEmpty("\n", stdout);

     printLineSkipEmpty(reformatted, stdout);
-    printLineSkipEmpty("\n", stdout);
     VIR_FREE(reformatted);

     return realQemuMonitorSend(mon, msg);
@@ -117,7 +116,6 @@
             printLineSkipEmpty("\n", stdout);

         printLineSkipEmpty(json, stdout);
-        printLineSkipEmpty("\n", stdout);
     }

  cleanup:


Fix a bug in the compress cctx method

Fix a bug in the compress cctx method

--- tests/regression/method.c
+++ tests/regression/method.c
@@ -175,8 +175,8 @@
                 state->compressed.capacity,
                 input.data,
                 input.size,
-                state->dictionary.data,
-                state->dictionary.size,
+                config->use_dictionary ? state->dictionary.data : NULL,
+                config->use_dictionary ? state->dictionary.size : 0,
                 params);
         else if (config->use_dictionary)
             state->compressed.size = ZSTD_compress_usingDict(


secretxml2xmltest: refactor testCompareXMLToXMLFiles

Use g_auto where possible and remove the pointless label.

Signed-off-by: Ján Tomko <4cab11cfb98d3c937327354a78eb07dbb6ee2bc6@redhat.com>
Reviewed-by: Michal Privoznik <83d82aaba2eed257f4814b0c239c260c4caaadf0@redhat.com>

--- tests/secretxml2xmltest.c
+++ tests/secretxml2xmltest.c
@@ -10,25 +10,19 @@
 static int
 testCompareXMLToXMLFiles(const char *inxml, const char *outxml)
 {
-    char *actual = NULL;
-    int ret = -1;
-    virSecretDef *secret = NULL;
+    g_autofree char *actual = NULL;
+    g_autoptr(virSecretDef) secret = NULL;

     if (!(secret = virSecretDefParseFile(inxml)))
-        goto fail;
+        return -1;

     if (!(actual = virSecretDefFormat(secret)))
-        goto fail;
+        return -1;

     if (virTestCompareToFile(actual, outxml) < 0)
-        goto fail;
+        return -1;

-    ret = 0;
-
- fail:
-    VIR_FREE(actual);
-    virSecretDefFree(secret);
-    return ret;
+    return 0;
 }

 struct testInfo {


remove gtk-style cast that doesn't work on old gtk

--- src/hal/utils/scope_disp.c
+++ src/hal/utils/scope_disp.c
@@ -514,7 +514,7 @@
     GdkModifierType mod;
     char tip[512];

-    gdk_window_get_pointer(GDK_WINDOW(widget->window), &x, &y, &mod);
+    gdk_window_get_pointer(widget->window, &x, &y, &mod);
     z = select_trace(x, y);
     if(z != -1) {
         scope_chan_t *chan = &(ctrl_usr->chan[z-1]);


add linux x64 config

add linux x64 config

error: pathspec 'config/linux/x64/config.h' did not match any file(s) known to git

--- config/linux/x64/config.h
+++ config/linux/x64/config.h
@@ -0,0 +1,98 @@
+/* config.h.  Generated from config.h.in by configure.  */
+/* config.h.in.  Generated from configure.ac by autoheader.  */
+
+/* Define to one of `_getb67', `GETB67', `getb67' for Cray-2 and Cray-YMP
+   systems. This function is required for `alloca.c' support on those systems.
+   */
+/* #undef CRAY_STACKSEG_END */
+
+/* Define to 1 if using `alloca.c'. */
+/* #undef C_ALLOCA */
+
+/* Define to 1 if you have `alloca', as a function or macro. */
+#define HAVE_ALLOCA 1
+
+/* Define to 1 if you have <alloca.h> and it should be used (not on Ultrix).
+   */
+#define HAVE_ALLOCA_H 1
+
+/* Define to 1 if you have the <dlfcn.h> header file. */
+#define HAVE_DLFCN_H 1
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+#define HAVE_INTTYPES_H 1
+
+/* Define to 1 if you have the <memory.h> header file. */
+#define HAVE_MEMORY_H 1
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#define HAVE_STDINT_H 1
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#define HAVE_STDLIB_H 1
+
+/* Define to 1 if you have the <strings.h> header file. */
+#define HAVE_STRINGS_H 1
+
+/* Define to 1 if you have the <string.h> header file. */
+#define HAVE_STRING_H 1
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#define HAVE_SYS_STAT_H 1
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#define HAVE_SYS_TYPES_H 1
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#define HAVE_UNISTD_H 1
+
+/* Define to the sub-directory in which libtool stores uninstalled libraries.
+   */
+#define LT_OBJDIR ".libs/"
+
+/* Define to 1 if your C compiler doesn't accept -c and -o together. */
+/* #undef NO_MINUS_C_MINUS_O */
+
+/* Name of package */
+#define PACKAGE "libvorbis"
+
+/* Define to the address where bug reports for this package should be sent. */
+#define PACKAGE_BUGREPORT "vorbis-dev@xiph.org"
+
+/* Define to the full name of this package. */
+#define PACKAGE_NAME "libvorbis"
+
+/* Define to the full name and version of this package. */
+#define PACKAGE_STRING "libvorbis 1.3.3"
+
+/* Define to the one symbol short name of this package. */
+#define PACKAGE_TARNAME "libvorbis"
+
+/* Define to the home page for this package. */
+#define PACKAGE_URL ""
+
+/* Define to the version of this package. */
+#define PACKAGE_VERSION "1.3.3"
+
+/* If using the C implementation of alloca, define if you know the
+   direction of stack growth for your system; otherwise it will be
+   automatically deduced at runtime.
+	STACK_DIRECTION > 0 => grows toward higher addresses
+	STACK_DIRECTION < 0 => grows toward lower addresses
+	STACK_DIRECTION = 0 => direction of growth unknown */
+/* #undef STACK_DIRECTION */
+
+/* Define to 1 if you have the ANSI C header files. */
+#define STDC_HEADERS 1
+
+/* Version number of package */
+#define VERSION "1.3.3"
+
+/* Define to `__inline__' or `__inline' if that's what the C compiler
+   calls it, or to nothing if 'inline' is not supported under any name.  */
+#ifndef __cplusplus
+/* #undef inline */
+#endif
+
+/* Define to `unsigned int' if <sys/types.h> does not define. */
+/* #undef size_t */


InfoFluoro::Save() bug fixed

InfoFluoro::Save() bug fixed

--- cpp/common/medical/Fluoro3draParams.h
+++ cpp/common/medical/Fluoro3draParams.h
@@ -331,7 +331,7 @@
 				/*iErr =*/ FileSaveString(file, "# m_Rows // in pixel\n");
 				/*iErr =*/ FileSaveU16(file, m_Rows);
 				/*iErr =*/ FileSaveString(file, "# m_Columns // in pixel\n");
-				/*iErr =*/ FileSaveF64(file, m_Columns);
+				/*iErr =*/ FileSaveU16(file, m_Columns);
 				/*iErr =*/ FileSaveString(file, "# m_DistanceSourceToDetector // in mm\n");
 				/*iErr =*/ FileSaveF64(file, m_DistanceSourceToDetector);
 				/*iErr =*/ FileSaveString(file, "# m_DistanceSourceToPatient // in mm\n");


Removed redundant call.

Removed redundant call.

--- cpp/lib/include/ZoteroHarvesterUtil.h
+++ cpp/lib/include/ZoteroHarvesterUtil.h
@@ -321,7 +321,6 @@
     ::pthread_detach(thread_id);
     // Flagged at the very end of the routine to prevent data races.
     tasklet->setStatus(completion_status);
-    ::pthread_exit(nullptr);

     return nullptr;
 }


mbi note

mbi note

--- cpvmm/vmm/bootstrap/bootstrap_entry.c
+++ cpvmm/vmm/bootstrap/bootstrap_entry.c
@@ -1137,8 +1137,11 @@

 int prepare_linux_image_for_evmm(multiboot_info_t *mbi)
 {
-    if (linux_start==0 || initram_start==0)
-        return 1;
+    if (linux_start==0 || initram_start==0) {
+        bprint("bad linux image or initram image\n");
+        return 1;
+    }
+    //FIX(JLM): this should be linux's mbi not emmv's
     if(expand_linux_image(mbi, linux_start, linux_end-linux_start,
                        initram_start, initram_end-initram_start,
                        &linux_entry_address)!=0) {