-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathstrided.cpp
114 lines (93 loc) · 2.42 KB
/
strided.cpp
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
//
// Copyright (c) 2010 by CodeSourcery
// Copyright (c) 2013 Stefan Seefeld
// All rights reserved.
//
// This file is part of OpenVSIP. It is made available under the
// license contained in the accompanying LICENSE.GPL file.
/// Description:
/// VSIPL++ Library: Unit tests for Strided.
#include <iostream>
#include <cassert>
#include <vsip/initfin.hpp>
#include <vsip/support.hpp>
#include <ovxx/strided.hpp>
#include <ovxx/length.hpp>
#include <ovxx/domain_utils.hpp>
#include "test.hpp"
using namespace ovxx;
template <typename T>
inline T
identity(Length<1> /*extent*/,
Index<1> idx,
int k)
{
return static_cast<T>(k*idx[0] + 1);
}
template <typename T>
inline T
identity(Length<2> extent,
Index<2> idx,
int k)
{
Index<2> offset;
index_type i = (idx[0]+offset[0])*extent[1] + (idx[1]+offset[1]);
return static_cast<T>(k*i+1);
}
template <dimension_type Dim,
typename Block>
void
fill_block(Block& blk, int k)
{
typedef typename Block::value_type value_type;
Length<Dim> ex = extent<Dim>(blk);
for (Index<Dim> idx; valid(ex,idx); next(ex, idx))
{
put(blk, idx, identity<value_type>(ex, idx, k));
}
}
template <dimension_type Dim,
typename Block>
void
check_block(Block& blk, int k)
{
typedef typename Block::value_type value_type;
Length<Dim> ex = extent<Dim>(blk);
for (Index<Dim> idx; valid(ex,idx); next(ex, idx))
{
test_assert(equal( get(blk, idx),
identity<value_type>(ex, idx, k)));
}
}
template <dimension_type Dim,
typename Block>
void
test_block(Domain<Dim> const& dom)
{
Block block(dom);
fill_block<Dim>(block, 5);
check_block<Dim>(block, 5);
}
template <typename T, pack_type P, storage_format_type C>
void
test_wrap()
{
Domain<1> dom1(15);
test_block<1, Strided<1, T, Layout<1, row1_type, P, C> > >(dom1);
Domain<2> dom2(15, 17);
test_block<2, Strided<2, T, Layout<2, row2_type, P, C> > >(dom2);
test_block<2, Strided<2, T, Layout<2, col2_type, P, C> > >(dom2);
}
int
main(int argc, char **argv)
{
vsipl library(argc, argv);
test_wrap<float, dense, array>();
test_wrap<float, aligned_16, array>();
test_wrap<complex<float>, dense, array>();
test_wrap<complex<float>, aligned_16, array>();
test_wrap<complex<float>, dense, interleaved_complex>();
test_wrap<complex<float>, aligned_16, interleaved_complex>();
test_wrap<complex<float>, dense, split_complex>();
test_wrap<complex<float>, aligned_16, split_complex>();
}