Skip to content

Commit 4853d82

Browse files
committed
Unbundle gridcodingrange code from htmresearch
1 parent 14172a9 commit 4853d82

File tree

2,621 files changed

+536539
-34
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,621 files changed

+536539
-34
lines changed

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# gridcodingrange
2+
3+
## Installation
4+
5+
~~~
6+
git clone https://github.com/Numenta/gridcodingrange
7+
cd gridcodingrange
8+
pip install -r requirements.txt
9+
pip install .
10+
~~~

gridcodingrange/__init__.py

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import _gridcodingrange
2+
3+
import numpy as np
4+
5+
6+
def computeGridUniquenessHypercube(domainToPlaneByModule, latticeBasisByModule,
7+
phaseResolution, ignoredCenterDiameter,
8+
pingInterval=10.0):
9+
domainToPlaneByModule = np.asarray(
10+
domainToPlaneByModule, dtype="float64")
11+
latticeBasisByModule = np.asarray(
12+
latticeBasisByModule, dtype="float64")
13+
14+
return _gridcodingrange.computeGridUniquenessHypercube(
15+
domainToPlaneByModule, latticeBasisByModule, phaseResolution,
16+
ignoredCenterDiameter, pingInterval)
17+
18+
19+
def computeBinSidelength(domainToPlaneByModule, phaseResolution,
20+
resultPrecision, upperBound=1000.0, timeout=-1.0):
21+
domainToPlaneByModule = np.asarray(
22+
domainToPlaneByModule, dtype="float64")
23+
24+
return _gridcodingrange.computeBinSidelength(
25+
domainToPlaneByModule, phaseResolution, resultPrecision, upperBound, timeout)
26+
27+
28+
def computeBinRectangle(domainToPlaneByModule, phaseResolution,
29+
resultPrecision, upperBound=1000.0, timeout=-1.0):
30+
domainToPlaneByModule = np.asarray(
31+
domainToPlaneByModule, dtype="float64")
32+
33+
return _gridcodingrange.computeBinRectangle(
34+
domainToPlaneByModule, phaseResolution, resultPrecision, upperBound, timeout)

make-tests.sh

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
cd "$(dirname "$0")"
6+
7+
debug=false
8+
9+
outbin="run-tests"
10+
11+
cmd="g++ -o $outbin ./src/test/main.cpp ./src/test/GridUniquenessTest.cpp ./src/GridUniqueness.cpp ./src/external/gtest/src/gtest-all.cc -I./src -I./src/external -I./src/external/gtest -lpthread"
12+
13+
if [ "$debug" = true ] ; then
14+
cmd="$cmd -g -D NTA_ASSERTIONS_ON"
15+
else
16+
cmd="$cmd -O3"
17+
fi
18+
19+
eval $cmd
20+
21+
echo "To run unit tests, execute: ./$outbin"

requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pybind11

setup.py

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import sys
2+
from setuptools import setup, Extension
3+
4+
5+
class get_pybind_include(object):
6+
"""Helper class to determine the pybind11 include path
7+
The purpose of this class is to postpone importing pybind11
8+
until it is actually installed, so that the ``get_include()``
9+
method can be invoked. """
10+
11+
def __init__(self, user=False):
12+
self.user = user
13+
14+
def __str__(self):
15+
import pybind11
16+
return pybind11.get_include(self.user)
17+
18+
19+
sources = [
20+
'src/gridcodingrange_module.cpp',
21+
'src/GridUniqueness.cpp',
22+
]
23+
24+
25+
compile_args = ["-std=c++14"]
26+
link_args = []
27+
28+
debug_mode = False
29+
if debug_mode:
30+
compile_args += ["-O0", "-D NTA_ASSERTIONS_ON"]
31+
else:
32+
compile_args += ["-g0"]
33+
34+
35+
if sys.platform == "darwin":
36+
compile_args += ["-std=c++14", "-mmacosx-version-min=10.10"]
37+
link_args += ["-stdlib=libc++", "-mmacosx-version-min=10.10"]
38+
39+
40+
module = Extension(
41+
'_gridcodingrange',
42+
sources=sources,
43+
extra_compile_args=compile_args,
44+
extra_link_args=link_args,
45+
include_dirs=['./src/external',
46+
get_pybind_include(),
47+
get_pybind_include(user=True)]
48+
)
49+
50+
setup(name='gridcodingrange',
51+
version='1.0',
52+
description='This is a demo package',
53+
packages=['gridcodingrange'],
54+
setup_requires=["pybind11"],
55+
ext_modules=[module])

src/GridUniqueness.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
* Implementations for GridUniqueness.hpp
2525
*/
2626

27-
#include <nupic/experimental/GridUniqueness.hpp>
28-
#include <nupic/utils/Log.hpp>
27+
#include "GridUniqueness.hpp"
28+
#include <nta_logging.hpp>
2929

3030
#include <math.h>
3131
#include <signal.h>

src/GridUniqueness.hpp

+24-25
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#ifndef NTA_GRID_UNIQUENESS_HPP
2828
#define NTA_GRID_UNIQUENESS_HPP
2929

30-
#include <nupic/types/Types.hpp>
3130
#include <vector>
3231
#include <utility>
3332

@@ -65,12 +64,12 @@ namespace nupic {
6564
* true if grid code zero is found, false otherwise.
6665
*/
6766
bool findGridCodeZero(
68-
const std::vector<std::vector<std::vector<Real64>>>& domainToPlaneByModule,
69-
const std::vector<std::vector<std::vector<Real64>>>& latticeBasisByModule,
70-
const std::vector<Real64>& x0,
71-
const std::vector<Real64>& dims,
72-
Real64 readoutResolution,
73-
std::vector<Real64>* pointWithGridCodeZero = nullptr);
67+
const std::vector<std::vector<std::vector<double>>>& domainToPlaneByModule,
68+
const std::vector<std::vector<std::vector<double>>>& latticeBasisByModule,
69+
const std::vector<double>& x0,
70+
const std::vector<double>& dims,
71+
double readoutResolution,
72+
std::vector<double>* pointWithGridCodeZero = nullptr);
7473

7574
/**
7675
* Given a set of grid cell module parameters, determines the diameter of
@@ -129,12 +128,12 @@ namespace nupic {
129128
* - The diameter of the hypercube that contains no collisions.
130129
* - A point just outside this hypercube that collides with the origin.
131130
*/
132-
std::pair<Real64,std::vector<Real64>> computeGridUniquenessHypercube(
133-
const std::vector<std::vector<std::vector<Real64>>>& domainToPlaneByModule,
134-
const std::vector<std::vector<std::vector<Real64>>>& latticeBasisByModule,
135-
Real64 readoutResolution,
136-
Real64 ignoredCenterDiameter,
137-
Real64 pingInterval=10.0);
131+
std::pair<double,std::vector<double>> computeGridUniquenessHypercube(
132+
const std::vector<std::vector<std::vector<double>>>& domainToPlaneByModule,
133+
const std::vector<std::vector<std::vector<double>>>& latticeBasisByModule,
134+
double readoutResolution,
135+
double ignoredCenterDiameter,
136+
double pingInterval=10.0);
138137

139138
/**
140139
* Compute the sidelength of the smallest hypercube that encloses the
@@ -172,12 +171,12 @@ namespace nupic {
172171
* The sidelength of this hypercube. Returns -1.0 if a surface can't be
173172
* found (i.e. if upperBound is reached.)
174173
*/
175-
Real64 computeBinSidelength(
176-
const std::vector<std::vector<std::vector<Real64>>>& domainToPlaneByModule,
177-
Real64 readoutResolution,
178-
Real64 resultPrecision,
179-
Real64 upperBound = 2048.0,
180-
Real64 timeout = -1.0);
174+
double computeBinSidelength(
175+
const std::vector<std::vector<std::vector<double>>>& domainToPlaneByModule,
176+
double readoutResolution,
177+
double resultPrecision,
178+
double upperBound = 2048.0,
179+
double timeout = -1.0);
181180

182181
/**
183182
* Like computeBinSidelength, but it computes a hyperrectangle rather than
@@ -214,12 +213,12 @@ namespace nupic {
214213
* The dimensions of this hyperrectangle. Returns an empty vector if a
215214
* surface can't be found (i.e. if upperBound is reached.)
216215
*/
217-
std::vector<Real64> computeBinRectangle(
218-
const std::vector<std::vector<std::vector<Real64>>>& domainToPlaneByModule,
219-
Real64 readoutResolution,
220-
Real64 resultPrecision,
221-
Real64 upperBound = 2048.0,
222-
Real64 timeout = -1.0);
216+
std::vector<double> computeBinRectangle(
217+
const std::vector<std::vector<std::vector<double>>>& domainToPlaneByModule,
218+
double readoutResolution,
219+
double resultPrecision,
220+
double upperBound = 2048.0,
221+
double timeout = -1.0);
223222
}
224223
}
225224
}
+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// (C) Copyright Herve Bronnimann 2004.
2+
//
3+
// Distributed under the Boost Software License, Version 1.0. (See accompanying
4+
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5+
6+
/*
7+
Revision history:
8+
1 July 2004
9+
Split the code into two headers to lessen dependence on
10+
Boost.tuple. (Herve)
11+
26 June 2004
12+
Added the code for the boost minmax library. (Herve)
13+
*/
14+
15+
#ifndef BOOST_ALGORITHM_MINMAX_HPP
16+
#define BOOST_ALGORITHM_MINMAX_HPP
17+
18+
/* PROPOSED STANDARD EXTENSIONS:
19+
*
20+
* minmax(a, b)
21+
* Effect: (b<a) ? std::make_pair(b,a) : std::make_pair(a,b);
22+
*
23+
* minmax(a, b, comp)
24+
* Effect: comp(b,a) ? std::make_pair(b,a) : std::make_pair(a,b);
25+
*
26+
*/
27+
28+
#include <boost/tuple/tuple.hpp> // for using pairs with boost::cref
29+
#include <boost/ref.hpp>
30+
31+
namespace boost {
32+
33+
template <typename T>
34+
tuple< T const&, T const& >
35+
minmax(T const& a, T const& b) {
36+
return (b<a) ? make_tuple(cref(b),cref(a)) : make_tuple(cref(a),cref(b));
37+
}
38+
39+
template <typename T, class BinaryPredicate>
40+
tuple< T const&, T const& >
41+
minmax(T const& a, T const& b, BinaryPredicate comp) {
42+
return comp(b,a) ? make_tuple(cref(b),cref(a)) : make_tuple(cref(a),cref(b));
43+
}
44+
45+
} // namespace boost
46+
47+
#endif // BOOST_ALGORITHM_MINMAX_HPP

0 commit comments

Comments
 (0)