| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -112,7 +112,19 @@ namespace af | |||
| 112 | 112 | ||
| 113 | 113 | static void free(const void *); | |
| 114 | 114 | ||
| 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; | ||
| 116 | 128 | ||
| 117 | 129 | array as(af_dtype type) const; | |
| 118 | 130 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,7 +20,7 @@ AFAPI array convolve2(const array& signal, const array& filter, bool expand=true | |||
| 20 | 20 | ||
| 21 | 21 | AFAPI array convolve3(const array& signal, const array& filter, bool expand=true); | |
| 22 | 22 | ||
| 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); | ||
| 24 | 24 | ||
| 25 | 25 | } | |
| 26 | 26 | #endif | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -47,7 +47,9 @@ AFAPI array erode(const array& in, const array& mask); | |||
| 47 | 47 | ||
| 48 | 48 | AFAPI array erode3d(const array& in, const array& mask); | |
| 49 | 49 | ||
| 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); | ||
| 51 | 53 | ||
| 52 | 54 | } | |
| 53 | 55 | #endif | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,77 +14,6 @@ | |||
| 14 | 14 | ||
| 15 | 15 | namespace af | |
| 16 | 16 | { | |
| 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 | - } | ||
| 88 | 17 | ||
| 89 | 18 | /////////////////////////////////////////////////////////////////////////// | |
| 90 | 19 | // Operator +=, -=, *=, /= | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -246,140 +246,133 @@ namespace af | |||
| 246 | 246 | return info.isInteger(); | |
| 247 | 247 | } | |
| 248 | 248 | ||
| 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) | ||
| 298 | 250 | { | |
| 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]; | ||
| 302 | 252 | } | |
| 303 | 253 | ||
| 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 | ||
| 305 | 255 | { | |
| 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); | ||
| 307 | 261 | } | |
| 308 | - | ||
| 309 | - array randu(const dim_type d0, | ||
| 310 | - const dim_type d1, af_dtype ty) | ||
| 262 | + array array::row(size_t index) const | ||
| 311 | 263 | { | |
| 312 | - return randu(dim4(d0, d1), ty); | ||
| 264 | + af_seq idx = {index, index, 1}; | ||
| 265 | + return this->operator()(idx, span, span, span); | ||
| 313 | 266 | } | |
| 314 | 267 | ||
| 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 | ||
| 317 | 269 | { | |
| 318 | - return randu(dim4(d0, d1, d2), ty); | ||
| 270 | + af_seq idx = {index, index, 1}; | ||
| 271 | + return this->operator()(span, idx, span, span); | ||
| 319 | 272 | } | |
| 320 | 273 | ||
| 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 | ||
| 324 | 275 | { | |
| 325 | - return randu(dim4(d0, d1, d2, d3), ty); | ||
| 276 | + af_seq idx = {index, index, 1}; | ||
| 277 | + return this->operator()(span, span, idx, span); | ||
| 326 | 278 | } | |
| 327 | 279 | ||
| 328 | - array randn(const dim4 &dims, af_dtype type) | ||
| 280 | + array array::rows(size_t first, size_t last) const | ||
| 329 | 281 | { | |
| 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); | ||
| 333 | 284 | } | |
| 334 | 285 | ||
| 335 | - array randn(const dim_type d0, af_dtype ty) | ||
| 286 | + array array::cols(size_t first, size_t last) const | ||
| 336 | 287 | { | |
| 337 | - return randn(dim4(d0), ty); | ||
| 288 | + af_seq idx = {first, last, 1}; | ||
| 289 | + return this->operator()(span, idx, span, span); | ||
| 338 | 290 | } | |
| 339 | 291 | ||
| 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 | ||
| 342 | 293 | { | |
| 343 | - return randn(dim4(d0, d1), ty); | ||
| 294 | + af_seq idx = {first, last, 1}; | ||
| 295 | + return this->operator()(span, span, idx, span); | ||
| 344 | 296 | } | |
| 345 | 297 | ||
| 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 | ||
| 348 | 299 | { | |
| 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); | ||
| 350 | 303 | } | |
| 351 | 304 | ||
| 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) | ||
| 355 | 306 | { | |
| 356 | - return randn(dim4(d0, d1, d2, d3), ty); | ||
| 307 | + AF_THROW(af_weak_copy(&arr, in.get())); | ||
| 357 | 308 | } | |
| 358 | 309 | ||
| 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; | ||
| 362 | 331 | } | |
| 363 | 332 | ||
| 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) | ||
| 365 | 334 | { | |
| 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; | ||
| 371 | 346 | } | |
| 372 | 347 | ||
| 373 | - array array::as(af_dtype type) const | ||
| 348 | + array& array::operator=(const af_cdouble &value) | ||
| 374 | 349 | { | |
| 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; | ||
| 378 | 361 | } | |
| 379 | 362 | ||
| 380 | - array::array(const array& in) : arr(0), isRef(false) | ||
| 363 | + array& array::operator=(const af_cfloat &value) | ||
| 381 | 364 | { | |
| 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; | ||
| 383 | 376 | } | |
| 384 | 377 | ||
| 385 | 378 | #define INSTANTIATE(T) \ | |
@@ -402,33 +395,4 @@ namespace af | |||
| 402 | 395 | ||
| 403 | 396 | #undef INSTANTIATE | |
| 404 | 397 | ||
| 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 | - } | ||
| 434 | 398 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -34,7 +34,7 @@ array convolve3(const array& signal, const array& filter, bool expand) | |||
| 34 | 34 | return array(out); | |
| 35 | 35 | } | |
| 36 | 36 | ||
| 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) | ||
| 38 | 38 | { | |
| 39 | 39 | af_array out = 0; | |
| 40 | 40 | AF_THROW(af_convolve2_sep(&out, signal.get(), col_filter.get(), row_filter.get(), expand)); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments