blitz Version 0.10
|
00001 // -*- C++ -*- 00002 /*************************************************************************** 00003 * blitz/shapecheck.h Functions for checking conformability of arrays 00004 * 00005 * $Id: shapecheck.h,v 1.6 2011/03/25 22:41:16 julianc Exp $ 00006 * 00007 * Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org> 00008 * 00009 * This file is a part of Blitz. 00010 * 00011 * Blitz is free software: you can redistribute it and/or modify 00012 * it under the terms of the GNU Lesser General Public License 00013 * as published by the Free Software Foundation, either version 3 00014 * of the License, or (at your option) any later version. 00015 * 00016 * Blitz is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Lesser General Public License for more details. 00020 * 00021 * You should have received a copy of the GNU Lesser General Public 00022 * License along with Blitz. If not, see <http://www.gnu.org/licenses/>. 00023 * 00024 * Suggestions: blitz-devel@lists.sourceforge.net 00025 * Bugs: blitz-support@lists.sourceforge.net 00026 * 00027 * For more information, please see the Blitz++ Home Page: 00028 * https://sourceforge.net/projects/blitz/ 00029 * 00030 ***************************************************************************/ 00031 00032 #ifndef BZ_SHAPECHECK_H 00033 #define BZ_SHAPECHECK_H 00034 00035 BZ_NAMESPACE(blitz) 00036 00037 /* 00038 * The function areShapesConformable(A,B) checks that the shapes 00039 * A and B are conformable (i.e. the same size/geometry). Typically 00040 * the A and B parameters are of type TinyVector<int,N_rank> and represent 00041 * the extent of the arrays. It's possible that in the future jagged-edged 00042 * arrays will be supported, in which case shapes may be lists 00043 * of subdomains. 00044 */ 00045 00046 template<typename T_shape1, typename T_shape2> 00047 inline bool areShapesConformable(const T_shape1&, const T_shape2&) 00048 { 00049 // If the shape objects are different types, this means 00050 // that the arrays are different ranks, or one is jagged 00051 // edged, etc. In this case the two arrays are not 00052 // conformable. 00053 return false; 00054 } 00055 00056 template<typename T_shape> 00057 inline bool areShapesConformable(const T_shape& a, const T_shape& b) 00058 { 00059 // The shape objects are the same type, so compare them. 00060 00061 // NEEDS_WORK-- once the "all" reduction is implemented, should 00062 // use it. 00063 // return all(a == b); 00064 00065 for (unsigned i=0; i < a.length(); ++i) 00066 { 00067 if (a[i] != b[i]) 00068 { 00069 BZ_DEBUG_MESSAGE("Incompatible shapes detected: " << endl 00070 << a << endl << b << endl); 00071 return false; 00072 } 00073 } 00074 00075 return true; 00076 } 00077 00078 BZ_NAMESPACE_END 00079 00080 #endif