libflame revision_anchor
Functions
FLA_Max_abs_value.c File Reference

(r)

Functions

FLA_Error FLA_Max_abs_value (FLA_Obj A, FLA_Obj amax)

Function Documentation

FLA_Error FLA_Max_abs_value ( FLA_Obj  A,
FLA_Obj  amax 
)

References FLA_Check_error_level(), FLA_Max_abs_value_check(), FLA_Obj_col_stride(), FLA_Obj_datatype(), FLA_Obj_length(), FLA_Obj_row_stride(), FLA_Obj_width(), dcomplex::imag, scomplex::imag, dcomplex::real, and scomplex::real.

Referenced by FLA_Norm1(), and FLA_Norm_inf().

{
  FLA_Datatype datatype;
  FLA_Datatype dt_amax;
  dim_t        i, j;
  dim_t        m_A, n_A;
  dim_t        rs_A, cs_A;

  if ( FLA_Check_error_level() >= FLA_MIN_ERROR_CHECKING )
    FLA_Max_abs_value_check( A, amax );

  datatype = FLA_Obj_datatype( A );
  dt_amax  = FLA_Obj_datatype( amax );

  m_A      = FLA_Obj_length( A );
  n_A      = FLA_Obj_width( A );
  rs_A     = FLA_Obj_row_stride( A );
  cs_A     = FLA_Obj_col_stride( A );
 
 
  switch ( datatype ){

  case FLA_FLOAT:
  {
    float *buff_A     = ( float * ) FLA_FLOAT_PTR( A );
    float *buff_amax  = ( float * ) FLA_FLOAT_PTR( amax );
    float  curr_amax;
    float  temp_amax;

    // Initialize the search with the absolute value of the first element.
    curr_amax = ( float ) fabs( buff_A[0] );

    // Inspect each element, saving values in curr_amax that are larger than
    // the previous elements.
    for( j = 0; j < n_A; j++ )
    {
      for( i = 0; i < m_A; i++ )
      {
        temp_amax = ( float ) fabs( buff_A[ j*cs_A + i*rs_A ] );

        if ( curr_amax < temp_amax )
          curr_amax = temp_amax;
      }
    }

    // Copy the result into the amax object buffer.
    *buff_amax = curr_amax;

    break;
  }

  case FLA_DOUBLE:
  {
    double *buff_A     = ( double * ) FLA_DOUBLE_PTR( A );
    double *buff_amax  = ( double * ) FLA_DOUBLE_PTR( amax );
    double  curr_amax;
    double  temp_amax;

    // Initialize the search with the absolute value of the first element.
    curr_amax = ( double ) fabs( buff_A[0] );

    // Inspect each element, saving values in curr_amax that are larger than
    // the previous elements.
    for( j = 0; j < n_A; j++ )
    {
      for( i = 0; i < m_A; i++ )
      {
        temp_amax = ( double ) fabs( buff_A[ j*cs_A + i*rs_A ] );

        if ( curr_amax < temp_amax )
          curr_amax = temp_amax;
      }
    }

    // Copy the result into the amax object buffer.
    *buff_amax = curr_amax;


    break;
  }

  case FLA_COMPLEX:
  {
    if ( dt_amax == FLA_FLOAT )
    {
      scomplex *buff_A     = ( scomplex * ) FLA_COMPLEX_PTR( A );
      float    *buff_amax  = ( float    * ) FLA_FLOAT_PTR( amax );
      scomplex *temp_value;
      float     curr_amax;
      float     temp_amax;

      // Initialize the search with the absolute value of the first element.
      temp_value = buff_A;
      curr_amax = ( float  ) sqrt( temp_value->real * temp_value->real + 
                                   temp_value->imag * temp_value->imag ); 

      // Inspect each element, saving values in curr_amax that are larger than
      // the previous elements.
      for( j = 0; j < n_A; j++ )
      {
        for( i = 0; i < m_A; i++ )
        {
          temp_value = buff_A + j*cs_A + i*rs_A;
          temp_amax = ( float  ) sqrt( temp_value->real * temp_value->real + 
                                       temp_value->imag * temp_value->imag ); 
          if ( curr_amax < temp_amax )
            curr_amax = temp_amax;
        }
      }

      // Copy the result into the amax object buffer.
      *buff_amax = curr_amax;
    }
    else if ( dt_amax == FLA_COMPLEX )
    {
      scomplex *buff_A     = ( scomplex * ) FLA_COMPLEX_PTR( A );
      scomplex *buff_amax  = ( scomplex * ) FLA_COMPLEX_PTR( amax );
      scomplex *temp_value;
      float     curr_amax;
      float     temp_amax;

      // Initialize the search with the absolute value of the first element.
      temp_value = buff_A;
      curr_amax = ( float  ) sqrt( temp_value->real * temp_value->real + 
                                   temp_value->imag * temp_value->imag ); 

      // Inspect each element, saving values in curr_amax that are larger than
      // the previous elements.
      for( j = 0; j < n_A; j++ )
      {
        for( i = 0; i < m_A; i++ )
        {
          temp_value = buff_A + j*cs_A + i*rs_A;
          temp_amax = ( float  ) sqrt( temp_value->real * temp_value->real + 
                                       temp_value->imag * temp_value->imag ); 
          if ( curr_amax < temp_amax )
            curr_amax = temp_amax;
        }
      }

      // Copy the result into the amax object buffer.
      buff_amax->real = curr_amax;
      buff_amax->imag = 0.0F;
    }

    break;
  }

  case FLA_DOUBLE_COMPLEX:
  {
    if ( dt_amax == FLA_DOUBLE )
    {
      dcomplex *buff_A     = ( dcomplex * ) FLA_DOUBLE_COMPLEX_PTR( A );
      double   *buff_amax  = ( double   * ) FLA_DOUBLE_PTR( amax );
      dcomplex *temp_value;
      double    curr_amax;
      double    temp_amax;

      // Initialize the search with the absolute value of the first element.
      temp_value = buff_A;
      curr_amax = ( double ) sqrt( temp_value->real * temp_value->real + 
                                   temp_value->imag * temp_value->imag ); 

      // Inspect each element, saving values in curr_amax that are larger than
      // the previous elements.
      for( j = 0; j < n_A; j++ )
      {
        for( i = 0; i < m_A; i++ )
        {
          temp_value = buff_A + j*cs_A + i*rs_A;
          temp_amax = ( double ) sqrt( temp_value->real * temp_value->real + 
                                       temp_value->imag * temp_value->imag ); 
          if ( curr_amax < temp_amax )
            curr_amax = temp_amax;
        }
      }

      // Copy the result into the amax object buffer.
      *buff_amax = curr_amax;
    }
    else if ( dt_amax == FLA_DOUBLE_COMPLEX )
    {
      dcomplex *buff_A     = ( dcomplex * ) FLA_DOUBLE_COMPLEX_PTR( A );
      dcomplex *buff_amax  = ( dcomplex * ) FLA_DOUBLE_COMPLEX_PTR( amax );
      dcomplex *temp_value;
      double    curr_amax;
      double    temp_amax;

      // Initialize the search with the absolute value of the first element.
      temp_value = buff_A;
      curr_amax = ( double ) sqrt( temp_value->real * temp_value->real + 
                                   temp_value->imag * temp_value->imag ); 

      // Inspect each element, saving values in curr_amax that are larger than
      // the previous elements.
      for( j = 0; j < n_A; j++ )
      {
        for( i = 0; i < m_A; i++ )
        {
          temp_value = buff_A + j*cs_A + i*rs_A;
          temp_amax = ( double ) sqrt( temp_value->real * temp_value->real + 
                                       temp_value->imag * temp_value->imag ); 
          if ( curr_amax < temp_amax )
            curr_amax = temp_amax;
        }
      }

      // Copy the result into the amax object buffer.
      buff_amax->real = curr_amax;
      buff_amax->imag = 0.0;
    }

    break;
  }

  }

  return FLA_SUCCESS;
}