Commit c9288854 authored by Jakub Klinkovský's avatar Jakub Klinkovský Committed by Tomáš Oberhuber
Browse files

Removed MultiArray and MultiVector classes

They were not used anywhere and will be superseded by NDArray.
parent 8d569cb1
Loading
Loading
Loading
Loading

src/TNL/Containers/MultiArray.h

deleted100644 → 0
+0 −371
Original line number Diff line number Diff line
/***************************************************************************
                          MultiArray.h  -  description
                             -------------------
    begin                : Nov 25, 2010
    copyright            : (C) 2010 by Tomas Oberhuber
    email                : tomas.oberhuber@fjfi.cvut.cz
 ***************************************************************************/

/* See Copyright Notice in tnl/Copyright */

#pragma once

#include <iostream>
#include <TNL/Containers/Array.h>
#include <TNL/Containers/StaticVector.h>
#include <TNL/Assert.h>

namespace TNL {
namespace Containers {   

template< int Dimension, typename Value = double, typename Device = Devices::Host, typename Index = int >
class MultiArray : public Array< Value, Device, Index >
{
};

template< typename Value, typename Device, typename Index >
class MultiArray< 1, Value, Device, Index > : public Array< Value, Device, Index >
{
   public:
   enum { Dimension = 1};
   typedef Value ValueType;
   typedef Device DeviceType;
   typedef Index IndexType;
   typedef MultiArray< 1, Value, Devices::Host, Index > HostType;
   typedef MultiArray< 1, Value, Devices::Cuda, Index > CudaType;


   MultiArray();

   static String getType();

   virtual String getTypeVirtual() const;

   static String getSerializationType();

   virtual String getSerializationTypeVirtual() const;

   void setDimensions( const Index iSize );

   void setDimensions( const Containers::StaticVector< 1, Index >& dimensions );

   __cuda_callable__ void getDimensions( Index& iSize ) const;

   __cuda_callable__ const Containers::StaticVector< 1, Index >& getDimensions() const;

   //! Set dimensions of the array using another array as a template
   template< typename MultiArray >
   void setLike( const MultiArray& v );
 
   void reset();

   __cuda_callable__ Index getElementIndex( const Index i ) const;

   void setElement( const Index i, Value value );

   //! This method can be used for general access to the elements of the arrays.
   /*! It does not return reference but value. So it can be used to access
    *  arrays in different address space (usually GPU device).
    *  See also operator().
    */
   Value getElement( const Index i ) const;

   //! Operator for accessing elements of the array.
   __cuda_callable__ Value& operator()( const Index i );

   __cuda_callable__ const Value& operator()( const Index i ) const;


   template< typename MultiArrayT >
   bool operator == ( const MultiArrayT& array ) const;

   template< typename MultiArrayT >
   bool operator != ( const MultiArrayT& array ) const;

   MultiArray< 1, Value, Device, Index >& operator = ( const MultiArray< 1, Value, Device, Index >& array );

   template< typename MultiArrayT >
   MultiArray< 1, Value, Device, Index >& operator = ( const MultiArrayT& array );

   //! Method for saving the object to a file as a binary data
   bool save( File& file ) const;

   //! Method for restoring the object from a file
   bool load( File& file );

   bool save( const String& fileName ) const;

   bool load( const String& fileName );

   protected:

   Containers::StaticVector< 1, Index > dimensions;
};

template< typename Value, typename Device, typename Index >
class MultiArray< 2, Value, Device, Index > : public Array< Value, Device, Index >
{
   public:
   enum { Dimension = 2 };
   typedef Value ValueType;
   typedef Device DeviceType;
   typedef Index IndexType;
   typedef MultiArray< 2, Value, Devices::Host, Index > HostType;
   typedef MultiArray< 2, Value, Devices::Cuda, Index > CudaType;


   MultiArray();

   static String getType();

   virtual String getTypeVirtual() const;

   static String getSerializationType();

   virtual String getSerializationTypeVirtual() const;

   void setDimensions( const Index jSize, const Index iSize );

   void setDimensions( const Containers::StaticVector< 2, Index >& dimensions );

   __cuda_callable__ void getDimensions( Index& jSize, Index& iSize ) const;

   __cuda_callable__ const Containers::StaticVector< 2, Index >& getDimensions() const;

   //! Set dimensions of the array using another array as a template
   template< typename MultiArray >
   void setLike( const MultiArray& v );

   void reset();

   __cuda_callable__ Index getElementIndex( const Index j, const Index i ) const;

   void setElement( const Index j, const Index i, Value value );

   //! This method can be used for general access to the elements of the arrays.
   /*! It does not return reference but value. So it can be used to access
    *  arrays in different adress space (usualy GPU device).
    *  See also operator().
    */
   Value getElement( const Index j, const Index i ) const;

   //! Operator for accessing elements of the array.
   /*! It returns reference to given elements so it cannot be
    *  used to access elements of arrays in different address space
    *  (GPU device usually).
    */
   __cuda_callable__ Value& operator()( const Index j, const Index i );

   __cuda_callable__ const Value& operator()( const Index j, const Index i ) const;

   template< typename MultiArrayT >
   bool operator == ( const MultiArrayT& array ) const;

   template< typename MultiArrayT >
   bool operator != ( const MultiArrayT& array ) const;

   MultiArray< 2, Value, Device, Index >& operator = ( const MultiArray< 2, Value, Device, Index >& array );

   template< typename MultiArrayT >
   MultiArray< 2, Value, Device, Index >& operator = ( const MultiArrayT& array );

   //! Method for saving the object to a file as a binary data
   bool save( File& file ) const;

   //! Method for restoring the object from a file
   bool load( File& file );

   bool save( const String& fileName ) const;

   bool load( const String& fileName );

   protected:

   Containers::StaticVector< 2, Index > dimensions;
};

template< typename Value, typename Device, typename Index >
class MultiArray< 3, Value, Device, Index > : public Array< Value, Device, Index >
{
   public:

   enum { Dimension = 3 };
   typedef Value ValueType;
   typedef Device DeviceType;
   typedef Index IndexType;
   typedef MultiArray< 3, Value, Devices::Host, Index > HostType;
   typedef MultiArray< 3, Value, Devices::Cuda, Index > CudaType;


   MultiArray();

   static String getType();

   virtual String getTypeVirtual() const;

   static String getSerializationType();

   virtual String getSerializationTypeVirtual() const;

   void setDimensions( const Index k, const Index j, const Index iSize );

   void setDimensions( const Containers::StaticVector< 3, Index >& dimensions );

   __cuda_callable__ void getDimensions( Index& k, Index& j, Index& iSize ) const;

   __cuda_callable__ const Containers::StaticVector< 3, Index >& getDimensions() const;

   //! Set dimensions of the array using another array as a template
   template< typename MultiArrayT >
   void setLike( const MultiArrayT& v );

   void reset();

   __cuda_callable__ Index getElementIndex( const Index k, const Index j, const Index i ) const;

   void setElement( const Index k, const Index j, const Index i, Value value );

   //! This method can be used for general access to the elements of the arrays.
   /*! It does not return reference but value. So it can be used to access
    *  arrays in different adress space (usualy GPU device).
    *  See also operator().
    */
   Value getElement( const Index k, const Index j, const Index i ) const;

   //! Operator for accessing elements of the array.
   /*! It returns reference to given elements so it cannot be
    *  used to access elements of arrays in different adress space
    *  (GPU device usualy).
    */
   __cuda_callable__ Value& operator()( const Index k, const Index j, const Index i );

   __cuda_callable__ const Value& operator()( const Index k, const Index j, const Index i ) const;

   template< typename MultiArrayT >
   bool operator == ( const MultiArrayT& array ) const;

   template< typename MultiArrayT >
   bool operator != ( const MultiArrayT& array ) const;

   MultiArray< 3, Value, Device, Index >& operator = ( const MultiArray< 3, Value, Device, Index >& array );

   template< typename MultiArrayT >
   MultiArray< 3, Value, Device, Index >& operator = ( const MultiArrayT& array );

   //! Method for saving the object to a file as a binary data
   bool save( File& file ) const;

   //! Method for restoring the object from a file
   bool load( File& file );

   bool save( const String& fileName ) const;

   bool load( const String& fileName );

   protected:

   Containers::StaticVector< 3, Index > dimensions;
};

template< typename Value, typename Device, typename Index >
class MultiArray< 4, Value, Device, Index > : public Array< Value, Device, Index >
{
   public:

   enum { Dimension = 4 };
   typedef Value ValueType;
   typedef Device DeviceType;
   typedef Index IndexType;
   typedef MultiArray< 4, Value, Devices::Host, Index > HostType;
   typedef MultiArray< 4, Value, Devices::Cuda, Index > CudaType;


   MultiArray();

   static String getType();

   virtual String getTypeVirtual() const;

   static String getSerializationType();

   virtual String getSerializationTypeVirtual() const;

   void setDimensions( const Index l, const Index k, const Index j, const Index iSize );

   void setDimensions( const Containers::StaticVector< 4, Index >& dimensions );

   __cuda_callable__ void getDimensions( Index& l, Index& k, Index& j, Index& iSize ) const;

   __cuda_callable__ const Containers::StaticVector< 4, Index >& getDimensions() const;

   //! Set dimensions of the array using another array as a template
   template< typename MultiArrayT >
   void setLike( const MultiArrayT& v );

   void reset();

   __cuda_callable__ Index getElementIndex( const Index l, const Index k, const Index j, const Index i ) const;

   void setElement( const Index l, const Index k, const Index j, const Index i, Value value );

   //! This method can be used for general access to the elements of the arrays.
   /*! It does not return reference but value. So it can be used to access
    *  arrays in different adress space (usualy GPU device).
    *  See also operator().
    */
   Value getElement( const Index l, const Index k, const Index j, const Index i ) const;

   //! Operator for accessing elements of the array.
   /*! It returns reference to given elements so it cannot be
    *  used to access elements of arrays in different adress space
    *  (GPU device usualy).
    */
   __cuda_callable__ Value& operator()( const Index l, const Index k, const Index j, const Index i );

   __cuda_callable__ const Value& operator()( const Index l, const Index k, const Index j, const Index i ) const;

   template< typename MultiArrayT >
   bool operator == ( const MultiArrayT& array ) const;

   template< typename MultiArrayT >
   bool operator != ( const MultiArrayT& array ) const;

   MultiArray< 4, Value, Device, Index >& operator = ( const MultiArray< 4, Value, Device, Index >& array );

   template< typename MultiArrayT >
   MultiArray< 4, Value, Device, Index >& operator = ( const MultiArrayT& array );

   //! Method for saving the object to a file as a binary data
   bool save( File& file ) const;

   //! Method for restoring the object from a file
   bool load( File& file );

   bool save( const String& fileName ) const;

   bool load( const String& fileName );

   protected:

   Containers::StaticVector< 4, Index > dimensions;
};

template< typename Value, typename device, typename Index >
std::ostream& operator << ( std::ostream& str, const MultiArray< 1, Value, device, Index >& array );

template< typename Value, typename device, typename Index >
std::ostream& operator << ( std::ostream& str, const MultiArray< 2, Value, device, Index >& array );

template< typename Value, typename device, typename Index >
std::ostream& operator << ( std::ostream& str, const MultiArray< 3, Value, device, Index >& array );

template< typename Value, typename device, typename Index >
std::ostream& operator << ( std::ostream& str, const MultiArray< 4, Value, device, Index >& array );

} // namespace Containers
} // namespace TNL

#include <TNL/Containers/MultiArray1D_impl.h>
#include <TNL/Containers/MultiArray2D_impl.h>
#include <TNL/Containers/MultiArray3D_impl.h>
#include <TNL/Containers/MultiArray4D_impl.h>
+0 −241
Original line number Diff line number Diff line
/***************************************************************************
                          MultiArray1D_impl.h  -  description
                             -------------------
    begin                : Nov 13, 2012
    copyright            : (C) 2012 by Tomas Oberhuber
    email                : tomas.oberhuber@fjfi.cvut.cz
 ***************************************************************************/

/* See Copyright Notice in tnl/Copyright */

#pragma once 

namespace TNL {
namespace Containers {   

template< typename Value, typename Device, typename Index >
MultiArray< 1, Value, Device, Index > :: MultiArray()
{
}

template< typename Value, typename Device, typename Index >
String MultiArray< 1, Value, Device, Index > :: getType()
{
   return String( "Containers::MultiArray< ") +
          String( Dimension ) +
          String( ", " ) +
          String( TNL::getType< Value >() ) +
          String( ", " ) +
          String( Device :: getDeviceType() ) +
          String( ", " ) +
          String( TNL::getType< Index >() ) +
          String( " >" );
}

template< typename Value,
          typename Device,
          typename Index >
String MultiArray< 1, Value, Device, Index > :: getTypeVirtual() const
{
   return this->getType();
};

template< typename Value,
          typename Device,
          typename Index >
String MultiArray< 1, Value, Device, Index > :: getSerializationType()
{
   return HostType::getType();
};

template< typename Value,
          typename Device,
          typename Index >
String MultiArray< 1, Value, Device, Index > :: getSerializationTypeVirtual() const
{
   return this->getSerializationType();
};

template< typename Value, typename Device, typename Index >
void MultiArray< 1, Value, Device, Index > :: setDimensions( const Index iSize )
{
   TNL_ASSERT( iSize > 0,
              std::cerr << "iSize = " << iSize );
   dimensions[ 0 ] = iSize;
   Array< Value, Device, Index >::setSize( iSize );
}

template< typename Value, typename Device, typename Index >
void MultiArray< 1, Value, Device, Index > :: setDimensions( const Containers::StaticVector< 1, Index >& dimensions )
{
   TNL_ASSERT( dimensions[ 0 ] > 0,
              std::cerr << " dimensions[ 0 ] = " << dimensions[ 0 ] );
   this->dimensions = dimensions;
   Array< Value, Device, Index >::setSize( this->dimensions[ 0 ] );
}

template< typename Value, typename Device, typename Index >
   template< typename MultiArrayT >
void MultiArray< 1, Value, Device, Index > :: setLike( const MultiArrayT& multiArray )
{
   setDimensions( multiArray. getDimensions() );
}

template< typename Value, typename Device, typename Index >
void MultiArray< 1, Value, Device, Index >::reset()
{
   this->dimensions = Containers::StaticVector< 1, Index >( ( Index ) 0 );
   Array< Value, Device, Index >::reset();
}

template< typename Value, typename Device, typename Index >
__cuda_callable__
void MultiArray< 1, Value, Device, Index > :: getDimensions( Index& xSize ) const
{
   xSize = this->dimensions[ 0 ];
}

template< typename Value, typename Device, typename Index >
__cuda_callable__
const Containers::StaticVector< 1, Index >& MultiArray< 1, Value, Device, Index > :: getDimensions() const
{
   return this->dimensions;
}

template< typename Value, typename Device, typename Index >
__cuda_callable__
Index MultiArray< 1, Value, Device, Index > :: getElementIndex( const Index i ) const
{
   TNL_ASSERT( i >= 0 && i < this->dimensions[ 0 ],
              std::cerr << "i = " << i << " this->dimensions[ 0 ] = " <<  this->dimensions[ 0 ] );
   return i;
}

template< typename Value, typename Device, typename Index >
Value MultiArray< 1, Value, Device, Index > :: getElement( const Index i ) const
{
   return Array< Value, Device, Index > :: getElement( getElementIndex( i ) );
}

template< typename Value, typename Device, typename Index >
void MultiArray< 1, Value, Device, Index > :: setElement( const Index i, Value value )
{
   Array< Value, Device, Index > :: setElement( getElementIndex( i ), value );
}

template< typename Value, typename Device, typename Index >
__cuda_callable__
Value& MultiArray< 1, Value, Device, Index > :: operator()( const Index element )
{
   return Array< Value, Device, Index > :: operator[]( getElementIndex( element ) );
}

template< typename Value, typename Device, typename Index >
__cuda_callable__
const Value& MultiArray< 1, Value, Device, Index > :: operator()( const Index element ) const
{
   return Array< Value, Device, Index > :: operator[]( getElementIndex( element ) );
}

template< typename Value, typename Device, typename Index >
   template< typename MultiArrayT >
bool MultiArray< 1, Value, Device, Index > :: operator == ( const MultiArrayT& array ) const
{
   // TODO: Static assert on dimensions
   TNL_ASSERT( this->getDimensions() == array. getDimensions(),
              std::cerr << "You are attempting to compare two arrays with different dimensions." << std::endl
                   << "First array dimensions are ( " << this->getDimensions() << " )" << std::endl
                   << "Second array dimensions are ( " << array. getDimensions() << " )" << std::endl; );
   return Array< Value, Device, Index > :: operator == ( array );
}

template< typename Value, typename Device, typename Index >
   template< typename MultiArrayT >
bool MultiArray< 1, Value, Device, Index > :: operator != ( const MultiArrayT& array ) const
{
   return ! ( (* this ) == array );
}

template< typename Value, typename Device, typename Index >
MultiArray< 1, Value, Device, Index >&
   MultiArray< 1, Value, Device, Index > :: operator = ( const MultiArray< 1, Value, Device, Index >& array )
{
   // TODO: Static assert on dimensions
   TNL_ASSERT( this->getDimensions() == array. getDimensions(),
              std::cerr << "You are attempting to assign two arrays with different dimensions." << std::endl
                   << "First array dimensions are ( " << this->getDimensions() << " )" << std::endl
                   << "Second array dimensions are ( " << array. getDimensions() << " )" << std::endl; );
   Array< Value, Device, Index > :: operator = ( array );
   return ( *this );
}

template< typename Value, typename Device, typename Index >
   template< typename MultiArrayT >
MultiArray< 1, Value, Device, Index >&
   MultiArray< 1, Value, Device, Index > :: operator = ( const MultiArrayT& array )
{
   // TODO: Static assert on dimensions
   TNL_ASSERT( this->getDimensions() == array. getDimensions(),
              std::cerr << "You are attempting to assign two arrays with different dimensions." << std::endl
                   << "First array dimensions are ( " << this->getDimensions() << " )" << std::endl
                   << "Second array dimensions are ( " << array. getDimensions() << " )" << std::endl; );
   Array< Value, Device, Index > :: operator = ( array );
   return ( *this );
}

template< typename Value, typename Device, typename Index >
bool MultiArray< 1, Value, Device, Index > :: save( File& file ) const
{
   if( ! Array< Value, Device, Index > :: save( file ) )
   {
      std::cerr << "I was not able to write the Array of MultiArray." << std::endl;
      return false;
   }
   if( ! dimensions. save( file ) )
   {
      std::cerr << "I was not able to write the dimensions of MultiArray." << std::endl;
      return false;
   }
   return true;
}

template< typename Value, typename Device, typename Index >
bool MultiArray< 1, Value, Device, Index > :: load( File& file )
{
   if( ! Array< Value, Device, Index > :: load( file ) )
   {
      std::cerr << "I was not able to read the Array of MultiArray." << std::endl;
      return false;
   }
   if( ! dimensions. load( file ) )
   {
      std::cerr << "I was not able to read the dimensions of MultiArray." << std::endl;
      return false;
   }
   return true;
}

template< typename Value, typename Device, typename Index >
bool MultiArray< 1, Value, Device, Index > :: save( const String& fileName ) const
{
   return Object :: save( fileName );
}

template< typename Value, typename Device, typename Index >
bool MultiArray< 1, Value, Device, Index > :: load( const String& fileName )
{
   return Object :: load( fileName );
}

template< typename Value, typename Device, typename Index >
std::ostream& operator << ( std::ostream& str, const MultiArray< 1, Value, Device, Index >& array )
{
   for( Index i = 0; i < array. getDimensions()[ 0 ]; i ++ )
   {
      str << array. getElement( i ) << " ";
   }
   return str;
}

} // namespace Containers
} // namespace TNL
+0 −255

File deleted.

Preview size limit exceeded, changes collapsed.

+0 −271

File deleted.

Preview size limit exceeded, changes collapsed.

+0 −290

File deleted.

Preview size limit exceeded, changes collapsed.

Loading