Commit 33214579 authored by Cianciosa, Mark's avatar Cianciosa, Mark
Browse files

Merge branch 'index' into 'main'

Add an index node. This can be used a potential code to index into a variable....

See merge request !92
parents c138bdba 4bcadc98
Loading
Loading
Loading
Loading
+92 −0
Original line number Diff line number Diff line
@@ -1676,6 +1676,98 @@ extern "C" {
        }
    }

//------------------------------------------------------------------------------
///  @brief Create a 1D index.
///
///  @param[in] c           The graph C context.
///  @param[in] variable    The variable to index.
///  @param[in] x_arg       The function x argument.
///  @param[in] x_scale     Scale factor x argument.
///  @param[in] x_offset    Offset factor x argument.
///  @returns A 1D index node.
//------------------------------------------------------------------------------
    graph_node graph_index_1D(STRUCT_TAG graph_c_context *c,
                              graph_node variable,
                              graph_node x_arg,
                              const double x_scale,
                              const double x_offset) {
        switch (c->type) {
            case FLOAT:
                if (c->safe_math) {
                    auto d = reinterpret_cast<graph_c_context_type<float, true> *> (c);
                    auto temp = graph::index_1D(d->nodes[variable],
                                                d->nodes[x_arg],
                                                static_cast<float> (x_scale),
                                                static_cast<float> (x_offset));
                    d->nodes[temp.get()] = temp;
                    return temp.get();
                } else {
                    auto d = reinterpret_cast<graph_c_context_type<float> *> (c);
                    auto temp = graph::index_1D(d->nodes[variable],
                                                d->nodes[x_arg],
                                                static_cast<float> (x_scale),
                                                static_cast<float> (x_offset));
                    d->nodes[temp.get()] = temp;
                    return temp.get();
                }
            
            case DOUBLE:
                if (c->safe_math) {
                    auto d = reinterpret_cast<graph_c_context_type<double, true> *> (c);
                    auto temp = graph::index_1D(d->nodes[variable],
                                                d->nodes[x_arg],
                                                x_scale, x_offset);
                    d->nodes[temp.get()] = temp;
                    return temp.get();
                } else {
                    auto d = reinterpret_cast<graph_c_context_type<double> *> (c);
                    auto temp = graph::index_1D(d->nodes[variable],
                                                d->nodes[x_arg],
                                                x_scale, x_offset);
                    d->nodes[temp.get()] = temp;
                    return temp.get();
                }

            case COMPLEX_FLOAT:
                if (c->safe_math) {
                    auto d = reinterpret_cast<graph_c_context_type<std::complex<float>, true> *> (c);
                    auto temp = graph::index_1D(d->nodes[variable],
                                                d->nodes[x_arg],
                                                std::complex<float> (x_scale),
                                                std::complex<float> (x_offset));
                    d->nodes[temp.get()] = temp;
                    return temp.get();
                } else {
                    auto d = reinterpret_cast<graph_c_context_type<std::complex<float>> *> (c);
                    auto temp = graph::index_1D(d->nodes[variable],
                                                d->nodes[x_arg],
                                                std::complex<float> (x_scale),
                                                std::complex<float> (x_offset));
                    d->nodes[temp.get()] = temp;
                    return temp.get();
                }
            
            case COMPLEX_DOUBLE:
                if (c->safe_math) {
                    auto d = reinterpret_cast<graph_c_context_type<std::complex<double>, true> *> (c);
                    auto temp = graph::index_1D(d->nodes[variable],
                                                d->nodes[x_arg],
                                                std::complex<double> (x_scale),
                                                std::complex<double> (x_offset));
                    d->nodes[temp.get()] = temp;
                    return temp.get();
                } else {
                    auto d = reinterpret_cast<graph_c_context_type<std::complex<double>> *> (c);
                    auto temp = graph::index_1D(d->nodes[variable],
                                                d->nodes[x_arg],
                                                std::complex<double> (x_scale),
                                                std::complex<double> (x_offset));
                    d->nodes[temp.get()] = temp;
                    return temp.get();
                }
        }
    }

//******************************************************************************
//  JIT
//******************************************************************************
+16 −0
Original line number Diff line number Diff line
@@ -445,6 +445,22 @@ extern "C" {
                                  const void *source,
                                  const size_t source_size);

//------------------------------------------------------------------------------
///  @brief Create a 1D index.
///
///  @param[in] c           The graph C context.
///  @param[in] variable    The variable to index.
///  @param[in] x_arg       The function x argument.
///  @param[in] x_scale     Scale factor x argument.
///  @param[in] x_offset    Offset factor x argument.
///  @returns A 1D index node.
//------------------------------------------------------------------------------
    graph_node graph_index_1D(STRUCT_TAG graph_c_context *c,
                              graph_node variable,
                              graph_node x_arg,
                              const double x_scale,
                              const double x_offset);

//------------------------------------------------------------------------------
///  @brief Create 2D piecewise node with complex arguments.
///
+59 −9
Original line number Diff line number Diff line
@@ -145,6 +145,7 @@
                                      piecewise_2D_double,                     &
                                      piecewise_2D_cfloat,                     &
                                      piecewise_2D_cdouble
         PROCEDURE :: index_1D => graph_context_index_1D
         PROCEDURE :: get_max_concurrency => graph_context_get_max_concurrency
         PROCEDURE :: set_device_number => graph_context_set_device_number
         PROCEDURE :: add_pre_item => graph_context_add_pre_item
@@ -593,7 +594,7 @@
         END FUNCTION

!-------------------------------------------------------------------------------
!>  @brief Create 1D piecewise node with complex double buffer.
!>  @brief Create 1D piecewise node.
!>
!>  @param[in] c           The graph C context.
!>  @param[in] arg         The left operand.
@@ -650,6 +651,27 @@
         INTEGER(C_LONG), VALUE     :: source_size
         END FUNCTION

!-------------------------------------------------------------------------------
!>  @brief Create 1D index node.
!>
!>  @param[in] c        The graph C context.
!>  @param[in] variable The variable to index.
!>  @param[in] arg      The left operand.
!>  @param[in] scale    Scale factor argument.
!>  @param[in] offset   Offset factor argument.
!>  @returns A 1D piecewise node.
!-------------------------------------------------------------------------------
         TYPE(C_PTR) FUNCTION graph_index_1D(c, variable, arg, scale, offset)  &
         BIND(C, NAME='graph_index_1D')
         USE, INTRINSIC :: ISO_C_BINDING
         IMPLICIT NONE
         TYPE(C_PTR), VALUE         :: c
         TYPE(C_PTR), VALUE         :: variable
         TYPE(C_PTR), VALUE         :: arg
         REAL(C_DOUBLE), VALUE      :: scale
         REAL(C_DOUBLE), VALUE      :: offset
         END FUNCTION

!-------------------------------------------------------------------------------
!>  @brief Get the maximum number of concurrent devices.
!>
@@ -1583,7 +1605,7 @@
!>  @param[in]     scale  Scale factor argument.
!>  @param[in]     offset Offset factor argument.
!>  @param[in]     source Source buffer to fill elements.
!>  @returns random(state)
!>  @returns piecewise_1D node.
!-------------------------------------------------------------------------------
      FUNCTION graph_context_piecewise_1D_float(this, arg, scale, offset,      &
                                                source)
@@ -1613,7 +1635,7 @@
!>  @param[in]     scale  Scale factor argument.
!>  @param[in]     offset Offset factor argument.
!>  @param[in]     source Source buffer to fill elements.
!>  @returns random(state)
!>  @returns piecewise_1D node.
!-------------------------------------------------------------------------------
      FUNCTION graph_context_piecewise_1D_double(this, arg, scale, offset,     &
                                                 source)
@@ -1643,7 +1665,7 @@
!>  @param[in]     scale  Scale factor argument.
!>  @param[in]     offset Offset factor argument.
!>  @param[in]     source Source buffer to fill elements.
!>  @returns random(state)
!>  @returns piecewise_1D node.
!-------------------------------------------------------------------------------
      FUNCTION graph_context_piecewise_1D_cfloat(this, arg, scale, offset,     &
                                                 source)
@@ -1673,7 +1695,7 @@
!>  @param[in]     scale  Scale factor argument.
!>  @param[in]     offset Offset factor argument.
!>  @param[in]     source Source buffer to fill elements.
!>  @returns random(state)
!>  @returns piecewise_1D node.
!-------------------------------------------------------------------------------
      FUNCTION graph_context_piecewise_1D_cdouble(this, arg, scale, offset,    &
                                                  source)
@@ -1706,7 +1728,7 @@
!>  @param[in]     y_scale  Scale factor for y argument.
!>  @param[in]     y_offset Offset factor for y argument.
!>  @param[in]     source   Source buffer to fill elements.
!>  @returns random(state)
!>  @returns piecewise_2D node.
!-------------------------------------------------------------------------------
      FUNCTION graph_context_piecewise_2D_float(this,                          &
                                                x_arg, x_scale, x_offset,      &
@@ -1747,7 +1769,7 @@
!>  @param[in]     y_scale  Scale factor for y argument.
!>  @param[in]     y_offset Offset factor for y argument.
!>  @param[in]     source   Source buffer to fill elements.
!>  @returns random(state)
!>  @returns piecewise_2D node.
!-------------------------------------------------------------------------------
      FUNCTION graph_context_piecewise_2D_double(this,                         &
                                                 x_arg, x_scale, x_offset,     &
@@ -1788,7 +1810,7 @@
!>  @param[in]     y_scale  Scale factor for y argument.
!>  @param[in]     y_offset Offset factor for y argument.
!>  @param[in]     source   Source buffer to fill elements.
!>  @returns random(state)
!>  @returns piecewise_2D node.
!-------------------------------------------------------------------------------
      FUNCTION graph_context_piecewise_2D_cfloat(this,                         &
                                                 x_arg, x_scale, x_offset,     &
@@ -1829,7 +1851,7 @@
!>  @param[in]     y_scale  Scale factor for y argument.
!>  @param[in]     y_offset Offset factor for y argument.
!>  @param[in]     source   Source buffer to fill elements.
!>  @returns random(state)
!>  @returns piecewise_2D node.
!-------------------------------------------------------------------------------
      FUNCTION graph_context_piecewise_2D_cdouble(this,                        &
                                                  x_arg, x_scale, x_offset,    &
@@ -1859,6 +1881,34 @@

      END FUNCTION

!-------------------------------------------------------------------------------
!>  @brief Create 1D index node with float buffer.
!>
!>  @param[in,out] this     @ref graph_context instance.
!>  @param[in]     variable The variable
!>  @param[in]     arg      The function argument.
!>  @param[in]     scale    Scale factor argument.
!>  @param[in]     offset   Offset factor argument.
!>  @returns index_1D node.
!-------------------------------------------------------------------------------
      FUNCTION graph_context_index_1D(this, variable, arg, scale, offset)

      IMPLICIT NONE

!  Declare Arguments
      TYPE(C_PTR)                         :: graph_context_index_1D
      CLASS(graph_context), INTENT(INOUT) :: this
      TYPE(C_PTR), INTENT(IN)             :: variable
      TYPE(C_PTR), INTENT(IN)             :: arg
      REAL(C_DOUBLE)                      :: scale
      REAL(C_DOUBLE)                      :: offset

!  Start of executable.
      graph_context_index_1D =                                                 &
         graph_index_1D(this%c_context, variable, arg, scale, offset)

      END FUNCTION

!*******************************************************************************
!  JIT
!*******************************************************************************
+32 −0
Original line number Diff line number Diff line
@@ -292,6 +292,38 @@ namespace backend {
            return true;
        }

//------------------------------------------------------------------------------
///  @brief Index row.
///
///  @param[in] index       The row index.
///  @param[in] num_columns The number of coils.
///  @returns A buffer containing the row.
//------------------------------------------------------------------------------
        buffer<T> index_row(const size_t index, const size_t num_columns) {
            buffer<T> b(num_columns);
            const size_t num_rows = size()/num_columns;
            for (size_t j = 0; j < num_columns; j++) {
                b[j] = memory[index*num_rows + j];
            }
            return b;
        }

//------------------------------------------------------------------------------
///  @brief Index column.
///
///  @param[in] index       The row index.
///  @param[in] num_columns The number of coils.
///  @returns A buffer containing the row.
//------------------------------------------------------------------------------
        buffer<T> index_column(const size_t index, const size_t num_columns) {
            const size_t num_rows = size()/num_columns;
            buffer<T> b(num_rows);
            for (size_t i = 0; i < num_rows; i++) {
                b[i] = memory[i*num_rows + index];
            }
            return b;
        }

//------------------------------------------------------------------------------
///  @brief Add row operation.
///
+354 −3

File changed.

Preview size limit exceeded, changes collapsed.

Loading