FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Merge pull request #25 from arrayfire/cpp_tests · arrayfire/arrayfire@df77e75 · GitHub

Repository navigation

Commit df77e75

Browse files
committed
Merge pull request #25 from arrayfire/cpp_tests
Tests for the C++ wrapper
2 parents f3bf849 + 5146d67 commit df77e75

40 files changed

Lines changed: 1518 additions & 217 deletions

‎include/af/array.h‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,19 @@ namespace af
112112

113113
static void free(const void *);
114114

115-
array operator()(const af_seq& s0, const af_seq& s1=span, const af_seq& s2=span, const af_seq& s3=span);
115+
array operator()(const af_seq& s0, const af_seq& s1=span, const af_seq& s2=span, const af_seq& s3=span) const;
116+
117+
array row(size_t index) const;
118+
119+
array col(size_t index) const;
120+
121+
array slice(size_t index) const;
122+
123+
array rows(size_t first, size_t last) const;
124+
125+
array cols(size_t first, size_t last) const;
126+
127+
array slices(size_t first, size_t last) const;
116128

117129
array as(af_dtype type) const;
118130

‎include/af/convolve.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ AFAPI array convolve2(const array& signal, const array& filter, bool expand=true
2020

2121
AFAPI array convolve3(const array& signal, const array& filter, bool expand=true);
2222

23-
AFAPI array convolve2_sep(const array& signal, const array& col_filter, const array& row_filter, bool expand=true);
23+
AFAPI array convolve2(const array& signal, const array& col_filter, const array& row_filter, bool expand=true);
2424

2525
}
2626
#endif

‎include/af/image.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ AFAPI array erode(const array& in, const array& mask);
4747

4848
AFAPI array erode3d(const array& in, const array& mask);
4949

50-
AFAPI std::pair<array, array> gradient(const array& in);
50+
AFAPI void grad(array& rows, array& cols, const array& in);
51+
52+
AFAPI array regions(const array& in, af_connectivity_type connectivity=AF_CONNECTIVITY_4);
5153

5254
}
5355
#endif

‎src/array/arith.cpp‎

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -14,77 +14,6 @@
1414

1515
namespace af
1616
{
17-
///////////////////////////////////////////////////////////////////////////
18-
// Operator Overloading for array
19-
///////////////////////////////////////////////////////////////////////////
20-
21-
///////////////////////////////////////////////////////////////////////////
22-
// Operator =
23-
///////////////////////////////////////////////////////////////////////////
24-
array& array::operator=(const array &other)
25-
{
26-
if (isRef) {
27-
AF_THROW(af_assign(arr, other.numdims(), s, other.get()));
28-
isRef = false;
29-
} else {
30-
if (this->get() == other.get()) {
31-
return *this;
32-
}
33-
if(this->get() != 0) {
34-
AF_THROW(af_destroy_array(this->get()));
35-
}
36-
37-
af_array temp = 0;
38-
AF_THROW(af_weak_copy(&temp, other.get()));
39-
this->arr = temp;
40-
}
41-
return *this;
42-
}
43-
44-
array& array::operator=(const double &value)
45-
{
46-
if (isRef) {
47-
array cst = constant(value, this->dims(), this->type());
48-
AF_THROW(af_assign(arr, numdims(), s, cst.get()));
49-
isRef = false;
50-
} else {
51-
if(this->get() != 0) {
52-
AF_THROW(af_destroy_array(this->get()));
53-
}
54-
AF_THROW(af_constant(&arr, value, numdims(), dims().get(), type()));
55-
}
56-
return *this;
57-
}
58-
59-
array& array::operator=(const af_cdouble &value)
60-
{
61-
if (isRef) {
62-
array cst = constant(value, this->dims());
63-
AF_THROW(af_assign(arr, numdims(), s, cst.get()));
64-
isRef = false;
65-
} else {
66-
if(this->get() != 0) {
67-
AF_THROW(af_destroy_array(this->get()));
68-
}
69-
AF_THROW(af_constant_c64(&arr, (const void*)&value, numdims(), dims().get()));
70-
}
71-
return *this;
72-
}
73-
74-
array& array::operator=(const af_cfloat &value)
75-
{
76-
if (isRef) {
77-
array cst = constant(value, this->dims());
78-
AF_THROW(af_assign(arr, numdims(), s, cst.get()));
79-
isRef = false;
80-
} else {
81-
if(this->get() != 0) {
82-
AF_THROW(af_destroy_array(this->get()));
83-
}
84-
AF_THROW(af_constant_c32(&arr, (const void*)&value, numdims(), dims().get()));
85-
}
86-
return *this;
87-
}
8817

8918
///////////////////////////////////////////////////////////////////////////
9019
// Operator +=, -=, *=, /=

‎src/array/array.cpp‎

Lines changed: 89 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -246,140 +246,133 @@ namespace af
246246
return info.isInteger();
247247
}
248248

249-
array constant(double val, const dim4 &dims, af_dtype type)
250-
{
251-
af_array res;
252-
AF_THROW(af_constant(&res, val, dims.ndims(), dims.get(), type));
253-
return array(res);
254-
}
255-
256-
array constant(af_cdouble val, const dim4 &dims)
257-
{
258-
double val_[] = {real(val), imag(val)};
259-
af_array res;
260-
AF_THROW(af_constant_c64(&res, val_, dims.ndims(), dims.get()));
261-
return array(res);
262-
}
263-
264-
array constant(af_cfloat val, const dim4 &dims)
265-
{
266-
float val_[] = {real(val), imag(val)};
267-
af_array res;
268-
AF_THROW(af_constant_c32(&res, val_, dims.ndims(), dims.get()));
269-
return array(res);
270-
}
271-
272-
array constant(double val, const dim_type d0, af_dtype ty)
273-
{
274-
return constant(val, dim4(d0), ty);
275-
}
276-
277-
array constant(double val, const dim_type d0,
278-
const dim_type d1, af_dtype ty)
279-
{
280-
return constant(val, dim4(d0, d1), ty);
281-
}
282-
283-
array constant(double val, const dim_type d0,
284-
const dim_type d1, const dim_type d2, af_dtype ty)
285-
{
286-
return constant(val, dim4(d0, d1, d2), ty);
287-
}
288-
289-
array constant(double val, const dim_type d0,
290-
const dim_type d1, const dim_type d2,
291-
const dim_type d3, af_dtype ty)
292-
{
293-
return constant(val, dim4(d0, d1, d2, d3), ty);
294-
}
295-
296-
297-
array randu(const dim4 &dims, af_dtype type)
249+
array::array(af_array in, af_seq *seqs) : arr(in), isRef(true)
298250
{
299-
af_array res;
300-
AF_THROW(af_randu(&res, dims.ndims(), dims.get(), type));
301-
return array(res);
251+
for(int i=0; i<4; ++i) s[i] = seqs[i];
302252
}
303253

304-
array randu(const dim_type d0, af_dtype ty)
254+
array array::operator()(const af_seq& s0, const af_seq& s1, const af_seq& s2, const af_seq& s3) const
305255
{
306-
return randu(dim4(d0), ty);
256+
af_array out = 0;
257+
af_seq indices[] = {s0, s1, s2, s3};
258+
//FIXME: check if this->s has same dimensions as numdims
259+
AF_THROW(af_weak_copy(&out, this->get()));
260+
return array(out, indices);
307261
}
308-
309-
array randu(const dim_type d0,
310-
const dim_type d1, af_dtype ty)
262+
array array::row(size_t index) const
311263
{
312-
return randu(dim4(d0, d1), ty);
264+
af_seq idx = {index, index, 1};
265+
return this->operator()(idx, span, span, span);
313266
}
314267

315-
array randu(const dim_type d0,
316-
const dim_type d1, const dim_type d2, af_dtype ty)
268+
array array::col(size_t index) const
317269
{
318-
return randu(dim4(d0, d1, d2), ty);
270+
af_seq idx = {index, index, 1};
271+
return this->operator()(span, idx, span, span);
319272
}
320273

321-
array randu(const dim_type d0,
322-
const dim_type d1, const dim_type d2,
323-
const dim_type d3, af_dtype ty)
274+
array array::slice(size_t index) const
324275
{
325-
return randu(dim4(d0, d1, d2, d3), ty);
276+
af_seq idx = {index, index, 1};
277+
return this->operator()(span, span, idx, span);
326278
}
327279

328-
array randn(const dim4 &dims, af_dtype type)
280+
array array::rows(size_t first, size_t last) const
329281
{
330-
af_array res;
331-
AF_THROW(af_randn(&res, dims.ndims(), dims.get(), type));
332-
return array(res);
282+
af_seq idx = {first, last, 1};
283+
return this->operator()(idx, span, span, span);
333284
}
334285

335-
array randn(const dim_type d0, af_dtype ty)
286+
array array::cols(size_t first, size_t last) const
336287
{
337-
return randn(dim4(d0), ty);
288+
af_seq idx = {first, last, 1};
289+
return this->operator()(span, idx, span, span);
338290
}
339291

340-
array randn(const dim_type d0,
341-
const dim_type d1, af_dtype ty)
292+
array array::slices(size_t first, size_t last) const
342293
{
343-
return randn(dim4(d0, d1), ty);
294+
af_seq idx = {first, last, 1};
295+
return this->operator()(span, span, idx, span);
344296
}
345297

346-
array randn(const dim_type d0,
347-
const dim_type d1, const dim_type d2, af_dtype ty)
298+
array array::as(af_dtype type) const
348299
{
349-
return randn(dim4(d0, d1, d2), ty);
300+
af_array out;
301+
AF_THROW(af_cast(&out, this->get(), type));
302+
return array(out);
350303
}
351304

352-
array randn(const dim_type d0,
353-
const dim_type d1, const dim_type d2,
354-
const dim_type d3, af_dtype ty)
305+
array::array(const array& in) : arr(0), isRef(false)
355306
{
356-
return randn(dim4(d0, d1, d2, d3), ty);
307+
AF_THROW(af_weak_copy(&arr, in.get()));
357308
}
358309

359-
array::array(af_array in, af_seq *seqs) : arr(in), isRef(true)
360-
{
361-
for(int i=0; i<4; ++i) s[i] = seqs[i];
310+
///////////////////////////////////////////////////////////////////////////
311+
// Operator =
312+
///////////////////////////////////////////////////////////////////////////
313+
array& array::operator=(const array &other)
314+
{
315+
if (isRef) {
316+
AF_THROW(af_assign(arr, numdims(), s, other.get()));
317+
isRef = false;
318+
} else {
319+
if (this->get() == other.get()) {
320+
return *this;
321+
}
322+
if(this->get() != 0) {
323+
AF_THROW(af_destroy_array(this->get()));
324+
}
325+
326+
af_array temp = 0;
327+
AF_THROW(af_weak_copy(&temp, other.get()));
328+
this->arr = temp;
329+
}
330+
return *this;
362331
}
363332

364-
array array::operator()(const af_seq& s0, const af_seq& s1, const af_seq& s2, const af_seq& s3)
333+
array& array::operator=(const double &value)
365334
{
366-
af_array out = 0;
367-
af_seq indices[] = {s0, s1, s2, s3};
368-
//FIXME: check if this->s has same dimensions as numdims
369-
AF_THROW(af_weak_copy(&out, this->get()));
370-
return array(out, indices);
335+
if (isRef) {
336+
array cst = constant(value, this->dims(), this->type());
337+
AF_THROW(af_assign(arr, numdims(), s, cst.get()));
338+
isRef = false;
339+
} else {
340+
if(this->get() != 0) {
341+
AF_THROW(af_destroy_array(this->get()));
342+
}
343+
AF_THROW(af_constant(&arr, value, numdims(), dims().get(), type()));
344+
}
345+
return *this;
371346
}
372347

373-
array array::as(af_dtype type) const
348+
array& array::operator=(const af_cdouble &value)
374349
{
375-
af_array out;
376-
AF_THROW(af_cast(&out, this->get(), type));
377-
return array(out);
350+
if (isRef) {
351+
array cst = constant(value, this->dims());
352+
AF_THROW(af_assign(arr, numdims(), s, cst.get()));
353+
isRef = false;
354+
} else {
355+
if(this->get() != 0) {
356+
AF_THROW(af_destroy_array(this->get()));
357+
}
358+
AF_THROW(af_constant_c64(&arr, (const void*)&value, numdims(), dims().get()));
359+
}
360+
return *this;
378361
}
379362

380-
array::array(const array& in) : arr(0), isRef(false)
363+
array& array::operator=(const af_cfloat &value)
381364
{
382-
AF_THROW(af_weak_copy(&arr, in.get()));
365+
if (isRef) {
366+
array cst = constant(value, this->dims());
367+
AF_THROW(af_assign(arr, numdims(), s, cst.get()));
368+
isRef = false;
369+
} else {
370+
if(this->get() != 0) {
371+
AF_THROW(af_destroy_array(this->get()));
372+
}
373+
AF_THROW(af_constant_c32(&arr, (const void*)&value, numdims(), dims().get()));
374+
}
375+
return *this;
383376
}
384377

385378
#define INSTANTIATE(T) \
@@ -402,33 +395,4 @@ namespace af
402395

403396
#undef INSTANTIATE
404397

405-
array iota(const dim4 &dims, const unsigned rep, af_dtype ty)
406-
{
407-
af_array out;
408-
AF_THROW(af_iota(&out, dims.ndims(), dims.get(), rep, ty));
409-
return array(out);
410-
}
411-
412-
array iota(const dim_type d0, const unsigned rep, af_dtype ty)
413-
{
414-
return iota(dim4(d0), rep, ty);
415-
}
416-
417-
array iota(const dim_type d0, const dim_type d1,
418-
const unsigned rep, af_dtype ty)
419-
{
420-
return iota(dim4(d0, d1), rep, ty);
421-
}
422-
423-
array iota(const dim_type d0, const dim_type d1, const dim_type d2,
424-
const unsigned rep, af_dtype ty)
425-
{
426-
return iota(dim4(d0, d1, d2), rep, ty);
427-
}
428-
429-
array iota(const dim_type d0, const dim_type d1, const dim_type d2,
430-
const dim_type d3, const unsigned rep, af_dtype ty)
431-
{
432-
return iota(dim4(d0, d1, d2, d3), rep, ty);
433-
}
434398
}

‎src/array/convolve.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ array convolve3(const array& signal, const array& filter, bool expand)
3434
return array(out);
3535
}
3636

37-
array convolve2_sep(const array& signal, const array& col_filter, const array& row_filter, bool expand)
37+
array convolve2(const array& signal, const array& col_filter, const array& row_filter, bool expand)
3838
{
3939
af_array out = 0;
4040
AF_THROW(af_convolve2_sep(&out, signal.get(), col_filter.get(), row_filter.get(), expand));

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL