Loading graph_c_binding/graph_c_binding.cpp +92 −0 Original line number Diff line number Diff line Loading @@ -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 //****************************************************************************** Loading graph_c_binding/graph_c_binding.h +16 −0 Original line number Diff line number Diff line Loading @@ -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. /// Loading graph_fortran_binding/graph_fortran_binding.f90 +59 −9 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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. Loading Loading @@ -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. !> Loading Loading @@ -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) Loading Loading @@ -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) Loading Loading @@ -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) Loading Loading @@ -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) Loading Loading @@ -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, & Loading Loading @@ -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, & Loading Loading @@ -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, & Loading Loading @@ -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, & Loading Loading @@ -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 !******************************************************************************* Loading graph_tests/c_binding_test.c +22 −8 Original line number Diff line number Diff line Loading @@ -124,6 +124,7 @@ void run_tests(const enum graph_type type, graph_node p2; graph_node i = graph_variable(c_context, 1, "i"); graph_node j = graph_variable(c_context, 1, "j"); graph_node variable = graph_variable(c_context, 3, "var"); switch (c_context->type) { case FLOAT: { float value1[3] = {2.0, 4.0, 6.0}; Loading @@ -132,6 +133,7 @@ void run_tests(const enum graph_type type, float value4 = 2.5; graph_set_variable(c_context, i, &value3); graph_set_variable(c_context, j, &value4); graph_set_variable(c_context, variable, &value1); p1 = graph_piecewise_1D(c_context, i, 1.0, 0.0, value1, 3); p2 = graph_piecewise_2D(c_context, 3, j, 1.0, 0.0, i, 1.0, 0.0, value2, 9); break; Loading @@ -144,6 +146,7 @@ void run_tests(const enum graph_type type, double value4 = 2.5; graph_set_variable(c_context, i, &value3); graph_set_variable(c_context, j, &value4); graph_set_variable(c_context, variable, &value1); p1 = graph_piecewise_1D(c_context, i, 1.0, 0.0, value1, 3); p2 = graph_piecewise_2D(c_context, 3, j, 1.0, 0.0, i, 1.0, 0.0, value2, 9); break; Loading @@ -158,6 +161,7 @@ void run_tests(const enum graph_type type, float complex value4 = CMPLXF(2.5, 0.0); graph_set_variable(c_context, i, &value3); graph_set_variable(c_context, j, &value4); graph_set_variable(c_context, variable, &value1); p1 = graph_piecewise_1D(c_context, i, 1.0, 0.0, value1, 3); p2 = graph_piecewise_2D(c_context, 3, j, 1.0, 0.0, i, 1.0, 0.0, value2, 9); break; Loading @@ -172,14 +176,16 @@ void run_tests(const enum graph_type type, double complex value4 = CMPLXF(2.5, 0.0); graph_set_variable(c_context, i, &value3); graph_set_variable(c_context, j, &value4); graph_set_variable(c_context, variable, &value1); p1 = graph_piecewise_1D(c_context, i, 1.0, 0.0, value1, 3); p2 = graph_piecewise_2D(c_context, 3, j, 1.0, 0.0, i, 1.0, 0.0, value2, 9); break; } } graph_node i1 = graph_index_1D(c_context, variable, i, 1.0, 0.0); graph_node inputs2[2] = {i, j}; graph_node outputs2[2] = {p1, p2}; graph_node inputs2[3] = {i, j, variable}; graph_node outputs2[3] = {p1, p2, i1}; graph_node *map_inputs2 = NULL; graph_node *map_outputs2 = NULL; Loading @@ -195,8 +201,8 @@ void run_tests(const enum graph_type type, map_inputs, map_outputs, 0, NULL, "c_binding", 1); graph_add_item(c_context, inputs2, 2, outputs2, 2, inputs2, 3, outputs2, 3, map_inputs2, map_outputs2, 0, NULL, "c_binding_piecewise", 1); graph_add_converge_item(c_context, &z, 1, Loading Loading @@ -239,7 +245,7 @@ void run_tests(const enum graph_type type, switch (c_context->type) { case FLOAT: { float value[9]; float value[10]; graph_copy_to_host(c_context, y, value); graph_copy_to_host(c_context, dydx, value + 1); graph_copy_to_host(c_context, dydm, value + 2); Loading @@ -249,6 +255,7 @@ void run_tests(const enum graph_type type, graph_copy_to_host(c_context, z, value + 6); graph_copy_to_host(c_context, p1, value + 7); graph_copy_to_host(c_context, p2, value + 8); graph_copy_to_host(c_context, i1, value + 9); assert(value[0] == 0.5f*2.0f + 0.2f && "Value of y does not match."); assert(value[1] == 0.5f && "Value of dydx does not match."); assert(value[2] == 2.0f && "Value of dydm does not match."); Loading @@ -262,11 +269,12 @@ void run_tests(const enum graph_type type, assert(value[6] == 1.0f && "Value of root does not match."); assert(value[7] == 4.0f && "Value of p1 does not match."); assert(value[8] == 8.0f && "Value of p2 does not match."); assert(value[9] == 4.0f && "Value of i1 does not match."); break; } case DOUBLE: { double value[9]; double value[10]; graph_copy_to_host(c_context, y, value); graph_copy_to_host(c_context, dydx, value + 1); graph_copy_to_host(c_context, dydm, value + 2); Loading @@ -276,6 +284,7 @@ void run_tests(const enum graph_type type, graph_copy_to_host(c_context, z, value + 6); graph_copy_to_host(c_context, p1, value + 7); graph_copy_to_host(c_context, p2, value + 8); graph_copy_to_host(c_context, i1, value + 9); assert(value[0] == 0.5*2.0 + 0.2 && "Value of y does not match."); assert(value[1] == 0.5 && "Value of dydx does not match."); assert(value[2] == 2.0 && "Value of dydm does not match."); Loading @@ -289,11 +298,12 @@ void run_tests(const enum graph_type type, assert(value[6] == 1.0 && "Value of root does not match."); assert(value[7] == 4.0 && "Value of p1 does not match."); assert(value[8] == 8.0 && "Value of p2 does not match."); assert(value[9] == 4.0 && "Value of i1 does not match."); break; } case COMPLEX_FLOAT: { float complex value[9]; float complex value[10]; graph_copy_to_host(c_context, y, value); graph_copy_to_host(c_context, dydx, value + 1); graph_copy_to_host(c_context, dydm, value + 2); Loading @@ -303,6 +313,7 @@ void run_tests(const enum graph_type type, graph_copy_to_host(c_context, z, value + 6); graph_copy_to_host(c_context, p1, value + 7); graph_copy_to_host(c_context, p2, value + 8); graph_copy_to_host(c_context, i1, value + 9); assert(crealf(value[0]) == 0.5f*2.0f + 0.2f && "Value of y does not match."); assert(crealf(value[1]) == 0.5f && "Value of dydx does not match."); assert(crealf(value[2]) == 2.0f && "Value of dydm does not match."); Loading @@ -316,11 +327,12 @@ void run_tests(const enum graph_type type, assert(crealf(value[6]) == 1.0f && "Value of root does not match."); assert(crealf(value[7]) == 4.0f && "Value of p1 does not match."); assert(crealf(value[8]) == 8.0f && "Value of p2 does not match."); assert(crealf(value[9]) == 4.0f && "Value of p1 does not match."); break; } case COMPLEX_DOUBLE: { double complex value[9]; double complex value[10]; graph_copy_to_host(c_context, y, value); graph_copy_to_host(c_context, dydx, value + 1); graph_copy_to_host(c_context, dydm, value + 2); Loading @@ -330,6 +342,7 @@ void run_tests(const enum graph_type type, graph_copy_to_host(c_context, z, value + 6); graph_copy_to_host(c_context, p1, value + 7); graph_copy_to_host(c_context, p2, value + 8); graph_copy_to_host(c_context, i1, value + 9); assert(creal(value[0]) == 0.5*2.0 + 0.2 && "Value of y does not match."); assert(creal(value[1]) == 0.5 && "Value of dydx does not match."); assert(creal(value[2]) == 2.0 && "Value of dydm does not match."); Loading @@ -343,6 +356,7 @@ void run_tests(const enum graph_type type, assert(creal(value[6]) == 1.0 && "Value of root does not match."); assert(creal(value[7]) == 4.0 && "Value of p1 does not match."); assert(creal(value[8]) == 8.0 && "Value of p2 does not match."); assert(creal(value[9]) == 4.0 && "Value of p1 does not match."); break; } } Loading graph_tests/f_binding_test.f90 +47 −8 File changed.Preview size limit exceeded, changes collapsed. Show changes Loading
graph_c_binding/graph_c_binding.cpp +92 −0 Original line number Diff line number Diff line Loading @@ -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 //****************************************************************************** Loading
graph_c_binding/graph_c_binding.h +16 −0 Original line number Diff line number Diff line Loading @@ -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. /// Loading
graph_fortran_binding/graph_fortran_binding.f90 +59 −9 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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. Loading Loading @@ -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. !> Loading Loading @@ -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) Loading Loading @@ -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) Loading Loading @@ -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) Loading Loading @@ -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) Loading Loading @@ -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, & Loading Loading @@ -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, & Loading Loading @@ -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, & Loading Loading @@ -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, & Loading Loading @@ -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 !******************************************************************************* Loading
graph_tests/c_binding_test.c +22 −8 Original line number Diff line number Diff line Loading @@ -124,6 +124,7 @@ void run_tests(const enum graph_type type, graph_node p2; graph_node i = graph_variable(c_context, 1, "i"); graph_node j = graph_variable(c_context, 1, "j"); graph_node variable = graph_variable(c_context, 3, "var"); switch (c_context->type) { case FLOAT: { float value1[3] = {2.0, 4.0, 6.0}; Loading @@ -132,6 +133,7 @@ void run_tests(const enum graph_type type, float value4 = 2.5; graph_set_variable(c_context, i, &value3); graph_set_variable(c_context, j, &value4); graph_set_variable(c_context, variable, &value1); p1 = graph_piecewise_1D(c_context, i, 1.0, 0.0, value1, 3); p2 = graph_piecewise_2D(c_context, 3, j, 1.0, 0.0, i, 1.0, 0.0, value2, 9); break; Loading @@ -144,6 +146,7 @@ void run_tests(const enum graph_type type, double value4 = 2.5; graph_set_variable(c_context, i, &value3); graph_set_variable(c_context, j, &value4); graph_set_variable(c_context, variable, &value1); p1 = graph_piecewise_1D(c_context, i, 1.0, 0.0, value1, 3); p2 = graph_piecewise_2D(c_context, 3, j, 1.0, 0.0, i, 1.0, 0.0, value2, 9); break; Loading @@ -158,6 +161,7 @@ void run_tests(const enum graph_type type, float complex value4 = CMPLXF(2.5, 0.0); graph_set_variable(c_context, i, &value3); graph_set_variable(c_context, j, &value4); graph_set_variable(c_context, variable, &value1); p1 = graph_piecewise_1D(c_context, i, 1.0, 0.0, value1, 3); p2 = graph_piecewise_2D(c_context, 3, j, 1.0, 0.0, i, 1.0, 0.0, value2, 9); break; Loading @@ -172,14 +176,16 @@ void run_tests(const enum graph_type type, double complex value4 = CMPLXF(2.5, 0.0); graph_set_variable(c_context, i, &value3); graph_set_variable(c_context, j, &value4); graph_set_variable(c_context, variable, &value1); p1 = graph_piecewise_1D(c_context, i, 1.0, 0.0, value1, 3); p2 = graph_piecewise_2D(c_context, 3, j, 1.0, 0.0, i, 1.0, 0.0, value2, 9); break; } } graph_node i1 = graph_index_1D(c_context, variable, i, 1.0, 0.0); graph_node inputs2[2] = {i, j}; graph_node outputs2[2] = {p1, p2}; graph_node inputs2[3] = {i, j, variable}; graph_node outputs2[3] = {p1, p2, i1}; graph_node *map_inputs2 = NULL; graph_node *map_outputs2 = NULL; Loading @@ -195,8 +201,8 @@ void run_tests(const enum graph_type type, map_inputs, map_outputs, 0, NULL, "c_binding", 1); graph_add_item(c_context, inputs2, 2, outputs2, 2, inputs2, 3, outputs2, 3, map_inputs2, map_outputs2, 0, NULL, "c_binding_piecewise", 1); graph_add_converge_item(c_context, &z, 1, Loading Loading @@ -239,7 +245,7 @@ void run_tests(const enum graph_type type, switch (c_context->type) { case FLOAT: { float value[9]; float value[10]; graph_copy_to_host(c_context, y, value); graph_copy_to_host(c_context, dydx, value + 1); graph_copy_to_host(c_context, dydm, value + 2); Loading @@ -249,6 +255,7 @@ void run_tests(const enum graph_type type, graph_copy_to_host(c_context, z, value + 6); graph_copy_to_host(c_context, p1, value + 7); graph_copy_to_host(c_context, p2, value + 8); graph_copy_to_host(c_context, i1, value + 9); assert(value[0] == 0.5f*2.0f + 0.2f && "Value of y does not match."); assert(value[1] == 0.5f && "Value of dydx does not match."); assert(value[2] == 2.0f && "Value of dydm does not match."); Loading @@ -262,11 +269,12 @@ void run_tests(const enum graph_type type, assert(value[6] == 1.0f && "Value of root does not match."); assert(value[7] == 4.0f && "Value of p1 does not match."); assert(value[8] == 8.0f && "Value of p2 does not match."); assert(value[9] == 4.0f && "Value of i1 does not match."); break; } case DOUBLE: { double value[9]; double value[10]; graph_copy_to_host(c_context, y, value); graph_copy_to_host(c_context, dydx, value + 1); graph_copy_to_host(c_context, dydm, value + 2); Loading @@ -276,6 +284,7 @@ void run_tests(const enum graph_type type, graph_copy_to_host(c_context, z, value + 6); graph_copy_to_host(c_context, p1, value + 7); graph_copy_to_host(c_context, p2, value + 8); graph_copy_to_host(c_context, i1, value + 9); assert(value[0] == 0.5*2.0 + 0.2 && "Value of y does not match."); assert(value[1] == 0.5 && "Value of dydx does not match."); assert(value[2] == 2.0 && "Value of dydm does not match."); Loading @@ -289,11 +298,12 @@ void run_tests(const enum graph_type type, assert(value[6] == 1.0 && "Value of root does not match."); assert(value[7] == 4.0 && "Value of p1 does not match."); assert(value[8] == 8.0 && "Value of p2 does not match."); assert(value[9] == 4.0 && "Value of i1 does not match."); break; } case COMPLEX_FLOAT: { float complex value[9]; float complex value[10]; graph_copy_to_host(c_context, y, value); graph_copy_to_host(c_context, dydx, value + 1); graph_copy_to_host(c_context, dydm, value + 2); Loading @@ -303,6 +313,7 @@ void run_tests(const enum graph_type type, graph_copy_to_host(c_context, z, value + 6); graph_copy_to_host(c_context, p1, value + 7); graph_copy_to_host(c_context, p2, value + 8); graph_copy_to_host(c_context, i1, value + 9); assert(crealf(value[0]) == 0.5f*2.0f + 0.2f && "Value of y does not match."); assert(crealf(value[1]) == 0.5f && "Value of dydx does not match."); assert(crealf(value[2]) == 2.0f && "Value of dydm does not match."); Loading @@ -316,11 +327,12 @@ void run_tests(const enum graph_type type, assert(crealf(value[6]) == 1.0f && "Value of root does not match."); assert(crealf(value[7]) == 4.0f && "Value of p1 does not match."); assert(crealf(value[8]) == 8.0f && "Value of p2 does not match."); assert(crealf(value[9]) == 4.0f && "Value of p1 does not match."); break; } case COMPLEX_DOUBLE: { double complex value[9]; double complex value[10]; graph_copy_to_host(c_context, y, value); graph_copy_to_host(c_context, dydx, value + 1); graph_copy_to_host(c_context, dydm, value + 2); Loading @@ -330,6 +342,7 @@ void run_tests(const enum graph_type type, graph_copy_to_host(c_context, z, value + 6); graph_copy_to_host(c_context, p1, value + 7); graph_copy_to_host(c_context, p2, value + 8); graph_copy_to_host(c_context, i1, value + 9); assert(creal(value[0]) == 0.5*2.0 + 0.2 && "Value of y does not match."); assert(creal(value[1]) == 0.5 && "Value of dydx does not match."); assert(creal(value[2]) == 2.0 && "Value of dydm does not match."); Loading @@ -343,6 +356,7 @@ void run_tests(const enum graph_type type, assert(creal(value[6]) == 1.0 && "Value of root does not match."); assert(creal(value[7]) == 4.0 && "Value of p1 does not match."); assert(creal(value[8]) == 8.0 && "Value of p2 does not match."); assert(creal(value[9]) == 4.0 && "Value of p1 does not match."); break; } } Loading
graph_tests/f_binding_test.f90 +47 −8 File changed.Preview size limit exceeded, changes collapsed. Show changes