/** @brief Deals with A -= B  for a matrix B */
    inline void execute_matrix_col_inplace_sub_matrix(statement const & s)
    {
      typedef statement::container_type   StatementContainer;

      StatementContainer const & expr = s.array();

      if (expr[0].lhs_type_ == MATRIX_COL_FLOAT_TYPE && expr[0].rhs_type_ == MATRIX_COL_FLOAT_TYPE)
      {
        viennacl::matrix_base<float, viennacl::column_major>       & A = *(expr[0].lhs_.matrix_col_float_);
        viennacl::matrix_base<float, viennacl::column_major> const & B = *(expr[0].rhs_.matrix_col_float_);
        viennacl::linalg::ambm(A,
                               A,  1.0, 1, false, false,
                               B, -1.0, 1, false, false);
      }
      else if (expr[0].lhs_type_ == MATRIX_COL_DOUBLE_TYPE && expr[0].rhs_type_ == MATRIX_COL_DOUBLE_TYPE)
      {
        viennacl::matrix_base<double, viennacl::column_major>       & A = *(expr[0].lhs_.matrix_col_double_);
        viennacl::matrix_base<double, viennacl::column_major> const & B = *(expr[0].rhs_.matrix_col_double_);
        viennacl::linalg::ambm(A,
                               A,  1.0, 1, false, false,
                               B, -1.0, 1, false, false);
      }
      else
        throw "not yet supported!";
    }
Example #2
0
    /** @brief Deals with x = y  for a vector y */
    inline void execute_vector_inplace_add_vector(statement const & s)
    {
      typedef statement::container_type   StatementContainer;

      StatementContainer const & expr = s.array();

      if (expr[0].lhs_type_ == VECTOR_FLOAT_TYPE && expr[0].rhs_type_ == VECTOR_FLOAT_TYPE)
      {
        viennacl::vector_base<float>       & x = *(expr[0].lhs_.vector_float_);
        viennacl::vector_base<float> const & y = *(expr[0].rhs_.vector_float_);
        viennacl::linalg::avbv(x,
                               x,  1.0, 1, false, false,
                               y,  1.0, 1, false, false);
      }
      else if (expr[0].lhs_type_ == VECTOR_DOUBLE_TYPE && expr[0].rhs_type_ == VECTOR_DOUBLE_TYPE)
      {
        viennacl::vector_base<double>       & x = *(expr[0].lhs_.vector_double_);
        viennacl::vector_base<double> const & y = *(expr[0].rhs_.vector_double_);
        viennacl::linalg::avbv(x,
                               x,  1.0, 1, false, false,
                               y,  1.0, 1, false, false);
      }
      else
        throw statement_not_supported_exception("Unsupported rvalue for inplace-add to vector");
    }
    /** @brief Deals with x = y  for a vector y */
    void execute_vector_inplace_sub_vector(statement const & s)
    {
      typedef typename statement::container_type   StatementContainer;

      StatementContainer const & expr = s.array();

      if (expr[0].lhs_type_ == VECTOR_FLOAT_TYPE && expr[0].rhs_type_ == VECTOR_FLOAT_TYPE)
      {
        viennacl::vector_base<float>       & x = *(expr[0].lhs_.vector_float_);
        viennacl::vector_base<float> const & y = *(expr[0].rhs_.vector_float_);
        viennacl::linalg::avbv(x,
                               x,  1.0, 1, false, false,
                               y, -1.0, 1, false, false);
      }
      else if (expr[0].lhs_type_ == VECTOR_DOUBLE_TYPE && expr[0].rhs_type_ == VECTOR_DOUBLE_TYPE)
      {
        viennacl::vector_base<double>       & x = *(expr[0].lhs_.vector_double_);
        viennacl::vector_base<double> const & y = *(expr[0].rhs_.vector_double_);
        viennacl::linalg::avbv(x,
                               x,  1.0, 1, false, false,
                               y, -1.0, 1, false, false);
      }
      else
        throw "not yet supported!";
    }
Example #4
0
    /** @brief Generic dispatcher */
    inline void execute_scalar_assign(statement const & s)
    {
      typedef statement::container_type   StatementContainer;

      StatementContainer const & expr = s.array();

      switch (expr[0].rhs_type_family_)
      {
        case COMPOSITE_OPERATION_FAMILY:
          execute_scalar_assign_composite(s);
          break;
        default:
          throw statement_not_supported_exception("Unsupported rvalue on root node for operation on scalar.");
      }
    }
Example #5
0
    /** @brief Generic dispatcher */
    inline void execute_matrix_row_assign(statement const & s)
    {
      typedef statement::container_type   StatementContainer;

      StatementContainer const & expr = s.array();

      switch (expr[0].rhs_type_family_)
      {
        case COMPOSITE_OPERATION_FAMILY:
          execute_matrix_row_assign_composite(s);
          break;
        case MATRIX_ROW_TYPE_FAMILY:
          execute_matrix_row_assign_matrix(s);
          break;
        default:
          throw statement_not_supported_exception("Invalid rvalue encountered in row-major matrix assignment");
      }
    }
    /** @brief Generic dispatcher */
    inline void execute_matrix_col_inplace_sub(statement const & s)
    {
      typedef statement::container_type   StatementContainer;

      StatementContainer const & expr = s.array();

      switch (expr[0].rhs_type_family_)
      {
        case COMPOSITE_OPERATION_FAMILY:
          execute_matrix_col_inplace_sub_composite(s);
          break;
        case MATRIX_COL_TYPE_FAMILY:
          execute_matrix_col_inplace_sub_matrix(s);
          break;
        default:
          throw "invalid rvalue in vector assignment";
      }
    }
    /** @brief Generic dispatcher */
    void execute_vector_assign(statement const & s)
    {
      typedef typename statement::container_type   StatementContainer;

      StatementContainer const & expr = s.array();

      switch (expr[0].rhs_type_family_)
      {
        case COMPOSITE_OPERATION_FAMILY:
          execute_vector_assign_composite(s);
          break;
        case VECTOR_TYPE_FAMILY:
          execute_vector_assign_vector(s);
          break;
        default:
          throw "invalid rvalue in vector assignment";
      }
    }
Example #8
0
    /** @brief Generic dispatcher */
    inline void execute_vector_inplace_add(statement const & s)
    {
      typedef statement::container_type   StatementContainer;

      StatementContainer const & expr = s.array();

      switch (expr[0].rhs_type_family_)
      {
        case COMPOSITE_OPERATION_FAMILY:
          execute_vector_inplace_add_composite(s);
          break;
        case VECTOR_TYPE_FAMILY:
          execute_vector_inplace_add_vector(s);
          break;
        default:
          throw statement_not_supported_exception("Invalid rvalue encountered in vector inplace-add");
      }
    }
Example #9
0
    /** @brief Deals with A = B  for a matrix B */
    inline void execute_matrix_row_assign_matrix(statement const & s)
    {
      typedef statement::container_type   StatementContainer;

      StatementContainer const & expr = s.array();

      if (expr[0].lhs_type_ == MATRIX_ROW_FLOAT_TYPE && expr[0].rhs_type_ == MATRIX_ROW_FLOAT_TYPE)
      {
        viennacl::matrix_base<float, viennacl::row_major>       & A = *(expr[0].lhs_.matrix_row_float_);
        viennacl::matrix_base<float, viennacl::row_major> const & B = *(expr[0].rhs_.matrix_row_float_);
        viennacl::linalg::am(A,
                             B, 1.0, 1, false, false);
      }
      else if (expr[0].lhs_type_ == MATRIX_ROW_DOUBLE_TYPE && expr[0].rhs_type_ == MATRIX_ROW_DOUBLE_TYPE)
      {
        viennacl::matrix_base<double, viennacl::row_major>       & A = *(expr[0].lhs_.matrix_row_double_);
        viennacl::matrix_base<double, viennacl::row_major> const & B = *(expr[0].rhs_.matrix_row_double_);
        viennacl::linalg::am(A,
                             B, 1.0, 1, false, false);
      }
      else
        throw statement_not_supported_exception("Unsupported assignment to row-major matrix");
    }
Example #10
0
    /** @brief Deals with x = RHS where RHS is a vector expression */
    inline void execute_matrix_row_assign_composite(statement const & s)
    {
      statement::container_type const & expr = s.array();

      if (expr[1].op_type_  == OPERATION_BINARY_ADD_TYPE)
      {
        if (expr[0].lhs_type_ == MATRIX_ROW_FLOAT_TYPE
            && expr[1].lhs_type_ == MATRIX_ROW_FLOAT_TYPE
            && expr[1].rhs_type_ == MATRIX_ROW_FLOAT_TYPE)
        {
          viennacl::matrix_base<float, viennacl::row_major>       & A = *(expr[0].lhs_.matrix_row_float_);
          viennacl::matrix_base<float, viennacl::row_major> const & B = *(expr[1].lhs_.matrix_row_float_);
          viennacl::matrix_base<float, viennacl::row_major> const & C = *(expr[1].rhs_.matrix_row_float_);
          viennacl::linalg::ambm(A,
                                 B, 1.0, 1, false, false,
                                 C, 1.0, 1, false, false);
        }
        else if (expr[0].lhs_type_ == MATRIX_ROW_DOUBLE_TYPE
                 && expr[1].lhs_type_ == MATRIX_ROW_DOUBLE_TYPE
                 && expr[1].rhs_type_ == MATRIX_ROW_DOUBLE_TYPE)
        {
          viennacl::matrix_base<double, viennacl::row_major>       & A = *(expr[0].lhs_.matrix_row_double_);
          viennacl::matrix_base<double, viennacl::row_major> const & B = *(expr[1].lhs_.matrix_row_double_);
          viennacl::matrix_base<double, viennacl::row_major> const & C = *(expr[1].rhs_.matrix_row_double_);
          viennacl::linalg::ambm(A,
                                 B, 1.0, 1, false, false,
                                 C, 1.0, 1, false, false);
        }
        else
          throw statement_not_supported_exception("Cannot deal with addition of row-major matrix");
      }
      else if (expr[1].op_type_  == OPERATION_BINARY_SUB_TYPE)
      {
        if (expr[0].lhs_type_ == MATRIX_ROW_FLOAT_TYPE
            && expr[1].lhs_type_ == MATRIX_ROW_FLOAT_TYPE
            && expr[1].rhs_type_ == MATRIX_ROW_FLOAT_TYPE)
        {
          viennacl::matrix_base<float, viennacl::row_major>       & A = *(expr[0].lhs_.matrix_row_float_);
          viennacl::matrix_base<float, viennacl::row_major> const & B = *(expr[1].lhs_.matrix_row_float_);
          viennacl::matrix_base<float, viennacl::row_major> const & C = *(expr[1].rhs_.matrix_row_float_);
          viennacl::linalg::ambm(A,
                                 B,  1.0, 1, false, false,
                                 C, -1.0, 1, false, false);
        }
        else if (expr[0].lhs_type_ == MATRIX_ROW_DOUBLE_TYPE
                 && expr[1].lhs_type_ == MATRIX_ROW_DOUBLE_TYPE
                 && expr[1].rhs_type_ == MATRIX_ROW_DOUBLE_TYPE)
        {
          viennacl::matrix_base<double, viennacl::row_major>       & A = *(expr[0].lhs_.matrix_row_double_);
          viennacl::matrix_base<double, viennacl::row_major> const & B = *(expr[1].lhs_.matrix_row_double_);
          viennacl::matrix_base<double, viennacl::row_major> const & C = *(expr[1].rhs_.matrix_row_double_);
          viennacl::linalg::ambm(A,
                                 B,  1.0, 1, false, false,
                                 C, -1.0, 1, false, false);
        }
        else
          throw statement_not_supported_exception("Cannot deal with subtraction of row-major matrix");
      }
      else
        throw statement_not_supported_exception("Unsupported binary operator for row-major matrix operations");
    }
    /** @brief Deals with x = RHS where RHS is a vector expression */
    void execute_vector_assign_composite(statement const & s)
    {
      typename statement::container_type const & expr = s.array();

      if (expr[1].op_type_  == OPERATION_BINARY_ADD_TYPE)
      {
        if (expr[0].lhs_type_ == VECTOR_FLOAT_TYPE
            && expr[1].lhs_type_ == VECTOR_FLOAT_TYPE
            && expr[1].rhs_type_ == VECTOR_FLOAT_TYPE)
        {
          viennacl::vector_base<float>       & x = *(expr[0].lhs_.vector_float_);
          viennacl::vector_base<float> const & y = *(expr[1].lhs_.vector_float_);
          viennacl::vector_base<float> const & z = *(expr[1].rhs_.vector_float_);
          viennacl::linalg::avbv(x,
                                 y, 1.0, 1, false, false,
                                 z, 1.0, 1, false, false);
        }
        else if (expr[0].lhs_type_ == VECTOR_DOUBLE_TYPE
                 && expr[1].lhs_type_ == VECTOR_DOUBLE_TYPE
                 && expr[1].rhs_type_ == VECTOR_DOUBLE_TYPE)
        {
          viennacl::vector_base<double>       & x = *(expr[0].lhs_.vector_double_);
          viennacl::vector_base<double> const & y = *(expr[1].lhs_.vector_double_);
          viennacl::vector_base<double> const & z = *(expr[1].rhs_.vector_double_);
          viennacl::linalg::avbv(x,
                                 y, 1.0, 1, false, false,
                                 z, 1.0, 1, false, false);
        }
        else
          throw "TODO";
      }
      else if (expr[1].op_type_  == OPERATION_BINARY_SUB_TYPE)
      {
        if (expr[0].lhs_type_ == VECTOR_FLOAT_TYPE
            && expr[1].lhs_type_ == VECTOR_FLOAT_TYPE
            && expr[1].rhs_type_ == VECTOR_FLOAT_TYPE)
        {
          viennacl::vector_base<float>       & x = *(expr[0].lhs_.vector_float_);
          viennacl::vector_base<float> const & y = *(expr[1].lhs_.vector_float_);
          viennacl::vector_base<float> const & z = *(expr[1].rhs_.vector_float_);
          viennacl::linalg::avbv(x,
                                 y,  1.0, 1, false, false,
                                 z, -1.0, 1, false, false);
        }
        else if (expr[0].lhs_type_ == VECTOR_DOUBLE_TYPE
                 && expr[1].lhs_type_ == VECTOR_DOUBLE_TYPE
                 && expr[1].rhs_type_ == VECTOR_DOUBLE_TYPE)
        {
          viennacl::vector_base<double>       & x = *(expr[0].lhs_.vector_double_);
          viennacl::vector_base<double> const & y = *(expr[1].lhs_.vector_double_);
          viennacl::vector_base<double> const & z = *(expr[1].rhs_.vector_double_);
          viennacl::linalg::avbv(x,
                                 y,  1.0, 1, false, false,
                                 z, -1.0, 1, false, false);
        }
        else
          throw "TODO";
      }
      else
        throw "TODO";
    }
Example #12
0
    /** @brief Deals with x = RHS where RHS is a vector expression */
    inline void execute_scalar_assign_composite(statement const & s)
    {
      statement::container_type const & expr = s.array();

      if (expr[1].op_type_  == OPERATION_BINARY_INNER_PROD_TYPE)
      {
        if (expr[0].lhs_type_ == SCALAR_FLOAT_TYPE
            && expr[1].lhs_type_ == VECTOR_FLOAT_TYPE
            && expr[1].rhs_type_ == VECTOR_FLOAT_TYPE)
        {
          viennacl::scalar<float>            & s = *(expr[0].lhs_.scalar_float_);
          viennacl::vector_base<float> const & y = *(expr[1].lhs_.vector_float_);
          viennacl::vector_base<float> const & z = *(expr[1].rhs_.vector_float_);
          viennacl::linalg::inner_prod_impl(y, z, s);
        }
        else if (expr[0].lhs_type_ == SCALAR_DOUBLE_TYPE
                 && expr[1].lhs_type_ == VECTOR_DOUBLE_TYPE
                 && expr[1].rhs_type_ == VECTOR_DOUBLE_TYPE)
        {
          viennacl::scalar<double>            & s = *(expr[0].lhs_.scalar_double_);
          viennacl::vector_base<double> const & y = *(expr[1].lhs_.vector_double_);
          viennacl::vector_base<double> const & z = *(expr[1].rhs_.vector_double_);
          viennacl::linalg::inner_prod_impl(y, z, s);
        }
        else
          throw statement_not_supported_exception("Cannot deal with inner product of the provided arguments");
      }
      else if (expr[1].op_type_  == OPERATION_UNARY_NORM_1_TYPE)
      {
        if (expr[0].lhs_type_ == SCALAR_FLOAT_TYPE
            && expr[1].lhs_type_ == VECTOR_FLOAT_TYPE)
        {
          viennacl::scalar<float>            & s = *(expr[0].lhs_.scalar_float_);
          viennacl::vector_base<float> const & x = *(expr[1].lhs_.vector_float_);
          viennacl::linalg::norm_1_impl(x, s);
        }
        else if (expr[0].lhs_type_ == SCALAR_DOUBLE_TYPE
                 && expr[1].lhs_type_ == VECTOR_DOUBLE_TYPE
                 && expr[1].rhs_type_ == VECTOR_DOUBLE_TYPE)
        {
          viennacl::scalar<double>            & s = *(expr[0].lhs_.scalar_double_);
          viennacl::vector_base<double> const & x = *(expr[1].lhs_.vector_double_);
          viennacl::linalg::norm_1_impl(x, s);
        }
        else
          throw statement_not_supported_exception("Cannot deal with norm_1 of the provided arguments");
      }
      else if (expr[1].op_type_  == OPERATION_UNARY_NORM_2_TYPE)
      {
        if (expr[0].lhs_type_ == SCALAR_FLOAT_TYPE
            && expr[1].lhs_type_ == VECTOR_FLOAT_TYPE)
        {
          viennacl::scalar<float>            & s = *(expr[0].lhs_.scalar_float_);
          viennacl::vector_base<float> const & x = *(expr[1].lhs_.vector_float_);
          viennacl::linalg::norm_2_impl(x, s);
        }
        else if (expr[0].lhs_type_ == SCALAR_DOUBLE_TYPE
                 && expr[1].lhs_type_ == VECTOR_DOUBLE_TYPE
                 && expr[1].rhs_type_ == VECTOR_DOUBLE_TYPE)
        {
          viennacl::scalar<double>            & s = *(expr[0].lhs_.scalar_double_);
          viennacl::vector_base<double> const & x = *(expr[1].lhs_.vector_double_);
          viennacl::linalg::norm_2_impl(x, s);
        }
        else
          throw statement_not_supported_exception("Cannot deal with norm_2 of the provided arguments");
      }
      else if (expr[1].op_type_  == OPERATION_UNARY_NORM_INF_TYPE)
      {
        if (expr[0].lhs_type_ == SCALAR_FLOAT_TYPE
            && expr[1].lhs_type_ == VECTOR_FLOAT_TYPE)
        {
          viennacl::scalar<float>            & s = *(expr[0].lhs_.scalar_float_);
          viennacl::vector_base<float> const & x = *(expr[1].lhs_.vector_float_);
          viennacl::linalg::norm_inf_impl(x, s);
        }
        else if (expr[0].lhs_type_ == SCALAR_DOUBLE_TYPE
                 && expr[1].lhs_type_ == VECTOR_DOUBLE_TYPE
                 && expr[1].rhs_type_ == VECTOR_DOUBLE_TYPE)
        {
          viennacl::scalar<double>            & s = *(expr[0].lhs_.scalar_double_);
          viennacl::vector_base<double> const & x = *(expr[1].lhs_.vector_double_);
          viennacl::linalg::norm_inf_impl(x, s);
        }
        else
          throw statement_not_supported_exception("Cannot deal with norm_inf of the provided arguments");
      }
      else
        throw statement_not_supported_exception("Unsupported operation for scalar.");
    }