<commit_before>#include <vector>
#include <arrayfire.h>
#include <af/utils.h>
#include "java_wrapper.h"

#ifdef ANDROID
#include <android/log.h>
#define  LOG(...)  __android_log_print(ANDROID_LOG_INFO, "ArrayFireJNI", __VA_ARGS__)
#else
#define LOG(msg,...) do {                       \
    printf(__FILE__":%d: " msg "\n",            \
           __LINE__, ##__VA_ARGS__);            \
  } while (0)
#endif

const int MaxDimSupported = 3;

JNIEXPORT void JNICALL Java_com_arrayfire_Array_info(JNIEnv *env, jclass clazz)
{
    try{
#ifndef ANDROID
        af::info();
#endif
    } catch(af::exception& e) {
    } catch(std::exception& e) {
    }
}

JNIEXPORT jlong JNICALL Java_com_arrayfire_Array_createRanduArray(JNIEnv *env, jclass clazz, jintArray dims, jint type)
{
    jlong ret;
    try{
        jint* dimptr = env->GetIntArrayElements(dims,0);
        af::dtype ty = (af::dtype)(type);
        af::array *A = new af::array(dimptr[0],dimptr[1],dimptr[2],dimptr[3], ty);
        *A = af::randu(dimptr[0],dimptr[1],dimptr[2], ty);
        ret = (jlong)(A);
        env->ReleaseIntArrayElements(dims,dimptr,0);
    } catch(af::exception& e) {
        ret = 0;
    } catch(std::exception& e) {
        ret = 0;
    }
    return ret;
}

JNIEXPORT jlong JNICALL Java_com_arrayfire_Array_createRandnArray(JNIEnv *env, jclass clazz, jintArray dims, jint type)
{
    jlong ret;
    try{
        jint* dimptr = env->GetIntArrayElements(dims,0);
        af::dtype ty = (af::dtype)(type);
        af::array *A = new af::array(dimptr[0],dimptr[1],dimptr[2],dimptr[3], ty);
        *A = af::randn(dimptr[0],dimptr[1],dimptr[2], ty);
        ret = (jlong)(A);
        env->ReleaseIntArrayElements(dims,dimptr,0);
    } catch(af::exception& e) {
        ret = 0;
    } catch(std::exception& e) {
        ret = 0;
    }
    return ret;
}


JNIEXPORT jlong JNICALL Java_com_arrayfire_Array_createConstantsArray(JNIEnv *env, jclass clazz, jdouble val, jintArray dims, jint type)
{
    jlong ret;
    try{
        jint* dimptr = env->GetIntArrayElements(dims,0);
        af::dtype ty = (af::dtype)(type);
        af::array *A = new af::array(dimptr[0],dimptr[1],dimptr[2],dimptr[3], ty);
        *A = af::constant(val, dimptr[0],dimptr[1],dimptr[2], ty);
        ret = (jlong)(A);
        env->ReleaseIntArrayElements(dims,dimptr,0);
    } catch(af::exception& e) {
        ret = 0;
    } catch(std::exception& e) {
        ret = 0;
    }
    return ret;
}

JNIEXPORT jlong JNICALL Java_com_arrayfire_Array_createEmptyArray(JNIEnv *env, jclass clazz, jintArray dims, jint type)
{
    jlong ret;
    try{
        jint* dimptr = env->GetIntArrayElements(dims,0);
        af::dtype ty = (af::dtype)(type);
        af::array *A = new af::array(dimptr[0],dimptr[1],dimptr[2],dimptr[3], ty);
        *A = af::constant(0.0f,dimptr[0],dimptr[1],dimptr[2], ty);
        ret = (jlong)(A);
        env->ReleaseIntArrayElements(dims,dimptr,0);
    } catch(af::exception& e) {
        ret = 0;
    } catch(std::exception& e) {
        ret = 0;
    }
    return ret;
}

#define CREATE_ARRAY_T(Ty, ty)                                          \
    JNIEXPORT jlong JNICALL Java_com_arrayfire_Array_createArrayFrom##Ty \
    (JNIEnv *env, jclass clazz, jintArray dims, j##ty##Array elems)     \
    {                                                                   \
        jlong ret;                                                      \
        try{                                                            \
            jint* dimptr = env->GetIntArrayElements(dims,0);            \
            j##ty* inptr= env->Get##Ty##ArrayElements(elems,0);         \
                af::array *A = new af::array(dimptr[0],dimptr[1],       \
                                             dimptr[2],dimptr[3],inptr); \
                                                                        \
                ret = (jlong)(A);                                       \
                env->ReleaseIntArrayElements(dims,dimptr,0);            \
                env->Release##Ty##ArrayElements(elems,inptr,0);         \
        } catch(af::exception& e) {                                     \
            ret = 0;                                                    \
        } catch(std::exception& e) {                                    \
            ret = 0;                                                    \
        }                                                               \
        return ret;                                                     \
    }                                                                   \

CREATE_ARRAY_T(Float, float);
CREATE_ARRAY_T(Double, double);
CREATE_ARRAY_T(Int, int);
CREATE_ARRAY_T(Boolean, boolean);<commit_msg>Changes to JNI wrapper required for Windows<commit_after>#include <vector>
#include <arrayfire.h>
#include <af/utils.h>
#include "java_wrapper.h"

#ifdef ANDROID
#include <android/log.h>
#define  LOG(...)  __android_log_print(ANDROID_LOG_INFO, "ArrayFireJNI", __VA_ARGS__)
#else
#define LOG(msg,...) do {                       \
    printf(__FILE__":%d: " msg "\n",            \
           __LINE__, ##__VA_ARGS__);            \
  } while (0)
#endif

const int MaxDimSupported = 3;

JNIEXPORT void JNICALL Java_com_arrayfire_Array_info(JNIEnv *env, jclass clazz)
{
    try{
#ifndef ANDROID
        af::info();
#endif
    } catch(af::exception& e) {
    } catch(std::exception& e) {
    }
}

JNIEXPORT jlong JNICALL Java_com_arrayfire_Array_createRanduArray(JNIEnv *env, jclass clazz, jintArray dims, jint type)
{
    jlong ret;
    try{
        jint* dimptr = env->GetIntArrayElements(dims,0);
        af::dtype ty = (af::dtype)(type);
        af::array *A = new af::array(dimptr[0],dimptr[1],dimptr[2],dimptr[3], ty);
        *A = af::randu(dimptr[0],dimptr[1],dimptr[2], ty);
        ret = (jlong)(A);
        env->ReleaseIntArrayElements(dims,dimptr,0);
    } catch(af::exception& e) {
        ret = 0;
    } catch(std::exception& e) {
        ret = 0;
    }
    return ret;
}

JNIEXPORT jlong JNICALL Java_com_arrayfire_Array_createRandnArray(JNIEnv *env, jclass clazz, jintArray dims, jint type)
{
    jlong ret;
    try{
        jint* dimptr = env->GetIntArrayElements(dims,0);
        af::dtype ty = (af::dtype)(type);
        af::array *A = new af::array(dimptr[0],dimptr[1],dimptr[2],dimptr[3], ty);
        *A = af::randn(dimptr[0],dimptr[1],dimptr[2], ty);
        ret = (jlong)(A);
        env->ReleaseIntArrayElements(dims,dimptr,0);
    } catch(af::exception& e) {
        ret = 0;
    } catch(std::exception& e) {
        ret = 0;
    }
    return ret;
}


JNIEXPORT jlong JNICALL Java_com_arrayfire_Array_createConstantsArray(JNIEnv *env, jclass clazz, jdouble val, jintArray dims, jint type)
{
    jlong ret;
    try{
        jint* dimptr = env->GetIntArrayElements(dims,0);
        af::dtype ty = (af::dtype)(type);
        af::array *A = new af::array(dimptr[0],dimptr[1],dimptr[2],dimptr[3], ty);
        *A = af::constant(val, dimptr[0],dimptr[1],dimptr[2], ty);
        ret = (jlong)(A);
        env->ReleaseIntArrayElements(dims,dimptr,0);
    } catch(af::exception& e) {
        ret = 0;
    } catch(std::exception& e) {
        ret = 0;
    }
    return ret;
}

JNIEXPORT jlong JNICALL Java_com_arrayfire_Array_createEmptyArray(JNIEnv *env, jclass clazz, jintArray dims, jint type)
{
    jlong ret;
    try{
        jint* dimptr = env->GetIntArrayElements(dims,0);
        af::dtype ty = (af::dtype)(type);
        af::array *A = new af::array(dimptr[0],dimptr[1],dimptr[2],dimptr[3], ty);
        *A = af::constant(0.0f,dimptr[0],dimptr[1],dimptr[2], ty);
        ret = (jlong)(A);
        env->ReleaseIntArrayElements(dims,dimptr,0);
    } catch(af::exception& e) {
        ret = 0;
    } catch(std::exception& e) {
        ret = 0;
    }
    return ret;
}

#define CREATE_ARRAY_T_(Ty, ty, wty)                                     \
    JNIEXPORT jlong JNICALL Java_com_arrayfire_Array_createArrayFrom##Ty \
    (JNIEnv *env, jclass clazz, jintArray dims, j##ty##Array elems)     \
    {                                                                   \
        jlong ret;                                                      \
        try{                                                            \
            jint* dimptr = env->GetIntArrayElements(dims,0);            \
            wty* inptr= (wty*)env->Get##Ty##ArrayElements(elems,0);     \
                af::array *A = new af::array(dimptr[0],dimptr[1],       \
                                             dimptr[2],dimptr[3],inptr);\
                                                                        \
                ret = (jlong)(A);                                       \
                env->ReleaseIntArrayElements(dims,dimptr,0);            \
                env->Release##Ty##ArrayElements(elems,(j##ty*)inptr,0); \
        } catch(af::exception& e) {                                     \
            ret = 0;                                                    \
        } catch(std::exception& e) {                                    \
            ret = 0;                                                    \
        }                                                               \
        return ret;                                                     \
    }                                                                   \


#define CREATE_ARRAY_T(Ty, ty) CREATE_ARRAY_T_(Ty, ty, ty)

CREATE_ARRAY_T(Float, float);
CREATE_ARRAY_T(Double, double);
CREATE_ARRAY_T(Int, int);

CREATE_ARRAY_T_(Boolean, boolean, bool);
{'fraction_non_alphanumeric': 0.1352848928384736, 'fraction_numerical': 0.012127548353371667, 'mean_word_length': 1.6294667399670149, 'pattern_counts': {'":': 2, '<': 11, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 57, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2601596', 'n_tokens_mistral': 3068, 'n_tokens_neox': 3042, 'n_words': 547}