Commit 7148ec4c authored by cianciosa's avatar cianciosa
Browse files

Expand fortran bindings. Refactor random bindings so state size no longer...

Expand fortran bindings. Refactor random bindings so state size no longer needs to be called explicitly.
parent c94b5a57
Loading
Loading
Loading
Loading
+23 −57
Original line number Diff line number Diff line
@@ -1255,65 +1255,27 @@ extern "C" {
//******************************************************************************
//  Random
//******************************************************************************
//------------------------------------------------------------------------------
///  @brief Get random size.
///
///  @param[in] c The graph C context.
///  @return The random size.
//------------------------------------------------------------------------------
    size_t graph_random_size(STRUCT_TAG graph_c_context *c) {
        switch (c->type) {
            case FLOAT:
                if (c->safe_math) {
                    return jit::context<float, true>::random_state_size;
                } else {
                    return jit::context<float>::random_state_size;
                }

            case DOUBLE:
                if (c->safe_math) {
                    return jit::context<double, true>::random_state_size;
                } else {
                    return jit::context<double>::random_state_size;
                }

            case COMPLEX_FLOAT:
                if (c->safe_math) {
                    return jit::context<std::complex<float>, true>::random_state_size;
                } else {
                    return jit::context<std::complex<float>>::random_state_size;
                }

            case COMPLEX_DOUBLE:
                if (c->safe_math) {
                    return jit::context<std::complex<double>, true>::random_state_size;
                } else {
                    return jit::context<std::complex<double>>::random_state_size;
                }
        }
    }

//------------------------------------------------------------------------------
///  @brief Construct a random state node.
///
///  @param[in] c    The graph C context.
///  @param[in] size Number of random states.
///  @param[in] seed Intial random seed.
///  @returns A random state node.
//------------------------------------------------------------------------------
    graph_node graph_random_state(STRUCT_TAG graph_c_context *c,
                                  const size_t size,
                                  const uint32_t seed) {
        switch (c->type) {
            case FLOAT:
                if (c->safe_math) {
                    auto d = reinterpret_cast<graph_c_context_type<float, true> *> (c);
                    auto temp = graph::random_state<float, true> (size, seed);
                    auto temp = graph::random_state<float, true> (jit::context<float, true>::random_state_size,
                                                                  seed);
                    d->nodes[temp.get()] = temp;
                    return temp.get();
                } else {
                    auto d = reinterpret_cast<graph_c_context_type<float> *> (c);
                    auto temp = graph::random_state<float> (size, seed);
                    auto temp = graph::random_state<float> (jit::context<float>::random_state_size,
                                                            seed);
                    d->nodes[temp.get()] = temp;
                    return temp.get();
                }
@@ -1321,12 +1283,14 @@ extern "C" {
            case DOUBLE:
                if (c->safe_math) {
                    auto d = reinterpret_cast<graph_c_context_type<double, true> *> (c);
                    auto temp = graph::random_state<double, true> (size, seed);
                    auto temp = graph::random_state<double, true> (jit::context<double, true>::random_state_size,
                                                                   seed);
                    d->nodes[temp.get()] = temp;
                    return temp.get();
                } else {
                    auto d = reinterpret_cast<graph_c_context_type<double> *> (c);
                    auto temp = graph::random_state<double> (size, seed);
                    auto temp = graph::random_state<double> (jit::context<double>::random_state_size,
                                                             seed);
                    d->nodes[temp.get()] = temp;
                    return temp.get();
                }
@@ -1334,12 +1298,13 @@ extern "C" {
            case COMPLEX_FLOAT:
                if (c->safe_math) {
                    auto d = reinterpret_cast<graph_c_context_type<std::complex<float>, true> *> (c);
                    auto temp = graph::random_state<std::complex<float>, true> (size, seed);
                    auto temp = graph::random_state<std::complex<float>, true> (jit::context<std::complex<float>, true>::random_state_size,
                                                                                seed);
                    d->nodes[temp.get()] = temp;
                    return temp.get();
                } else {
                    auto d = reinterpret_cast<graph_c_context_type<std::complex<float>> *> (c);
                    auto temp = graph::random_state<std::complex<float>> (size, seed);
                    auto temp = graph::random_state<std::complex<float>> (jit::context<std::complex<float>>::random_state_size, seed);
                    d->nodes[temp.get()] = temp;
                    return temp.get();
                }
@@ -1347,12 +1312,13 @@ extern "C" {
            case COMPLEX_DOUBLE:
                if (c->safe_math) {
                    auto d = reinterpret_cast<graph_c_context_type<std::complex<double>, true> *> (c);
                    auto temp = graph::random_state<std::complex<double>, true> (size, seed);
                    auto temp = graph::random_state<std::complex<double>, true> (jit::context<std::complex<double>, true>::random_state_size,
                                                                                 seed);
                    d->nodes[temp.get()] = temp;
                    return temp.get();
                } else {
                    auto d = reinterpret_cast<graph_c_context_type<std::complex<double>> *> (c);
                    auto temp = graph::random_state<std::complex<double>> (size, seed);
                    auto temp = graph::random_state<std::complex<double>> (jit::context<std::complex<double>>::random_state_size, seed);
                    d->nodes[temp.get()] = temp;
                    return temp.get();
                }
@@ -1363,8 +1329,8 @@ extern "C" {
///  @brief Create random node.
///
///  @param[in] c   The graph C context.
///  @param[in] arg The left opperand.
///  @returns random(arg)
///  @param[in] arg A random state node.
///  @returns random(state)
//------------------------------------------------------------------------------
    graph_node graph_random(STRUCT_TAG graph_c_context *c,
                            graph_node arg) {
@@ -1478,7 +1444,7 @@ extern "C" {
///  @brief Create 1D piecewise node.
///
///  @param[in] c           The graph C context.
///  @param[in] arg         The left opperand.
///  @param[in] arg         The function argument.
///  @param[in] scale       Scale factor argument.
///  @param[in] offset      Offset factor argument.
///  @param[in] source      Source buffer to fill elements.
@@ -1579,12 +1545,12 @@ extern "C" {
///
///  @param[in] c           The graph C context.
///  @param[in] num_cols    Number of columns.
///  @param[in] x_arg       The left opperand.
///  @param[in] x_scale     Scale factor argument.
///  @param[in] x_offset    Offset factor argument.
///  @param[in] y_arg       The left opperand.
///  @param[in] y_scale     Scale factor argument.
///  @param[in] y_offset    Offset factor argument.
///  @param[in] x_arg       The function x argument.
///  @param[in] x_scale     Scale factor x argument.
///  @param[in] x_offset    Offset factor x argument.
///  @param[in] y_arg       The function y argument.
///  @param[in] y_scale     Scale factor y argument.
///  @param[in] y_offset    Offset factor y argument.
///  @param[in] source      Source buffer to fill elements.
///  @param[in] source_size Number of elements in the source buffer.
///  @returns A 2D piecewise node.
+20 −30
Original line number Diff line number Diff line
@@ -114,7 +114,7 @@ extern "C" {
///
///  @param[in] c   The graph C context.
///  @param[in] var The variable to set.
///  @returns THe pseudo variable.
///  @returns The pseudo variable.
//------------------------------------------------------------------------------
    graph_node graph_pseudo_variable(STRUCT_TAG graph_c_context *c,
                                     graph_node var);
@@ -123,14 +123,14 @@ extern "C" {
///  @brief Remove pseudo.
///
///  @param[in] c   The graph C context.
///  @param[in] var The variable to set.
///  @param[in] var The graph to remove pseudo variables.
///  @returns The graph with pseudo variables removed.
//------------------------------------------------------------------------------
    graph_node graph_remove_pseudo(STRUCT_TAG graph_c_context *c,
                                   graph_node var);

//------------------------------------------------------------------------------
///  @brief Remove pseudo.
///  @brief Create Addition node.
///
///  @param[in] c     The graph C context.
///  @param[in] left  The left opperand.
@@ -181,7 +181,7 @@ extern "C" {
///  @brief Create Sqrt node.
///
///  @param[in] c   The graph C context.
///  @param[in] arg The left opperand.
///  @param[in] arg The function argument.
///  @returns sqrt(arg)
//------------------------------------------------------------------------------
    graph_node graph_sqrt(STRUCT_TAG graph_c_context *c,
@@ -191,7 +191,7 @@ extern "C" {
///  @brief Create exp node.
///
///  @param[in] c   The graph C context.
///  @param[in] arg The left opperand.
///  @param[in] arg The function argument.
///  @returns exp(arg)
//------------------------------------------------------------------------------
    graph_node graph_exp(STRUCT_TAG graph_c_context *c,
@@ -201,7 +201,7 @@ extern "C" {
///  @brief Create log node.
///
///  @param[in] c   The graph C context.
///  @param[in] arg The left opperand.
///  @param[in] arg The function argument.
///  @returns log(arg)
//------------------------------------------------------------------------------
    graph_node graph_log(STRUCT_TAG graph_c_context *c,
@@ -223,7 +223,7 @@ extern "C" {
///  @brief Create imaginary error function node.
///
///  @param[in] c   The graph C context.
///  @param[in] arg The left opperand.
///  @param[in] arg The function argument.
///  @returns erfi(arg)
//------------------------------------------------------------------------------
    graph_node graph_erfi(STRUCT_TAG graph_c_context *c,
@@ -233,7 +233,7 @@ extern "C" {
///  @brief Create sine node.
///
///  @param[in] c   The graph C context.
///  @param[in] arg The left opperand.
///  @param[in] arg The function argument.
///  @returns sin(arg)
//------------------------------------------------------------------------------
    graph_node graph_sin(STRUCT_TAG graph_c_context *c,
@@ -243,7 +243,7 @@ extern "C" {
///  @brief Create cosine node.
///
///  @param[in] c   The graph C context.
///  @param[in] arg The left opperand.
///  @param[in] arg The function argument.
///  @returns sin(arg)
//------------------------------------------------------------------------------
    graph_node graph_cos(STRUCT_TAG graph_c_context *c,
@@ -261,41 +261,31 @@ extern "C" {
                          graph_node left,
                          graph_node right);

//------------------------------------------------------------------------------
///  @brief Get random size.
///
///  @param[in] c The graph C context.
///  @return The random size.
//------------------------------------------------------------------------------
    size_t graph_random_size(STRUCT_TAG graph_c_context *c);

//------------------------------------------------------------------------------
///  @brief Construct a random state node.
///
///  @param[in] c    The graph C context.
///  @param[in] size Number of random states.
///  @param[in] seed Intial random seed.
///  @returns A random state node.
//------------------------------------------------------------------------------
    graph_node graph_random_state(STRUCT_TAG graph_c_context *c,
                                  const size_t size,
                                  const uint32_t seed);

//------------------------------------------------------------------------------
///  @brief Create random node.
///
///  @param[in] c     The graph C context.
///  @param[in] arg The left opperand.
///  @returns random(arg)
///  @param[in] state A random state node.
///  @returns random(state)
//------------------------------------------------------------------------------
    graph_node graph_random(STRUCT_TAG graph_c_context *c,
                            graph_node arg);
                            graph_node state);

//------------------------------------------------------------------------------
///  @brief Create 1D piecewise node.
///
///  @param[in] c           The graph C context.
///  @param[in] arg         The left opperand.
///  @param[in] arg         The function argument.
///  @param[in] scale       Scale factor argument.
///  @param[in] offset      Offset factor argument.
///  @param[in] source      Source buffer to fill elements.
@@ -314,12 +304,12 @@ extern "C" {
///
///  @param[in] c           The graph C context.
///  @param[in] num_cols    Number of columns.
///  @param[in] x_arg       The left opperand.
///  @param[in] x_scale     Scale factor argument.
///  @param[in] x_offset    Offset factor argument.
///  @param[in] y_arg       The left opperand.
///  @param[in] y_scale     Scale factor argument.
///  @param[in] y_offset    Offset factor argument.
///  @param[in] x_arg       The function x argument.
///  @param[in] x_scale     Scale factor x argument.
///  @param[in] x_offset    Offset factor x argument.
///  @param[in] y_arg       The function y argument.
///  @param[in] y_scale     Scale factor y argument.
///  @param[in] y_offset    Offset factor y argument.
///  @param[in] source      Source buffer to fill elements.
///  @param[in] source_size Number of elements in the source buffer.
///  @returns A 2D piecewise node.
+1046 −25

File changed.

Preview size limit exceeded, changes collapsed.

+15 −10
Original line number Diff line number Diff line
@@ -12,8 +12,6 @@ add_test_target (piecewise_test cpp)
add_test_target (erfi_test cpp)
add_test_target (efit_test cpp)
add_test_target (random_test cpp)
add_test_target (c_binding_test c)
add_test_target (f_binding_test f90)

target_compile_definitions (erfi_test
                            PRIVATE
@@ -25,11 +23,18 @@ target_compile_definitions (efit_test
                            EFIT_GOLD_FILE="${CMAKE_CURRENT_SOURCE_DIR}/efit_gold.nc"
)

if (${BUILD_C_BINDING})
    add_test_target (c_binding_test c)
    target_link_libraries (c_binding_test
                           PRIVATE
                           graph_c
    )
endif ()

if (${BUILD_Fortran_BINDING})
    add_test_target (f_binding_test f90)
    target_link_libraries (f_binding_test
                           PRIVATE
                           graph_f
    )
endif ()
+1 −3
Original line number Diff line number Diff line
@@ -98,9 +98,7 @@ void run_tests(const enum graph_type type,
        }
    }

    graph_node state = graph_random_state(c_context,
                                          graph_random_size(c_context),
                                          0);
    graph_node state = graph_random_state(c_context, 0);
    graph_node rand = graph_random(c_context, state);

    const size_t max_device = graph_get_max_concurrency(c_context) - 1;
Loading