Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion 3 .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[submodule "Boost.NumPy"]
path = Boost.NumPy
url = git://github.com/ndarray/Boost.NumPy.git
url = https://github.com/ChrislS/Boost.NumPy.git
branch = master
2 changes: 1 addition & 1 deletion 2 Boost.NumPy
5 changes: 2 additions & 3 deletions 5 README
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ an empty Boost.NumPy directory. Even if you don't plan to use
Boost.NumPy (which is required only if you want to build the
Boost.Python bindings for ndarray), it *is* necessary to checkout the
Boost.NumPy source (as parts of the build system is shared). So,
immediately after cloning ndarray, you'll need to run two commands:
immediately after cloning ndarray, you'll need to run:

git submodule init
git submodule update
git submodule update --init --recursive

From there, you'll be able to build ndarray and (optionally)
Boost.NumPy together just by running "scons" from the root of the
Expand Down
80 changes: 13 additions & 67 deletions 80 SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -8,59 +8,14 @@
# of the source distribution, or alternately available at:
# https://github.com/ndarray/ndarray
#

import os
import sys
sys.path.insert(0, os.path.abspath('Boost.NumPy'))
from SConsChecks import AddLibOptions, GetLibChecks

def CheckBoostTest(context):
source_file = """
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE config
#include "boost/test/unit_test.hpp"
#include "boost/test/results_reporter.hpp"
#include <iostream>

BOOST_AUTO_TEST_CASE(ConfigTestCase) {
boost::unit_test::results_reporter::set_stream(std::cout);
BOOST_CHECK(true);
}
"""
context.Message("Checking for Boost.Test Library...")
context.env.setupPaths(
prefix = GetOption("boost_prefix"),
include = GetOption("boost_include"),
lib = GetOption("boost_lib")
)
result = (
context.checkLibs([''], source_file) or
context.checkLibs(['boost_unit_test_framework'], source_file) or
context.checkLibs(['boost_unit_test_framework-mt'], source_file)
)
if not result:
context.Result(0)
print("Cannot build against Boost.Test.")
return False
result, output = context.TryRun(source_file, '.cpp')
if not result:
context.Result(0)
print("Cannot build against Boost.Test.")
return False
context.Result(1)
return True

def CheckSwig(context):
context.Message("Checking for SWIG...")
context.env.PrependUnique(SWIGFLAGS = ["-python", "-c++"])
result, swig_cmd = config.TryAction("which swig > $TARGET")
context.Result(result)
if result:
context.env.AppendUnique(SWIGPATH = ["#include"])
print("Using SWIG at", swig_cmd.strip())
return result

setupOptions, makeEnvironment, setupTargets, checks = SConscript("Boost.NumPy/SConscript")

checks["CheckBoostTest"] = CheckBoostTest
checks["CheckSwig"] = CheckSwig
setupOptions, makeEnvironment, setupTargets, checks, libs = SConscript("Boost.NumPy/SConscript")
libs.extend(['swig', 'eigen', 'boost.test', 'fftw', 'boost.preprocessor'])
checks = GetLibChecks(libs)

variables = setupOptions()

Expand All @@ -69,34 +24,22 @@ AddOption("--with-eigen", dest="eigen_prefix", type="string", nargs=1, action="s
help="prefix for Eigen libraries; should have an 'include' subdirectory")
AddOption("--with-eigen-include", dest="eigen_include", type="string", nargs=1, action="store",
metavar="DIR", help="location of Eigen header files")

AddOption("--with-fftw", dest="fftw_prefix", type="string", nargs=1, action="store",
metavar="DIR", default=os.environ.get("FFTW_DIR"),
help="prefix for FFTW libraries; should have 'include' and 'lib' subdirectories")
AddOption("--with-fftw-include", dest="fftw_include", type="string", nargs=1, action="store",
metavar="DIR", help="location of FFTW header files")
AddOption("--with-fftw-lib", dest="fftw_lib", type="string", nargs=1, action="store",
metavar="DIR", help="location of FFTW library")

building = not GetOption("help") and not GetOption("clean")

env = makeEnvironment(variables)
env.AppendUnique(CPPPATH=["#include"])

if building:
config = env.Configure(custom_tests=checks)
config.env.setupPaths(
prefix = GetOption("eigen_prefix"),
include = GetOption("eigen_include"),
lib = None
)
config.env.setupPaths(
prefix = GetOption("fftw_prefix"),
include = GetOption("fftw_include"),
lib = GetOption("fftw_lib")
)
haveEigen = config.CheckCXXHeader("Eigen/Core")
haveFFTW = config.CheckLibWithHeader("fftw3", "fftw3.h", "C", autoadd=False)
haveEigen = config.CheckEigen()
haveFFTW = config.CheckFFTW()
env = config.Finish()
else:
haveEigen = False
Expand All @@ -118,6 +61,9 @@ if building:
config = pyEnv.Configure(custom_tests=checks)
havePython = config.CheckPython() and config.CheckNumPy()
haveSwig = havePython and config.CheckSwig()
if haveSwig:
pyEnv.AppendUnique(SWIGPATH = ["#include"])
config.CheckBoostPP()
pyEnv = config.Finish()
else:
havePython = False
Expand All @@ -141,6 +87,7 @@ elif building:
print("Not building Boost.NumPy component.")

headers = SConscript(os.path.join("include", "SConscript"), exports="env")

prefix = Dir(GetOption("prefix")).abspath
install_headers = GetOption("install_headers")
if not install_headers:
Expand All @@ -149,5 +96,4 @@ for header in Flatten(headers):
relative = os.path.relpath(header.abspath, Dir("#include").abspath)
env.Alias("install", env.InstallAs(os.path.join(install_headers, relative), header))

if False:
tests = SConscript(os.path.join("tests", "SConscript"), exports=["env", "testEnv", "pyEnv", "bpEnv"])
tests = SConscript(os.path.join("tests", "SConscript"), exports=["env", "testEnv", "pyEnv", "bpEnv"])
2 changes: 1 addition & 1 deletion 2 include/ndarray/Array.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class Array : public ArrayBaseN< Array<T,N,C> > {
*
* This is implemented in initialization.h.
*/
explicit Array(int n1, int n2=1, int n3=1, int n4=1, int n5=1, int n6=1, int n7=1, int n8=1);
explicit Array(std::size_t n1, std::size_t n2=1, std::size_t n3=1, std::size_t n4=1, std::size_t n5=1, std::size_t n6=1, std::size_t n7=1, std::size_t n8=1);

/**
* @brief Non-converting shallow assignment.
Expand Down
57 changes: 41 additions & 16 deletions 57 include/ndarray/ArrayBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
* @brief Definitions for ArrayBase.
*/


#include <cstddef>

#include <boost/iterator/counting_iterator.hpp>

#include "ndarray/ExpressionBase.h"
Expand Down Expand Up @@ -60,7 +61,7 @@ class ArrayBase : public ExpressionBase<Derived> {
/// @brief Number of guaranteed row-major contiguous dimensions, counted from the end (boost::mpl::int_).
typedef typename Traits::RMC RMC;
/// @brief Vector type for N-dimensional indices.
typedef Vector<int,ND::value> Index;
typedef Vector<std::size_t,ND::value> Index;
/// @brief ArrayRef to a reverse-ordered contiguous array; the result of a call to transpose().
typedef ArrayRef<Element,ND::value,-RMC::value> FullTranspose;
/// @brief ArrayRef to a noncontiguous array; the result of a call to transpose(...).
Expand All @@ -71,33 +72,57 @@ class ArrayBase : public ExpressionBase<Derived> {
typedef ArrayRef<Element,ND::value,RMC::value> Deep;

/// @brief Return a single subarray.
Reference operator[](int n) const {
Reference operator[](std::size_t n) const {
return Traits::makeReference(
this->_data + n * this->template getStride<0>(),
this->_data + n * this->
#ifndef _MSC_VER
template
#endif
getStride<0>(),
this->_core
);
}

/// @brief Return a single element from the array.
Element & operator[](Index const & i) const {
return *(this->_data + this->_core->template computeOffset(i));
return *(this->_data + this->_core->
#ifndef _MSC_VER
template
#endif
computeOffset(i));
}

/// @brief Return an Iterator to the beginning of the array.
Iterator begin() const {
return Traits::makeIterator(
this->_data,
this->_core,
this->template getStride<0>()
this->
#ifndef _MSC_VER
template
#endif
getStride<0>()
);
}

/// @brief Return an Iterator to one past the end of the array.
Iterator end() const {
return Traits::makeIterator(
this->_data + this->template getSize<0>() * this->template getStride<0>(),
this->_data + this->
#ifndef _MSC_VER
template
#endif
getSize<0>() * this->
#ifndef _MSC_VER
template
#endif
getStride<0>(),
this->_core,
this->template getStride<0>()
this->
#ifndef _MSC_VER
template
#endif
getStride<0>()
);
}

Expand All @@ -111,12 +136,12 @@ class ArrayBase : public ExpressionBase<Derived> {
Manager::Ptr getManager() const { return this->_core->getManager(); }

/// @brief Return the size of a specific dimension.
template <int P> int getSize() const {
template <int P> size_t getSize() const {
return detail::getDimension<P>(*this->_core).getSize();
}

/// @brief Return the stride in a specific dimension.
template <int P> int getStride() const {
template <int P> std::size_t getStride() const {
return detail::getDimension<P>(*this->_core).getStride();
}

Expand All @@ -127,15 +152,15 @@ class ArrayBase : public ExpressionBase<Derived> {
Index getStrides() const { Index r; this->_core->fillStrides(r); return r; }

/// @brief Return the total number of elements in the array.
int getNumElements() const { return this->_core->getNumElements(); }
std::size_t getNumElements() const { return this->_core->getNumElements(); }

/// @brief Return a view of the array with the order of the dimensions reversed.
FullTranspose transpose() const {
Index shape = getShape();
Index strides = getStrides();
for (int n=0; n < ND::value / 2; ++n) {
std::swap(shape[n], shape[ND::value-n-1]);
std::swap(strides[n], strides[ND::value-n-1]);
for (std::size_t n=0; n < static_cast<std::size_t>(ND::value / 2); ++n) {
std::swap(shape[n], shape[static_cast<std::size_t>(ND::value-n-1)]);
std::swap(strides[n], strides[static_cast<std::size_t>(ND::value-n-1)]);
}
return FullTranspose(
getData(),
Expand All @@ -149,7 +174,7 @@ class ArrayBase : public ExpressionBase<Derived> {
Index newStrides;
Index oldShape = getShape();
Index oldStrides = getStrides();
for (int n=0; n < ND::value; ++n) {
for (std::size_t n=0; n < static_cast<std::size_t>(ND::value); ++n) {
newShape[n] = oldShape[order[n]];
newStrides[n] = oldStrides[order[n]];
}
Expand All @@ -159,7 +184,7 @@ class ArrayBase : public ExpressionBase<Derived> {
);
}

/// @brief Return a Array view to this.
/// @brief Return an Array view to this.
Shallow const shallow() const { return Shallow(this->getSelf()); }

/// @brief Return an ArrayRef view to this.
Expand Down
14 changes: 7 additions & 7 deletions 14 include/ndarray/ArrayBaseN.h.m4
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private:
*
* @brief Definition of ArrayBaseN, a dimension-specialized CRTP base class for Array and ArrayRef.
*/

#include <cstddef>
#include "ndarray/ArrayBase.h"

namespace ndarray {
Expand All @@ -75,12 +75,12 @@ private:
ArrayBaseN(Element * data, CorePtr const & core) : Super(data, core) {}
};

SPECIALIZE(1, `int n0', `n0')
SPECIALIZE(2, `int n0, int n1', `n0, n1')
SPECIALIZE(3, `int n0, int n1, int n2', `n0, n1, n2')
SPECIALIZE(4, `int n0, int n1, int n2, int n3', `n0, n1, n2, n3')
SPECIALIZE(5, `int n0, int n1, int n2, int n3, int n4', `n0, n1, n2, n3, n4')
SPECIALIZE(6, `int n0, int n1, int n2, int n3, int n4, int n5', `n0, n1, n2, n3, n4, n5')
SPECIALIZE(1, `std::size_t n0', `n0')
SPECIALIZE(2, `std::size_t n0, std::size_t n1', `n0, n1')
SPECIALIZE(3, `std::size_t n0, std::size_t n1, std::size_t n2', `n0, n1, n2')
SPECIALIZE(4, `std::size_t n0, std::size_t n1, std::size_t n2, std::size_t n3', `n0, n1, n2, n3')
SPECIALIZE(5, `std::size_t n0, std::size_t n1, std::size_t n2, std::size_t n3, std::size_t n4', `n0, n1, n2, n3, n4')
SPECIALIZE(6, `std::size_t n0, std::size_t n1, std::size_t n2, std::size_t n3, std::size_t n4, std::size_t n5', `n0, n1, n2, n3, n4, n5')

} // namespace ndarray

Expand Down
2 changes: 1 addition & 1 deletion 2 include/ndarray/ArrayRef.h.m4
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public:
*
* This is implemented in initialization.h.
*/
explicit ArrayRef(int n1, int n2=1, int n3=1, int n4=1, int n5=1, int n6=1, int n7=1, int n8=1);
explicit ArrayRef(std::size_t n1, std::size_t n2=1, std::size_t n3=1, std::size_t n4=1, std::size_t n5=1, std::size_t n6=1, std::size_t n7=1, std::size_t n8=1);

/**
* @brief Non-converting copy constructor.
Expand Down
10 changes: 6 additions & 4 deletions 10 include/ndarray/ArrayTraits.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* @brief Traits for Array.
*/

#include <cstddef>

#include "ndarray_fwd.h"
#include "ndarray/ExpressionTraits.h"
#include "ndarray/detail/Core.h"
Expand Down Expand Up @@ -54,7 +56,7 @@ struct ArrayTraits {
static Reference makeReference(Element * data, CorePtr const & core) {
return Reference(data, core);
}
static Iterator makeIterator(Element * data, CorePtr const & core, int stride) {
static Iterator makeIterator(Element * data, CorePtr const & core, std::ptrdiff_t stride) {
return Iterator(Reference(data, core), stride);
}
};
Expand All @@ -73,7 +75,7 @@ struct ArrayTraits<T,1,0> {
static Reference makeReference(Element * data, CorePtr const & core) {
return *data;
}
static Iterator makeIterator(Element * data, CorePtr const & core, int stride) {
static Iterator makeIterator(Element * data, CorePtr const & core, std::ptrdiff_t stride) {
return Iterator(data, stride);
}
};
Expand All @@ -92,7 +94,7 @@ struct ArrayTraits<T,1,1> {
static Reference makeReference(Element * data, CorePtr const & core) {
return *data;
}
static Iterator makeIterator(Element * data, CorePtr const & core, int stride) {
static Iterator makeIterator(Element * data, CorePtr const & core, std::ptrdiff_t stride) {
return data;
}
};
Expand All @@ -111,7 +113,7 @@ struct ArrayTraits<T,1,-1> {
static Reference makeReference(Element * data, CorePtr const & core) {
return *data;
}
static Iterator makeIterator(Element * data, CorePtr const & core, int stride) {
static Iterator makeIterator(Element * data, CorePtr const & core, std::ptrdiff_t stride) {
return data;
}
};
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.