Skip to content
This repository has been archived by the owner on Sep 1, 2023. It is now read-only.

Commit

Permalink
reformat code using clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
lscheinkman committed Feb 27, 2018
1 parent 8343255 commit a6c186a
Show file tree
Hide file tree
Showing 251 changed files with 58,691 additions and 67,335 deletions.
67 changes: 3 additions & 64 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,66 +1,5 @@
---
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: true
AlignEscapedNewlinesLeft: false
AlignOperands: true
AlignTrailingComments: true
AlignConsecutiveAssignments: false
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AlwaysBreakAfterDefinitionReturnType: false
AlwaysBreakTemplateDeclarations: false
AlwaysBreakBeforeMultilineStrings: false
BreakBeforeBinaryOperators: None
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BinPackParameters: true
BinPackArguments: true
ColumnLimit: 80
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
DerivePointerAlignment: false
ExperimentalAutoDetectBinPacking: false
IndentCaseLabels: false
IndentWrappedFunctionNames: false
IndentFunctionDeclarationAfterType: false
MaxEmptyLinesToKeep: 1
KeepEmptyLinesAtTheStartOfBlocks: true
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakString: 1000
PenaltyBreakFirstLessLess: 120
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
SpacesBeforeTrailingComments: 1
Cpp11BracedListStyle: true
Standard: Cpp11
IndentWidth: 2
TabWidth: 8
UseTab: Never
BreakBeforeBraces: Attach
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpacesInAngles: false
SpaceInEmptyParentheses: false
SpacesInCStyleCastParentheses: false
SpaceAfterCStyleCast: false
SpacesInContainerLiterals: true
SpaceBeforeAssignmentOperators: true
ContinuationIndentWidth: 4
CommentPragmas: '^ IWYU pragma:'
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
SpaceBeforeParens: ControlStatements
DisableFormat: false
Language: Cpp
BasedOnStyle: LLVM
DisableFormat: false
...

42 changes: 23 additions & 19 deletions src/examples/algorithms/HelloSP_TP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,33 @@
* ---------------------------------------------------------------------
*/

#include <algorithm> // std::generate
#include <cmath> // pow
#include <cstdlib> // std::rand, std::srand
#include <ctime> // std::time
#include <iostream>
#include <vector>
#include <algorithm> // std::generate
#include <ctime> // std::time
#include <cstdlib> // std::rand, std::srand
#include <cmath> // pow

#include "nupic/algorithms/SpatialPooler.hpp"
#include "nupic/algorithms/Cells4.hpp"
#include "nupic/algorithms/SpatialPooler.hpp"
#include "nupic/os/Timer.hpp"

using namespace std;
using namespace nupic;
using nupic::algorithms::spatial_pooler::SpatialPooler;
using nupic::algorithms::Cells4::Cells4;
using nupic::algorithms::spatial_pooler::SpatialPooler;

// function generator:
int RandomNumber01 () { return (rand()%2); } // returns random (binary) numbers from {0,1}
int RandomNumber01() {
return (rand() % 2);
} // returns random (binary) numbers from {0,1}

int main(int argc, const char * argv[])
{
const UInt DIM = 2048; // number of columns in SP, TP
const UInt DIM_INPUT = 10000;
const UInt TP_CELLS_PER_COL = 10; // cells per column in TP
const UInt EPOCHS = pow(10, 4); // number of iterations (calls to SP/TP compute() )
int main(int argc, const char *argv[]) {
const UInt DIM = 2048; // number of columns in SP, TP
const UInt DIM_INPUT = 10000;
const UInt TP_CELLS_PER_COL = 10; // cells per column in TP
const UInt EPOCHS =
pow(10, 4); // number of iterations (calls to SP/TP compute() )

vector<UInt> inputDim = {DIM_INPUT};
vector<UInt> colDim = {DIM};
Expand All @@ -53,18 +55,19 @@ const UInt EPOCHS = pow(10, 4); // number of iterations (calls to SP/TP compute(
vector<UInt> input(DIM_INPUT);
vector<UInt> outSP(DIM); // active array, output of SP/TP
const int _CELLS = DIM * TP_CELLS_PER_COL;
vector<UInt> outTP(_CELLS);
vector<UInt> outTP(_CELLS);
Real rIn[DIM] = {}; // input for TP (must be Reals)
Real rOut[_CELLS] = {};

// initialize SP, TP
SpatialPooler sp(inputDim, colDim);
Cells4 tp(DIM, TP_CELLS_PER_COL, 12, 8, 15, 5, .5, .8, 1.0, .1, .1, 0.0, false, 42, true, false);
Cells4 tp(DIM, TP_CELLS_PER_COL, 12, 8, 15, 5, .5, .8, 1.0, .1, .1, 0.0,
false, 42, true, false);

// Start a stopwatch timer
Timer stopwatch(true);

//run
// run
for (UInt e = 0; e < EPOCHS; e++) {
generate(input.begin(), input.end(), RandomNumber01);
fill(outSP.begin(), outSP.end(), 0);
Expand All @@ -77,20 +80,21 @@ const UInt EPOCHS = pow(10, 4); // number of iterations (calls to SP/TP compute(

tp.compute(rIn, rOut, true, true);

for (UInt i=0; i< _CELLS; i++) {
for (UInt i = 0; i < _CELLS; i++) {
outTP[i] = (UInt)rOut[i];
}

// print
if (e == EPOCHS-1) {
if (e == EPOCHS - 1) {
cout << "Epoch = " << e << endl;
cout << "SP=" << outSP << endl;
cout << "TP=" << outTP << endl;
}
}

stopwatch.stop();
cout << "Total elapsed time = " << stopwatch.getElapsed() << " seconds" << endl;
cout << "Total elapsed time = " << stopwatch.getElapsed() << " seconds"
<< endl;

return 0;
}
45 changes: 15 additions & 30 deletions src/examples/prototest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
* ---------------------------------------------------------------------
*/

#include <iostream>
#include <fstream>
#include <iostream>
#include <stdio.h>
#include <time.h>
#include <vector>
Expand All @@ -38,8 +38,7 @@ using namespace std;
using namespace nupic;
using namespace nupic::algorithms::spatial_pooler;

void testSP()
{
void testSP() {
Random random(10);

const UInt inputSize = 500;
Expand All @@ -53,30 +52,25 @@ void testSP()
sp1.initialize(inputDims, colDims);

UInt input[inputSize];
for (UInt i = 0; i < inputSize; ++i)
{
if (i < w)
{
for (UInt i = 0; i < inputSize; ++i) {
if (i < w) {
input[i] = 1;
} else {
input[i] = 0;
}
}
UInt output[numColumns];

for (UInt i = 0; i < 10000; ++i)
{
for (UInt i = 0; i < 10000; ++i) {
random.shuffle(input, input + inputSize);
sp1.compute(input, true, output);
}

// Now we reuse the last input to test after serialization

vector<UInt> activeColumnsBefore;
for (UInt i = 0; i < numColumns; ++i)
{
if (output[i] == 1)
{
for (UInt i = 0; i < numColumns; ++i) {
if (output[i] == 1) {
activeColumnsBefore.push_back(i);
}
}
Expand All @@ -94,8 +88,7 @@ void testSP()

Real64 timeA = 0.0, timeC = 0.0;

for (UInt i = 0; i < 100; ++i)
{
for (UInt i = 0; i < 100; ++i) {
// Create new input
random.shuffle(input, input + inputSize);

Expand Down Expand Up @@ -128,8 +121,7 @@ void testSP()
timeA = timeA + testTimer.getElapsed();
}

for (UInt i = 0; i < numColumns; ++i)
{
for (UInt i = 0; i < numColumns; ++i) {
NTA_CHECK(outputBaseline[i] == outputA[i]);
}

Expand Down Expand Up @@ -158,11 +150,9 @@ void testSP()
timeC = timeC + testTimer.getElapsed();
}

for (UInt i = 0; i < numColumns; ++i)
{
for (UInt i = 0; i < numColumns; ++i) {
NTA_CHECK(outputBaseline[i] == outputC[i]);
}

}

remove("outA.proto");
Expand All @@ -173,15 +163,13 @@ void testSP()
cout << "Manual: " << timeC << endl;
}

void testRandomIOStream(UInt n)
{
void testRandomIOStream(UInt n) {
Random r1(7);
Random r2;

nupic::Timer testTimer;
testTimer.start();
for (UInt i = 0; i < n; ++i)
{
for (UInt i = 0; i < n; ++i) {
r1.getUInt32();

// Serialize
Expand Down Expand Up @@ -209,15 +197,13 @@ void testRandomIOStream(UInt n)
cout << "Cap'n Proto: " << testTimer.getElapsed() << endl;
}

void testRandomManual(UInt n)
{
void testRandomManual(UInt n) {
Random r1(7);
Random r2;

nupic::Timer testTimer;
testTimer.start();
for (UInt i = 0; i < n; ++i)
{
for (UInt i = 0; i < n; ++i) {
r1.getUInt32();

// Serialize
Expand Down Expand Up @@ -245,8 +231,7 @@ void testRandomManual(UInt n)
cout << "Manual: " << testTimer.getElapsed() << endl;
}

int main(int argc, const char * argv[])
{
int main(int argc, const char *argv[]) {
UInt n = 1000;
cout << "Timing for Random serialization (smaller is better):" << endl;
testRandomIOStream(n);
Expand Down
Loading

0 comments on commit a6c186a

Please sign in to comment.