<commit_before>/*******************************************************
 * Copyright (c) 2014, ArrayFire
 * All rights reserved.
 *
 * This file is distributed under 3-clause BSD license.
 * The complete license agreement can be obtained at:
 * http://arrayfire.com/licenses/BSD-3-Clause
 ********************************************************/

#include <af/graphics.h>
#include <af/image.h>

#include <ArrayInfo.hpp>
#include <graphics_common.hpp>
#include <err_common.hpp>
#include <backend.hpp>
#include <plot3.hpp>
#include <reduce.hpp>
#include <join.hpp>
#include <transpose.hpp>
#include <reorder.hpp>
#include <handle.hpp>
#include <af/data.h>
#include <iostream>

using af::dim4;
using namespace detail;

#if defined(WITH_GRAPHICS)
using namespace graphics;

template<typename T>
fg::Plot3* setup_plot3(const af_array P, fg::PlotType ptype, fg::MarkerType mtype)
{
    Array<T> pIn = getArray<T>(P);
    ArrayInfo Pinfo = getInfo(P);
    af::dim4 P_dims = Pinfo.dims();

    DIM_ASSERT(0, Pinfo.ndims() == 1 || Pinfo.ndims() == 2);
    DIM_ASSERT(0, (P_dims[0] == 3 || P_dims[1] == 3) ||
                    (Pinfo.isVector() && P_dims[0]%3 == 0));

    if(Pinfo.isVector()){
        dim4 rdims(P_dims.elements()/3, 3, 1, 1);
        pIn.modDims(rdims);
        P_dims = pIn.dims();
    }

    T max[3], min[3];
    if(P_dims[0] == 3) {
        copyData(max, reduce<af_max_t, T, T>(pIn, 1));
        copyData(min, reduce<af_min_t, T, T>(pIn, 1));
    }

    if(P_dims[1] == 3) {
        copyData(max, reduce<af_max_t, T, T>(pIn, 0));
        copyData(min, reduce<af_min_t, T, T>(pIn, 0));
    }

    ForgeManager& fgMngr = ForgeManager::getInstance();
    fg::Plot3* plot3 = fgMngr.getPlot3(P_dims.elements()/3, getGLType<T>(), ptype, mtype);
    plot3->setColor(1.0, 0.0, 0.0);
    plot3->setAxesLimits(max[0], min[0],
                         max[1], min[1],
                         max[2], min[2]);
    plot3->setAxesTitles("X Axis", "Y Axis", "Z Axis");

    if(P_dims[1] == 3){
        pIn = transpose(pIn, false);
    }
    copy_plot3<T>(pIn, plot3);

    return plot3;
}

af_err plot3Wrapper(const af_window wind, const af_array P, const af_cell* const props, const fg::PlotType type=fg::FG_LINE, const fg::MarkerType marker=fg::FG_NONE)
{
    if(wind==0) {
        std::cerr<<"Not a valid window"<<std::endl;
        return AF_SUCCESS;
    }

    try {
        ArrayInfo Pinfo = getInfo(P);
        af_dtype Ptype  = Pinfo.getType();

        fg::Window* window = reinterpret_cast<fg::Window*>(wind);
        window->makeCurrent();
        fg::Plot3* plot3 = NULL;

        switch(Ptype) {
            case f32: plot3 = setup_plot3<float >(P, type, marker); break;
            case s32: plot3 = setup_plot3<int   >(P, type, marker); break;<commit_msg>Cleaning up code in plot3<commit_after>/*******************************************************
 * Copyright (c) 2014, ArrayFire
 * All rights reserved.
 *
 * This file is distributed under 3-clause BSD license.
 * The complete license agreement can be obtained at:
 * http://arrayfire.com/licenses/BSD-3-Clause
 ********************************************************/

#include <af/graphics.h>
#include <af/image.h>

#include <ArrayInfo.hpp>
#include <graphics_common.hpp>
#include <err_common.hpp>
#include <backend.hpp>
#include <plot3.hpp>
#include <reduce.hpp>
#include <join.hpp>
#include <transpose.hpp>
#include <reorder.hpp>
#include <handle.hpp>
#include <af/data.h>
#include <iostream>

using af::dim4;
using namespace detail;

#if defined(WITH_GRAPHICS)
using namespace graphics;

template<typename T>
fg::Plot3* setup_plot3(const af_array P, fg::PlotType ptype, fg::MarkerType mtype)
{
    Array<T> pIn = getArray<T>(P);
    ArrayInfo Pinfo = getInfo(P);
    af::dim4 P_dims = Pinfo.dims();

    DIM_ASSERT(0, Pinfo.ndims() == 1 || Pinfo.ndims() == 2);
    DIM_ASSERT(0, (P_dims[0] == 3 || P_dims[1] == 3) ||
                    (Pinfo.isVector() && P_dims[0]%3 == 0));

    if(Pinfo.isVector()){
        dim4 rdims(P_dims.elements()/3, 3, 1, 1);
        pIn.modDims(rdims);
        P_dims = pIn.dims();
    }

    if(P_dims[1] == 3){
        pIn = transpose(pIn, false);
    }

    T max[3], min[3];
    copyData(max, reduce<af_max_t, T, T>(pIn, 1));
    copyData(min, reduce<af_min_t, T, T>(pIn, 1));

    ForgeManager& fgMngr = ForgeManager::getInstance();
    fg::Plot3* plot3 = fgMngr.getPlot3(P_dims.elements()/3, getGLType<T>(), ptype, mtype);
    plot3->setColor(1.0, 0.0, 0.0);
    plot3->setAxesLimits(max[0], min[0],
                         max[1], min[1],
                         max[2], min[2]);
    plot3->setAxesTitles("X Axis", "Y Axis", "Z Axis");
    copy_plot3<T>(pIn, plot3);
    return plot3;
}

af_err plot3Wrapper(const af_window wind, const af_array P, const af_cell* const props, const fg::PlotType type=fg::FG_LINE, const fg::MarkerType marker=fg::FG_NONE)
{
    if(wind==0) {
        std::cerr<<"Not a valid window"<<std::endl;
        return AF_SUCCESS;
    }

    try {
        ArrayInfo Pinfo = getInfo(P);
        af_dtype Ptype  = Pinfo.getType();

        fg::Window* window = reinterpret_cast<fg::Window*>(wind);
        window->makeCurrent();
        fg::Plot3* plot3 = NULL;

        switch(Ptype) {
            case f32: plot3 = setup_plot3<float >(P, type, marker); break;
            case s32: plot3 = setup_plot3<int   >(P, type, marker); break;
{'fraction_non_alphanumeric': 0.20022329735764793, 'fraction_numerical': 0.026237439523632302, 'mean_word_length': 3.289704708699122, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '725442', 'n_tokens_mistral': 2059, 'n_tokens_neox': 1979, 'n_words': 427}