<commit_before>#include "hog.pencil.h"

#include <math.h>   //sqrt, atan, atan2, ceil, floor
#include <string.h> //memset

#if SIGNED_HOG
static const float BINSIZE_IN_DEGREES = 360.0f / NUMBER_OF_BINS;
#else
static const float BINSIZE_IN_DEGREES = 180.0f / NUMBER_OF_BINS;
#endif

#ifndef M_PI
#define M_PI           3.14159265358979323846
#endif

#define min(x,y)    ((x) < (y) ? (x) : (y))
#define max(x,y)    ((x) > (y) ? (x) : (y))

static void hog_multi( const int rows
                     , const int cols
                     , const int step
                     , const uint8_t image[static const restrict rows][step]
                     , const int num_locations
                     , const float location_x[static const restrict num_locations]
                     , const float location_y[static const restrict num_locations]
                     , const float block_size
                     , float hist[static const restrict num_locations][NUMBER_OF_CELLS][NUMBER_OF_CELLS][NUMBER_OF_BINS]    //out
                     ) {
#pragma scop

#pragma pencil independent
    for (int i = 0; i < num_locations; ++i) {
	    float cell_size = block_size / NUMBER_OF_CELLS;
	    float minx = location_x[i] - block_size / 2.0f;
	    float miny = location_y[i] - block_size / 2.0f;
	    float maxx = location_x[i] + block_size / 2.0f;
	    float maxy = location_y[i] + block_size / 2.0f;

	    int minxi = max(ceil(minx), 1);
	    int minyi = max(ceil(miny), 1);
	    int maxxi = min(floor(maxx), cols - 2);
	    int maxyi = min(floor(maxy), rows - 2);

	    memset(hist[i], 0, HISTOGRAM_BINS);

#if GAUSSIAN_WEIGHTS
	    const float sigma = block_size / 2.0f;
	    const float sigmaSq = sigma*sigma;
	    const float m1p2sigmaSq = -1.0f / (2.0f * sigmaSq);
#endif

	    #pragma pencil independent reduction(+:hist[i])
	    for (int pointy = minyi; pointy <= maxyi; ++pointy) {
#if SPARTIAL_WEIGHTS
            float relative_pos_y = (pointy - miny) / cell_size - 0.5f;
            int cellyi = floor(relative_pos_y);
            float yscale1 = relative_pos_y - cellyi;
            float yscale0 = 1.0f - yscale1;
#endif
#if GAUSSIAN_WEIGHTS
            float dy = pointy - location_y[i];
            float dySq = dy*dy;
#endif

            #pragma pencil independent reduction(+:hist[i])
            for (int pointx = minxi; pointx <= maxxi; ++pointx) {
#if SPARTIAL_WEIGHTS<commit_msg>hog.pencil.c, replace the function memset by a loop<commit_after>#include "hog.pencil.h"

#include <math.h>   //sqrt, atan, atan2, ceil, floor
#include <string.h> //memset

#if SIGNED_HOG
static const float BINSIZE_IN_DEGREES = 360.0f / NUMBER_OF_BINS;
#else
static const float BINSIZE_IN_DEGREES = 180.0f / NUMBER_OF_BINS;
#endif

#ifndef M_PI
#define M_PI           3.14159265358979323846
#endif

#define min(x,y)    ((x) < (y) ? (x) : (y))
#define max(x,y)    ((x) > (y) ? (x) : (y))

static void hog_multi( const int rows
                     , const int cols
                     , const int step
                     , const uint8_t image[static const restrict rows][step]
                     , const int num_locations
                     , const float location_x[static const restrict num_locations]
                     , const float location_y[static const restrict num_locations]
                     , const float block_size
                     , float hist[static const restrict num_locations][NUMBER_OF_CELLS][NUMBER_OF_CELLS][NUMBER_OF_BINS]    //out
                     ) {
#pragma scop

#pragma pencil independent
    for (int i = 0; i < num_locations; ++i) {
	    float cell_size = block_size / NUMBER_OF_CELLS;
	    float minx = location_x[i] - block_size / 2.0f;
	    float miny = location_y[i] - block_size / 2.0f;
	    float maxx = location_x[i] + block_size / 2.0f;
	    float maxy = location_y[i] + block_size / 2.0f;

	    int minxi = max(ceil(minx), 1);
	    int minyi = max(ceil(miny), 1);
	    int maxxi = min(floor(maxx), cols - 2);
	    int maxyi = min(floor(maxy), rows - 2);

	    for (int j1 = 0; j1 < NUMBER_OF_CELLS; j1++)
	      for (int j2 = 0; j2 < NUMBER_OF_CELLS; j2++)
	        for (int j3 = 0; j3 < NUMBER_OF_BINS; j3++)
	          hist[i][j1][j2][j3] = 0;

#if GAUSSIAN_WEIGHTS
	    const float sigma = block_size / 2.0f;
	    const float sigmaSq = sigma*sigma;
	    const float m1p2sigmaSq = -1.0f / (2.0f * sigmaSq);
#endif

	    #pragma pencil independent reduction(+:hist[i])
	    for (int pointy = minyi; pointy <= maxyi; ++pointy) {
#if SPARTIAL_WEIGHTS
            float relative_pos_y = (pointy - miny) / cell_size - 0.5f;
            int cellyi = floor(relative_pos_y);
            float yscale1 = relative_pos_y - cellyi;
            float yscale0 = 1.0f - yscale1;
#endif
#if GAUSSIAN_WEIGHTS
            float dy = pointy - location_y[i];
            float dySq = dy*dy;
#endif

            #pragma pencil independent reduction(+:hist[i])
            for (int pointx = minxi; pointx <= maxxi; ++pointx) {
#if SPARTIAL_WEIGHTS
{'fraction_non_alphanumeric': 0.1124949779027722, 'fraction_numerical': 0.027119325030132584, 'mean_word_length': 2.306108897742364, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 9, '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': '3168726', 'n_tokens_mistral': 1935, 'n_tokens_neox': 1757, 'n_words': 460}