Skip to content

Commit

Permalink
Apply clang-format
Browse files Browse the repository at this point in the history
This applies clang-format to all source files.
No code changes.
  • Loading branch information
mlund committed Oct 22, 2024
1 parent 1e9e8dd commit 1742b51
Show file tree
Hide file tree
Showing 271 changed files with 24,745 additions and 24,487 deletions.
4 changes: 4 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
BasedOnStyle: LLVM
SortIncludes: false
Standard: c++11

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build/
*~
78 changes: 38 additions & 40 deletions src/API/DomainSampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
D I S C L A I M E R
IN NO EVENT SHALL TRININTY COLLEGE DUBLIN BE LIABLE TO ANY PARTY FOR
IN NO EVENT SHALL TRININTY COLLEGE DUBLIN BE LIABLE TO ANY PARTY FOR
DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING,
BUT NOT LIMITED TO, LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE
AND ITS DOCUMENTATION, EVEN IF TRINITY COLLEGE DUBLIN HAS BEEN ADVISED OF
BUT NOT LIMITED TO, LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE
AND ITS DOCUMENTATION, EVEN IF TRINITY COLLEGE DUBLIN HAS BEEN ADVISED OF
THE POSSIBILITY OF SUCH DAMAGES.
TRINITY COLLEGE DUBLIN DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE SOFTWARE PROVIDED HEREIN IS ON AN "AS IS" BASIS, AND TRINITY
TRINITY COLLEGE DUBLIN DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE SOFTWARE PROVIDED HEREIN IS ON AN "AS IS" BASIS, AND TRINITY
COLLEGE DUBLIN HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
ENHANCEMENTS, OR MODIFICATIONS.
Expand All @@ -39,31 +39,30 @@
#include "DomainSampler.h"
#include "../Base/Defs.h"

int findInfo(const SamplerInfo infos[], float v, int n){
int findInfo(const SamplerInfo infos[], float v, int n) {
// binary search
int minI = 0, maxI = n-1;
while (minI < maxI-1){
int midI = (minI+maxI)/2;
if (infos[midI].val < v){
int minI = 0, maxI = n - 1;
while (minI < maxI - 1) {
int midI = (minI + maxI) / 2;
if (infos[midI].val < v) {
// use midI..maxI
minI = midI;
}
else{
} else {
// use minI..midI
maxI = midI;
}
}
}

if (infos[minI].val < v)
return maxI;
else
return minI;
}

int samplerInfoCompare(const void *elem1, const void *elem2){
SamplerInfo *i1 = (SamplerInfo*)elem1;
SamplerInfo *i2 = (SamplerInfo*)elem2;
float d = i1-i2;
int samplerInfoCompare(const void *elem1, const void *elem2) {
SamplerInfo *i1 = (SamplerInfo *)elem1;
SamplerInfo *i2 = (SamplerInfo *)elem2;
float d = i1 - i2;
if (d < 0)
return -1;
else if (d > 0)
Expand All @@ -72,60 +71,59 @@ int samplerInfoCompare(const void *elem1, const void *elem2){
return 0;
}

void sampleDomain(Array<int> *counts, SamplerInfo infos[], int numVals, int numSamples){
void sampleDomain(Array<int> *counts, SamplerInfo infos[], int numVals,
int numSamples) {
// setup counts
counts->reallocate(numVals);

// initialise domain info & counts
for (int i = 0; i < numVals; i++){
for (int i = 0; i < numVals; i++) {
SamplerInfo *inf = &infos[i];
inf->sourceI = i;

counts->index(i) = 0;
}
}

// order the infos in increasing order
qsort(infos, numVals, sizeof(SamplerInfo), samplerInfoCompare);

// get total of the domain values
float total = 0.0f;
for (int i = 0; i < numVals; i++){
for (int i = 0; i < numVals; i++) {
total += infos[i].val;
}

}

// make cumulative and work out maxSamples
float totalSofar = 0.0f;
for (int i = 0; i < numVals; i++){
for (int i = 0; i < numVals; i++) {
SamplerInfo *s = &infos[i];
s->maxSamples = numSamples*(s->val / total);
s->maxSamples = numSamples * (s->val / total);
totalSofar += s->val;
s->val = totalSofar;
}
}

// generate samples
for (int i = 0; i < numSamples; i++){
for (int i = 0; i < numSamples; i++) {
// pick a random triangle
float r = rand()/(float)RAND_MAX;
int j = findInfo(infos, r*total, numVals);
float r = rand() / (float)RAND_MAX;
int j = findInfo(infos, r * total, numVals);

if (j == -1){
if (j == -1) {
OUTPUTINFO("Problem attributing sample");
i--;
}
else{
} else {
SamplerInfo *s = &infos[j];
if (counts->index(s->sourceI) <= s->maxSamples){
counts->index(s->sourceI)++; // do sample
}
else{
i--; // reject sample
}
if (counts->index(s->sourceI) <= s->maxSamples) {
counts->index(s->sourceI)++; // do sample
} else {
i--; // reject sample
}
}
}
}

void sampleDomain(Array<int> *counts, const Array<float> &vals, int numSamples){
void sampleDomain(Array<int> *counts, const Array<float> &vals,
int numSamples) {
// initialise domain info
int numVals = vals.getSize();
SamplerInfo *infos = new SamplerInfo[numVals];
Expand Down
21 changes: 11 additions & 10 deletions src/API/DomainSampler.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
D I S C L A I M E R
IN NO EVENT SHALL TRININTY COLLEGE DUBLIN BE LIABLE TO ANY PARTY FOR
IN NO EVENT SHALL TRININTY COLLEGE DUBLIN BE LIABLE TO ANY PARTY FOR
DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING,
BUT NOT LIMITED TO, LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE
AND ITS DOCUMENTATION, EVEN IF TRINITY COLLEGE DUBLIN HAS BEEN ADVISED OF
BUT NOT LIMITED TO, LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE
AND ITS DOCUMENTATION, EVEN IF TRINITY COLLEGE DUBLIN HAS BEEN ADVISED OF
THE POSSIBILITY OF SUCH DAMAGES.
TRINITY COLLEGE DUBLIN DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE SOFTWARE PROVIDED HEREIN IS ON AN "AS IS" BASIS, AND TRINITY
TRINITY COLLEGE DUBLIN DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE SOFTWARE PROVIDED HEREIN IS ON AN "AS IS" BASIS, AND TRINITY
COLLEGE DUBLIN HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
ENHANCEMENTS, OR MODIFICATIONS.
Expand All @@ -37,15 +37,15 @@
\**************************************************************************/

/*
Attribute a number of samples to a set of areas in a domain. Each areas has a
probability associated with it.
Attribute a number of samples to a set of areas in a domain. Each areas has
a probability associated with it.
*/
#ifndef _DOMAIN_SAMPLER_H_
#define _DOMAIN_SAMPLER_H_

#include "../Storage/Array.h"

struct SamplerInfo{
struct SamplerInfo {
float val;
int sourceI;
float maxSamples;
Expand All @@ -54,7 +54,8 @@ struct SamplerInfo{
int findInfo(const SamplerInfo infos[], float v, int n);
int samplerInfoCompare(const void *elem1, const void *elem2);

void sampleDomain(Array<int> *counts, SamplerInfo infos[], int numVals, int numSamples);
void sampleDomain(Array<int> *counts, SamplerInfo infos[], int numVals,
int numSamples);
void sampleDomain(Array<int> *counts, const Array<float> &vals, int numSamples);

#endif
Loading

0 comments on commit 1742b51

Please sign in to comment.