File: multi_array.hpp

package info (click to toggle)
siconos 4.4.0%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 78,364 kB
  • sloc: cpp: 160,975; ansic: 130,000; fortran: 33,051; python: 21,000; xml: 1,244; sh: 385; makefile: 318
file content (87 lines) | stat: -rw-r--r-- 2,352 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//
// Copyright (c) 2010 Rutger ter Borg
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//

#ifndef BOOST_NUMERIC_BINDINGS_BOOST_MULTI_ARRAY_HPP
#define BOOST_NUMERIC_BINDINGS_BOOST_MULTI_ARRAY_HPP

#include <boost/numeric/bindings/detail/adaptor.hpp>
#include <boost/multi_array.hpp>
#include <boost/mpl/range_c.hpp>

namespace boost {
namespace numeric {
namespace bindings {
namespace detail {

template< typename Map, typename AddressingIndex >
struct multi_array_dim_inserter {

    typedef typename mpl::insert<
        typename mpl::insert<
            Map,
            mpl::pair< tag::size_type< AddressingIndex::value >, std::ptrdiff_t >
        >::type,
        mpl::pair< tag::stride_type< AddressingIndex::value >, std::ptrdiff_t >
    >::type type;

};

template< typename T, std::size_t Dim, typename Alloc, typename Id, typename Enable >
struct adaptor< boost::multi_array<T,Dim,Alloc>, Id, Enable > {

    typedef typename copy_const< Id, T >::type value_type;
    typedef mpl::map<
        mpl::pair< tag::value_type, value_type >,
        mpl::pair< tag::entity, tag::tensor< Dim > >,
        mpl::pair< tag::data_order, tag::row_major >,
        mpl::pair< tag::data_structure, tag::linear_array >
    >  basic_map;
    typedef typename mpl::fold<
        mpl::range_c< std::size_t, 1, Dim+1 >,
        basic_map,
        multi_array_dim_inserter<
            mpl::_1,
            mpl::_2
        >
    >::type property_map;

    // Sizes are only reachable if Addressing Index <= Dim, otherwise
    // the default (1) will be returned
    static std::ptrdiff_t size1( const Id& id ) {
        return id.shape()[0];
    }

    static std::ptrdiff_t size2( const Id& id ) {
        return id.shape()[1];
    }

    static std::ptrdiff_t stride1( const Id& id ) {
        return id.strides()[0];
    }

    // Only reachable if dimension D is sufficient
    static std::ptrdiff_t stride2( const Id& id ) {
        return id.strides()[1];
    }

    static value_type* begin_value( Id& id ) {
        return id.data();
    }

    static value_type* end_value( Id& id ) {
        return id.data()+id.num_elements();
    }

};

} // namespace detail
} // namespace bindings
} // namespace numeric
} // namespace boost

#endif