[80] | 1 | /*************************************************************************** |
---|
| 2 | * blitz/shapecheck.h Functions for checking conformability of arrays |
---|
| 3 | * |
---|
| 4 | * $Id: shapecheck.h,v 1.5 2003/12/11 03:44:22 julianc Exp $ |
---|
| 5 | * |
---|
| 6 | * Copyright (C) 1997-2001 Todd Veldhuizen <tveldhui@oonumerics.org> |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * Suggestions: blitz-dev@oonumerics.org |
---|
| 19 | * Bugs: blitz-bugs@oonumerics.org |
---|
| 20 | * |
---|
| 21 | * For more information, please see the Blitz++ Home Page: |
---|
| 22 | * http://oonumerics.org/blitz/ |
---|
| 23 | * |
---|
| 24 | ***************************************************************************/ |
---|
| 25 | |
---|
| 26 | #ifndef BZ_SHAPECHECK_H |
---|
| 27 | #define BZ_SHAPECHECK_H |
---|
| 28 | |
---|
| 29 | BZ_NAMESPACE(blitz) |
---|
| 30 | |
---|
| 31 | /* |
---|
| 32 | * The function areShapesConformable(A,B) checks that the shapes |
---|
| 33 | * A and B are conformable (i.e. the same size/geometry). Typically |
---|
| 34 | * the A and B parameters are of type TinyVector<int,N_rank> and represent |
---|
| 35 | * the extent of the arrays. It's possible that in the future jagged-edged |
---|
| 36 | * arrays will be supported, in which case shapes may be lists |
---|
| 37 | * of subdomains. |
---|
| 38 | */ |
---|
| 39 | |
---|
| 40 | template<typename T_shape1, typename T_shape2> |
---|
| 41 | inline bool areShapesConformable(const T_shape1&, const T_shape2&) |
---|
| 42 | { |
---|
| 43 | // If the shape objects are different types, this means |
---|
| 44 | // that the arrays are different ranks, or one is jagged |
---|
| 45 | // edged, etc. In this case the two arrays are not |
---|
| 46 | // conformable. |
---|
| 47 | return false; |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | template<typename T_shape> |
---|
| 51 | inline bool areShapesConformable(const T_shape& a, const T_shape& b) |
---|
| 52 | { |
---|
| 53 | // The shape objects are the same type, so compare them. |
---|
| 54 | |
---|
| 55 | // NEEDS_WORK-- once the "all" reduction is implemented, should |
---|
| 56 | // use it. |
---|
| 57 | // return all(a == b); |
---|
| 58 | |
---|
| 59 | for (unsigned i=0; i < a.length(); ++i) |
---|
| 60 | { |
---|
| 61 | if (a[i] != b[i]) |
---|
| 62 | { |
---|
| 63 | BZ_DEBUG_MESSAGE("Incompatible shapes detected: " << endl |
---|
| 64 | << a << endl << b << endl); |
---|
| 65 | return false; |
---|
| 66 | } |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | return true; |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | BZ_NAMESPACE_END |
---|
| 73 | |
---|
| 74 | #endif |
---|