<!--these sections will sit under sect1 - Implementation Issues-->

<sect2><title>CepMatrix and Template Classes</title>

  <sect3><title>Introduction</title>
  <para>At a very early stage in the design of the <command>GDMS</command> it became clear that some form of matrix object would be
  required, capable of fulfilling following requirements:-
  </para>
<itemizedlist>
    <listitem><para>Storage of a given data set and the results of any transformation preformed on it.</para></listitem>
    <listitem><para>Capability of preforming matrix operations including addition, subtraction,  with either another
    matrix or by a scalar value, division and transposition. In addition, support for many other operations was required
    in order to preform all the functionality of this system.</para></listitem>
    <listitem><para>Support for both two and three dimensional matrices.</para></listitem>
  </itemizedlist>
  
  <para>
  In addition, the matrix object itself had to be fast, flexible and reliable as it lies a the heart of the <command>GDMS</command>.
  In order to meet these requirements, therefore, the <command>cepMatrix</command> class template was created.
  </para>
  </sect3> <!--Introduction-->

  <sect3><title>Storage of data sets</title>
  
  <para>The first problem encountered in creating the <command>cepMatrix</command> was the need to support multiple
  data types. This was due to the fact that while the original data sets themselves as well as the transformations in the time domain
  were all of type <command>double</command>, once a transformation into the frequency domain was conducted the data became of type
  <command>complex</command>. This problem was overcome, however, by using one of the most powerful C++ functions, namely Template 
  Classes. A Template Class works by creating a class which is unrestricted by data type. The data type of the object itself
  is only specified when the object is instantiated, thereby allowing the same segment of code inside the Template Class to
  work with multiple types of data such as <command>int</command>, <command>float</command>, <command>double</command> and 
  <command>complex</command>. 
  </para>
  
  </sect3><!--Storage of data sets-->
  
  <sect3><title>cepMatrix operations</title>
  
  <para>Another key requirement of <command>cepMatrix</command> was the ability to carry out a whole range of matrix operations such
  as addition, subtraction, division and transposition. Much of this functionality was achieved by the use of  
  operator overloading. The method of operation overloading is another feature of C++ that allows the
  simplification of function calls, especially when relating to mathematical operations. For example, in order to add 
  matrices <command>A</command> and <command>B</command> together and save the results in <command>A</command> without operator
  overloading may look like this:- 
  </para>
  
  
  <programlisting>
  copy(A, multiply(A,B));
  </programlisting>
  
  <para>
  Conversely, if the += operator were overloaded the problem would simplify to
  </para>
  
 <programlisting>
  A += B;
 </programlisting>  
  
  <para>
  which is much easier to understand and actually removes a function call. In <command>cepMatrix</command> the following operations
  are overloaded:-
</para>
  
  <itemizedlist>
    <listitem><para>A += B :- adds matrix B to matrix A and stores the result in matrix A</para></listitem>
    <listitem><para>A -= B :- subtracts matrix B from matrix A and stores the result in matrix A</para></listitem>
    <listitem><para>A *= B :- multiplies matrix A by matrix B and stores the result in matrix A</para></listitem>
    <listitem><para>A *= c :- multiplies matrix A by the scalar value c and stores the result in matrix A</para></listitem>
    <listitem><para>A /= B :- divides matrix A by matrix B stores the result in matrix A</para></listitem>
    <listitem><para>A = B  :- copies matrix B to matrix A</para></listitem>
    <listitem><para>A == B :- returns true if matrix A is equal to matrix B</para></listitem>
    <listitem><para>A != B :- returns true is matrix A is not equal to matrix B</para></listitem>
  </itemizedlist>
  
  
  <para>
  The <command>cepMatrix</command> Class Template also supports other operations built to facilitate implementation inside the
  <command>GDMS</command> application. This includes an operation to query the matrix and determine if it is a strictly diagonal
  and operations to determine the maximum and minimum values of a given column in a matrix. There is also an operation
  to resize a matrix by adding a given number of rows to it. In addition, there are several get and set accesor methods provided 
  for accessing individual elements of a given matrix.
  </para>
 
  </sect3><!--cepMatrix operations-->
  
  <sect3><title>Two Dimensional and Three Dimensional Matrices</title>
  
  <para>A third, key requirement of the <command>cepMatrix</command> Template Class was support for both two and three dimensional
  matrices. This is due to the fact that when data is windowed it requires a new matrix for each frame that is returned. It was
  decided that the preferred method of dealing with this problem was to keep all the data inside one <command>cepMatrix</command>
  object rather than having to use another container such as an array or vector. This, in turn, enabled the passing of data between
  objects in a uniform way and simplified the function calls required to access the given data. 
  </para>
  
  <para>
  Due to the fact that it was not strictly necessary to add any extra functionality and time constraints, three dimensional 
  matrices are implemented purely as storage devices. As such, there is limited support for these matrices 
  inside this object, that is, they can be created, accessed and copied but they can not be used in any other matrix operations 
  such as multiplication, addition, subtraction and division.
  </para>
    
  <para>Both two dimensional and three dimensional matrices are stored as arrays and are treated as separate member variables within 
  the <command>cepMatrix</command> Template Classes. This approach was taken for several reasons, firstly due to the fact that
  <command>cepMatrix</command> is a Template class all member variables had to be of a primitive type, that is, other templates
  can not be instantiated inside these classes. This restriction on Template Classes is actually a compiler dependent and 
  is not a limitation of the language specification, per se. It does, however, arise when using <command>g++</command> which is 
  the most widely use compiler on the operating systems in which the <command>GDMS</command> is required to be used. 
  This limitation, was therefore, applied the to <command>cepMatrix</command> class and thus each matrix was stored, 
  internally as an array. In addition, the decision to treat two dimensional and three dimensional matrices as separate member 
  variables was made for reasons speed in preforming matrix operations. This is due to the fact that if all matrices were stored 
  using the same member variable, that is, the three dimensional member variable it would mean that an extra memory reference 
  would be incurred each time a matrix element is accessed. Consequently, some matrix operations would take almost twice as
  long to complete.   
  </para>
  </sect3>
  
  
  
  <sect3><title>Future Enhancements</title>
  <para>Whilst the <command>cepMatrix</command> Template Class includes all the functionality required to of it to be a powerful
  tool inside the <command>GDMS</command> system there are a few enhancements that could be made. As mentioned, three dimensional 
  matrices, unlike two dimensional matrices have very limited functionality inside this class. In future releases, it would be
  anticipated that three dimensional matrices have all the functionality associated with two dimensional matrices. Other future
  enhancements that could be made, would be to allow greater flexibility in re-sizing matrices, the implementation of
  iterators and the overloading of the [] operators to make the <command>cepMatrix</command> Template Class a full C++ Template
  container.</para>
  </sect3> <!--Future Enahncements-->

</sect2> <!--Template Classes-->

