ivl 679
|
00001 /* This file is part of the ivl C++ library <http://image.ntua.gr/ivl>. 00002 A C++ template library extending syntax towards mathematical notation. 00003 00004 Copyright (C) 2012 Yannis Avrithis <iavr@image.ntua.gr> 00005 Copyright (C) 2012 Kimon Kontosis <kimonas@image.ntua.gr> 00006 00007 ivl is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU Lesser General Public License 00009 version 3 as published by the Free Software Foundation. 00010 00011 Alternatively, you can redistribute it and/or modify it under the terms 00012 of the GNU General Public License version 2 as published by the Free 00013 Software Foundation. 00014 00015 ivl is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00018 See the GNU General Public License for more details. 00019 00020 You should have received a copy of the GNU General Public License 00021 and a copy of the GNU Lesser General Public License along 00022 with ivl. If not, see <http://www.gnu.org/licenses/>. */ 00023 00024 /* 00025 function [xx, yy] = meshgrid (x, y) 00026 00027 if (nargin == 1) 00028 y = x; 00029 endif 00030 if (nargin > 0 && nargin < 3) 00031 if (is_vector (x) && is_vector (y)) 00032 xx = ones(length(y), 1) * x(:).'; 00033 yy = y(:) * ones(1, length(x)); 00034 else 00035 error ("meshgrid: arguments must be vectors"); 00036 endif 00037 else 00038 usage ("[xx, yy] = meshgrid (x, y)"); 00039 endif 00040 00041 endfunction 00042 */ 00043 #ifndef IVL_MFUNC_MESHGRID 00044 #define IVL_MFUNC_MESHGRID 00045 00046 namespace ivl { 00047 00048 static __attribute__((unused)) 00049 struct meshgrid_impl : public ivl_func<meshgrid_impl> 00050 { 00051 template<class T, class S1, class S2, class I1, class I2> 00052 void operate(array_2d<T, S1>& xx, array_2d<T, S2>& yy, sep, 00053 const array<T, I1>& x, const array<T, I2>& y) 00054 { 00055 xx = mtimes(ones<T>(y.length(), 1), array_2d<T>(1, x.length(), x)); 00056 yy = mtimes(array_2d<T>(y.length(), 1, y), ones<T>(1, x.length())); 00057 } 00058 // TODO: make a global decision... 00059 template<class T, class T0, class T1, class T2, 00060 class S1, class S2, class I1, class I2> 00061 void operate(array_nd<T, S1>& xx, array_nd<T0, S2>& yy, sep, 00062 const array<T1, I1>& x, const array<T2, I2>& y) 00063 { 00064 xx = mtimes(ones<T>(y.length(), 1), array_2d<T>(1, x.length(), x)); 00065 yy = mtimes(array_2d<T>(y.length(), 1, y), ones<T>(1, x.length())); 00066 } 00067 00068 template<class T, class I1, class I2> 00069 ret<array_2d<T>, array_2d<T> > operator()( 00070 const array<T, I1>& x, const array<T, I2>& y) 00071 { 00072 ret<array_2d<T> > xx, yy; 00073 xx = mtimes(ones<T>(y.length(), 1), array_2d<T>(1, x.length(), x)); 00074 yy = mtimes(array_2d<T>(y.length(), 1, y), ones<T>(1, x.length())); 00075 return (_, xx, yy); 00076 } 00077 } meshgrid; 00078 00079 } /* namespace ivl */ 00080 00081 #endif // IVL_MFUNC_MESHGRID