I have poor reading comprehension when it comes to C++ but it looks like Boost.MultiArray caches the indexes. The technical term to use is "strides." A stride is how far one must move in memory to get to the next element in an array along a certain dimension. In addition to accessing elements in a Boost.MultiArray directly, there are also "Views"
- Code: Select all
array_type::array_view<3>::type myview =
myarray[ boost::indices[range(0,2)][range(1,3)][range(0,4,2)] ];
which allows you to specify a range for each dimension (aka slicing) and doesn't copy the underlying data. I'm assuming accessing a MultiArray directly uses a view too but I'm not sure.
The stride array is a data member of a View. See View.hpp
- Code: Select all
const index* strides() const {
return stride_list_.data();
}
On a related note, we've played with the idea of allowing a type specified for collection literals like:
# we're start the list with a Square,
# but want the list type to be more general:
t = [Square()] to List<of Shape>
I'm in favor of the "to" syntax to specify the exact type of a literal. There are tons of dictionary implementations and using the same literal syntax for all of them is desirable. I'm not clear as to how the "to" keyword differs from "as."
If I get some time next week I'll look into extending the MultiArray class. Methods I'm considering implementing are .reshape, .compareTo, .size (or .numElements). strides and shape will be get properties. Also a constructor that also takes in "data as T*".
One choice is to have an accompanying MultiArrayView class so that one can have multiple views of the same multi array like in Boost. A slice will return a MultiArrayView. Alternatively, there could be no MultiArrayView class, and then MultiArray would expose just a single view of itself, like in numpy.
There's lots of other less important methods on the
numpy site if you're interested.
Hopefully I understand all of this correctly.
Also, is there a particular reason for not implementing getHashCode
def getHashCode as int is override
throw InvalidOperationException()
or is it a TODO?
BTW, what is currently the best editor to use on a Mac?