annotate scripts/general/repmat.m @ 17338:1c89599167a6

maint: End m-files with 1 blank line. Simplifies automated grammarchecking script. * scripts/@ftp/ascii.m, scripts/@ftp/binary.m, scripts/@ftp/cd.m, scripts/@ftp/close.m, scripts/@ftp/delete.m, scripts/@ftp/dir.m, scripts/@ftp/display.m, scripts/@ftp/ftp.m, scripts/@ftp/loadobj.m, scripts/@ftp/mget.m, scripts/@ftp/mkdir.m, scripts/@ftp/mput.m, scripts/@ftp/rename.m, scripts/@ftp/rmdir.m, scripts/@ftp/saveobj.m, scripts/audio/lin2mu.m, scripts/audio/loadaudio.m, scripts/audio/mu2lin.m, scripts/audio/record.m, scripts/audio/saveaudio.m, scripts/audio/setaudio.m, scripts/deprecated/__error_text__.m, scripts/deprecated/cut.m, scripts/deprecated/error_text.m, scripts/deprecated/isstr.m, scripts/deprecated/polyderiv.m, scripts/deprecated/studentize.m, scripts/deprecated/sylvester_matrix.m, scripts/general/bicubic.m, scripts/general/celldisp.m, scripts/general/colon.m, scripts/general/cplxpair.m, scripts/general/del2.m, scripts/general/display.m, scripts/general/isdir.m, scripts/general/isequaln.m, scripts/general/loadobj.m, scripts/general/private/__isequal__.m, scripts/general/private/__splinen__.m, scripts/general/profexplore.m, scripts/general/quadgk.m, scripts/general/randi.m, scripts/general/repmat.m, scripts/general/saveobj.m, scripts/geometry/delaunay.m, scripts/help/__unimplemented__.m, scripts/help/doc_cache_create.m, scripts/help/get_first_help_sentence.m, scripts/help/help.m, scripts/help/print_usage.m, scripts/help/private/__additional_help_message__.m, scripts/help/private/__strip_html_tags__.m, scripts/help/type.m, scripts/image/imfinfo.m, scripts/image/imformats.m, scripts/image/imread.m, scripts/image/imwrite.m, scripts/image/private/__imfinfo__.m, scripts/image/private/__imread__.m, scripts/image/private/__imwrite__.m, scripts/image/private/imageIO.m, scripts/image/private/imwrite_filename.m, scripts/image/private/ind2x.m, scripts/io/beep.m, scripts/io/strread.m, scripts/io/textread.m, scripts/io/textscan.m, scripts/linear-algebra/krylov.m, scripts/linear-algebra/subspace.m, scripts/miscellaneous/bug_report.m, scripts/miscellaneous/bunzip2.m, scripts/miscellaneous/cast.m, scripts/miscellaneous/copyfile.m, scripts/miscellaneous/debug.m, scripts/miscellaneous/dir.m, scripts/miscellaneous/dump_prefs.m, scripts/miscellaneous/error_ids.m, scripts/miscellaneous/fileattrib.m, scripts/miscellaneous/gunzip.m, scripts/miscellaneous/isdeployed.m, scripts/miscellaneous/ismac.m, scripts/miscellaneous/mex.m, scripts/miscellaneous/mexext.m, scripts/miscellaneous/mkoctfile.m, scripts/miscellaneous/movefile.m, scripts/miscellaneous/namelengthmax.m, scripts/miscellaneous/news.m, scripts/miscellaneous/pack.m, scripts/miscellaneous/perl.m, scripts/miscellaneous/private/display_info_file.m, scripts/miscellaneous/python.m, scripts/miscellaneous/rmappdata.m, scripts/miscellaneous/run.m, scripts/miscellaneous/tar.m, scripts/miscellaneous/tempname.m, scripts/miscellaneous/untar.m, scripts/miscellaneous/unzip.m, scripts/miscellaneous/what.m, scripts/miscellaneous/zip.m, scripts/optimization/fminunc.m, scripts/optimization/fsolve.m, scripts/optimization/fzero.m, scripts/optimization/glpk.m, scripts/optimization/optimget.m, scripts/optimization/optimset.m, scripts/optimization/qp.m, scripts/optimization/sqp.m, scripts/path/pathdef.m, scripts/pkg/pkg.m, scripts/pkg/private/build.m, scripts/pkg/private/describe.m, scripts/pkg/private/dirempty.m, scripts/pkg/private/get_forge_download.m, scripts/pkg/private/get_forge_pkg.m, scripts/pkg/private/get_unsatisfied_deps.m, scripts/pkg/private/install.m, scripts/pkg/private/is_architecture_dependent.m, scripts/pkg/private/list_forge_packages.m, scripts/pkg/private/rebuild.m, scripts/pkg/private/shell.m, scripts/pkg/private/uninstall.m, scripts/plot/axes.m, scripts/plot/box.m, scripts/plot/closereq.m, scripts/plot/diffuse.m, scripts/plot/ezpolar.m, scripts/plot/findfigs.m, scripts/plot/gco.m, scripts/plot/guidata.m, scripts/plot/guihandles.m, scripts/plot/hdl2struct.m, scripts/plot/linkprop.m, scripts/plot/peaks.m, scripts/plot/print.m, scripts/plot/private/__add_datasource__.m, scripts/plot/private/__axis_label__.m, scripts/plot/private/__clabel__.m, scripts/plot/private/__color_str_rgb__.m, scripts/plot/private/__contour__.m, scripts/plot/private/__default_plot_options__.m, scripts/plot/private/__errcomm__.m, scripts/plot/private/__file_filter__.m, scripts/plot/private/__fltk_file_filter__.m, scripts/plot/private/__getlegenddata__.m, scripts/plot/private/__gnuplot_open_stream__.m, scripts/plot/private/__gnuplot_print__.m, scripts/plot/private/__go_draw_axes__.m, scripts/plot/private/__interp_cube__.m, scripts/plot/private/__is_function__.m, scripts/plot/private/__line__.m, scripts/plot/private/__marching_cube__.m, scripts/plot/private/__next_line_style__.m, scripts/plot/private/__patch__.m, scripts/plot/private/__pie__.m, scripts/plot/private/__pltopt__.m, scripts/plot/private/__quiver__.m, scripts/plot/private/__scatter__.m, scripts/plot/private/__stem__.m, scripts/plot/private/__uigetdir_fltk__.m, scripts/plot/private/__uigetfile_fltk__.m, scripts/plot/private/__uiobject_split_args__.m, scripts/plot/private/__uiputfile_fltk__.m, scripts/plot/refresh.m, scripts/plot/saveas.m, scripts/plot/shg.m, scripts/plot/specular.m, scripts/plot/sphere.m, scripts/plot/struct2hdl.m, scripts/plot/subplot.m, scripts/plot/uicontextmenu.m, scripts/plot/uicontrol.m, scripts/plot/uipanel.m, scripts/plot/uipushtool.m, scripts/plot/uiresume.m, scripts/plot/uitoggletool.m, scripts/plot/uitoolbar.m, scripts/plot/uiwait.m, scripts/plot/waitforbuttonpress.m, scripts/polynomial/pchip.m, scripts/polynomial/polyeig.m, scripts/polynomial/ppval.m, scripts/prefs/addpref.m, scripts/prefs/getpref.m, scripts/prefs/ispref.m, scripts/prefs/private/loadprefs.m, scripts/prefs/private/prefsfile.m, scripts/prefs/private/saveprefs.m, scripts/prefs/setpref.m, scripts/set/private/validargs.m, scripts/set/unique.m, scripts/signal/arch_fit.m, scripts/signal/arch_rnd.m, scripts/signal/arch_test.m, scripts/signal/arma_rnd.m, scripts/signal/durbinlevinson.m, scripts/signal/fractdiff.m, scripts/signal/freqz.m, scripts/signal/freqz_plot.m, scripts/signal/hurst.m, scripts/signal/periodogram.m, scripts/signal/private/rectangle_lw.m, scripts/signal/private/rectangle_sw.m, scripts/signal/private/triangle_sw.m, scripts/signal/spectral_adf.m, scripts/signal/spectral_xdf.m, scripts/signal/stft.m, scripts/signal/synthesis.m, scripts/signal/yulewalker.m, scripts/sparse/colperm.m, scripts/sparse/eigs.m, scripts/sparse/etreeplot.m, scripts/sparse/gmres.m, scripts/sparse/private/__sprand_impl__.m, scripts/sparse/spdiags.m, scripts/sparse/sprandn.m, scripts/specfun/bessel.m, scripts/specfun/betaln.m, scripts/specfun/expint.m, scripts/special-matrix/gallery.m, scripts/startup/__finish__.m, scripts/statistics/base/qqplot.m, scripts/statistics/distributions/tcdf.m, scripts/statistics/distributions/wienrnd.m, scripts/statistics/models/logistic_regression.m, scripts/statistics/models/private/logistic_regression_derivatives.m, scripts/statistics/models/private/logistic_regression_likelihood.m, scripts/statistics/tests/anova.m, scripts/statistics/tests/bartlett_test.m, scripts/statistics/tests/chisquare_test_homogeneity.m, scripts/statistics/tests/chisquare_test_independence.m, scripts/statistics/tests/cor_test.m, scripts/statistics/tests/f_test_regression.m, scripts/statistics/tests/hotelling_test.m, scripts/statistics/tests/hotelling_test_2.m, scripts/statistics/tests/kolmogorov_smirnov_test_2.m, scripts/statistics/tests/kruskal_wallis_test.m, scripts/statistics/tests/manova.m, scripts/statistics/tests/mcnemar_test.m, scripts/statistics/tests/prop_test_2.m, scripts/statistics/tests/run_test.m, scripts/statistics/tests/sign_test.m, scripts/statistics/tests/t_test.m, scripts/statistics/tests/t_test_2.m, scripts/statistics/tests/t_test_regression.m, scripts/statistics/tests/u_test.m, scripts/statistics/tests/var_test.m, scripts/statistics/tests/welch_test.m, scripts/statistics/tests/wilcoxon_test.m, scripts/statistics/tests/z_test.m, scripts/statistics/tests/z_test_2.m, scripts/strings/strcat.m, scripts/strings/strjoin.m, scripts/strings/strsplit.m, scripts/testfun/__have_feature__.m, scripts/testfun/__printf_assert__.m, scripts/testfun/__prog_output_assert__.m, scripts/testfun/__run_test_suite__.m, scripts/time/clock.m, scripts/time/datenum.m, scripts/ui/errordlg.m, scripts/ui/private/message_dialog.m: End m-files with 1 blank line.
author Rik <rik@octave.org>
date Wed, 28 Aug 2013 08:33:02 -0700
parents b81b9d079515
children d63878346099
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14138
72c96de7a403 maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents: 12639
diff changeset
1 ## Copyright (C) 2000-2012 Paul Kienzle
8390
49901b624316 optimize repmat for scalar & matrix case
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
2 ## Copyright (C) 2008 Jaroslav Hajek
3914
9eb96199e0f1 [project @ 2002-04-30 02:40:04 by jwe]
jwe
parents:
diff changeset
3 ##
9eb96199e0f1 [project @ 2002-04-30 02:40:04 by jwe]
jwe
parents:
diff changeset
4 ## This file is part of Octave.
9eb96199e0f1 [project @ 2002-04-30 02:40:04 by jwe]
jwe
parents:
diff changeset
5 ##
9eb96199e0f1 [project @ 2002-04-30 02:40:04 by jwe]
jwe
parents:
diff changeset
6 ## Octave is free software; you can redistribute it and/or modify it
9eb96199e0f1 [project @ 2002-04-30 02:40:04 by jwe]
jwe
parents:
diff changeset
7 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6987
diff changeset
8 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6987
diff changeset
9 ## your option) any later version.
3914
9eb96199e0f1 [project @ 2002-04-30 02:40:04 by jwe]
jwe
parents:
diff changeset
10 ##
9eb96199e0f1 [project @ 2002-04-30 02:40:04 by jwe]
jwe
parents:
diff changeset
11 ## Octave is distributed in the hope that it will be useful, but
9eb96199e0f1 [project @ 2002-04-30 02:40:04 by jwe]
jwe
parents:
diff changeset
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of
9eb96199e0f1 [project @ 2002-04-30 02:40:04 by jwe]
jwe
parents:
diff changeset
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9eb96199e0f1 [project @ 2002-04-30 02:40:04 by jwe]
jwe
parents:
diff changeset
14 ## General Public License for more details.
9eb96199e0f1 [project @ 2002-04-30 02:40:04 by jwe]
jwe
parents:
diff changeset
15 ##
9eb96199e0f1 [project @ 2002-04-30 02:40:04 by jwe]
jwe
parents:
diff changeset
16 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6987
diff changeset
17 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6987
diff changeset
18 ## <http://www.gnu.org/licenses/>.
3914
9eb96199e0f1 [project @ 2002-04-30 02:40:04 by jwe]
jwe
parents:
diff changeset
19
9eb96199e0f1 [project @ 2002-04-30 02:40:04 by jwe]
jwe
parents:
diff changeset
20 ## -*- texinfo -*-
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
21 ## @deftypefn {Function File} {} repmat (@var{A}, @var{m})
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
22 ## @deftypefnx {Function File} {} repmat (@var{A}, @var{m}, @var{n})
3914
9eb96199e0f1 [project @ 2002-04-30 02:40:04 by jwe]
jwe
parents:
diff changeset
23 ## @deftypefnx {Function File} {} repmat (@var{A}, [@var{m} @var{n}])
9041
853f96e8008f Cleanup documentation file matrix.texi
Rik <rdrider0-list@yahoo.com>
parents: 8970
diff changeset
24 ## @deftypefnx {Function File} {} repmat (@var{A}, [@var{m} @var{n} @var{p} @dots{}])
3914
9eb96199e0f1 [project @ 2002-04-30 02:40:04 by jwe]
jwe
parents:
diff changeset
25 ## Form a block matrix of size @var{m} by @var{n}, with a copy of matrix
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
26 ## @var{A} as each element. If @var{n} is not specified, form an
14366
b76f0740940e doc: Periodic grammar check of documentation.
Rik <octave@nomad.inbox5.com>
parents: 14363
diff changeset
27 ## @var{m} by @var{m} block matrix. For copying along more than two
14241
a52925666288 repmat.m: Fix incorrect docstring regarding higher dimensions
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
28 ## dimensions, specify the number of times to copy across each dimension
a52925666288 repmat.m: Fix incorrect docstring regarding higher dimensions
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
29 ## @var{m}, @var{n}, @var{p}, @dots{}, in a vector in the second argument.
10801
a40e32927b3a Improve documentation for new repelems function.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
30 ## @seealso{repelems}
3914
9eb96199e0f1 [project @ 2002-04-30 02:40:04 by jwe]
jwe
parents:
diff changeset
31 ## @end deftypefn
9eb96199e0f1 [project @ 2002-04-30 02:40:04 by jwe]
jwe
parents:
diff changeset
32
9eb96199e0f1 [project @ 2002-04-30 02:40:04 by jwe]
jwe
parents:
diff changeset
33 ## Author: Paul Kienzle <pkienzle@kienzle.powernet.co.uk>
9eb96199e0f1 [project @ 2002-04-30 02:40:04 by jwe]
jwe
parents:
diff changeset
34 ## Created: July 2000
9eb96199e0f1 [project @ 2002-04-30 02:40:04 by jwe]
jwe
parents:
diff changeset
35
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11318
diff changeset
36 function x = repmat (A, m, n)
3915
2f341412622f [project @ 2002-04-30 02:41:04 by jwe]
jwe
parents: 3914
diff changeset
37
3914
9eb96199e0f1 [project @ 2002-04-30 02:40:04 by jwe]
jwe
parents:
diff changeset
38 if (nargin < 2 || nargin > 3)
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5443
diff changeset
39 print_usage ();
3914
9eb96199e0f1 [project @ 2002-04-30 02:40:04 by jwe]
jwe
parents:
diff changeset
40 endif
9eb96199e0f1 [project @ 2002-04-30 02:40:04 by jwe]
jwe
parents:
diff changeset
41
4844
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4030
diff changeset
42 if (nargin == 3)
15436
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
43 if (! isempty (m) && isempty (n))
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
44 m = m(:).';
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
45 n = 1;
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
46 elseif (isempty (m) && ! isempty (n))
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
47 m = n(:).';
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
48 n = 1;
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
49 elseif (isempty (m) && isempty (n))
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
50 m = n = 1;
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
51 else
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
52 if (all (size (m) > 1))
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
53 m = m(:,1);
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
54 if (numel (m) < 3)
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
55 n = n(end);
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
56 else
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
57 n = [];
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
58 endif
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
59 endif
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
60 if (all (size (n) > 1))
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
61 n = n(:,1);
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
62 endif
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
63 m = m(:).';
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
64 n = n(:).';
4844
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4030
diff changeset
65 endif
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
66 else
15434
e1f59fd57756 repmat() should interpret empties as implying unit.
Ben Abbott <bpabbott@mac.com>
parents: 14366
diff changeset
67 if (isempty (m))
15436
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
68 m = n = 1;
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
69 elseif (isscalar (m))
3914
9eb96199e0f1 [project @ 2002-04-30 02:40:04 by jwe]
jwe
parents:
diff changeset
70 n = m;
15436
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
71 elseif (ndims (m) > 2)
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
72 error ("repmat: M has more than 2 dimensions")
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
73 elseif (all (size (m) > 1))
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
74 m = m(:,1).';
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
75 n = [];
3914
9eb96199e0f1 [project @ 2002-04-30 02:40:04 by jwe]
jwe
parents:
diff changeset
76 else
15436
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
77 m = m(:).';
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
78 n = [];
3914
9eb96199e0f1 [project @ 2002-04-30 02:40:04 by jwe]
jwe
parents:
diff changeset
79 endif
9eb96199e0f1 [project @ 2002-04-30 02:40:04 by jwe]
jwe
parents:
diff changeset
80 endif
15436
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
81 idx = [m, n];
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
82
8508
dee629f14bfa repmat.m: handle negative dimensions properly
John W. Eaton <jwe@octave.org>
parents: 8507
diff changeset
83 if (all (idx < 0))
15436
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
84 error ("repmat: invalid dimensions")
8508
dee629f14bfa repmat.m: handle negative dimensions properly
John W. Eaton <jwe@octave.org>
parents: 8507
diff changeset
85 else
dee629f14bfa repmat.m: handle negative dimensions properly
John W. Eaton <jwe@octave.org>
parents: 8507
diff changeset
86 idx = max (idx, 0);
dee629f14bfa repmat.m: handle negative dimensions properly
John W. Eaton <jwe@octave.org>
parents: 8507
diff changeset
87 endif
3914
9eb96199e0f1 [project @ 2002-04-30 02:40:04 by jwe]
jwe
parents:
diff changeset
88
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11318
diff changeset
89 if (numel (A) == 1)
8390
49901b624316 optimize repmat for scalar & matrix case
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
90 ## optimize the scalar fill case.
11318
d7ea780b036f repmat: handle special case of replicating scalar using index vector containing zeros
John W. Eaton <jwe@octave.org>
parents: 10801
diff changeset
91 if (any (idx == 0))
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11318
diff changeset
92 x = resize (A, idx);
11318
d7ea780b036f repmat: handle special case of replicating scalar using index vector containing zeros
John W. Eaton <jwe@octave.org>
parents: 10801
diff changeset
93 else
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11318
diff changeset
94 x(1:prod (idx)) = A;
11318
d7ea780b036f repmat: handle special case of replicating scalar using index vector containing zeros
John W. Eaton <jwe@octave.org>
parents: 10801
diff changeset
95 x = reshape (x, idx);
d7ea780b036f repmat: handle special case of replicating scalar using index vector containing zeros
John W. Eaton <jwe@octave.org>
parents: 10801
diff changeset
96 endif
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11318
diff changeset
97 elseif (ndims (A) == 2 && length (idx) < 3)
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11318
diff changeset
98 if (issparse (A))
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11318
diff changeset
99 x = kron (ones (idx), A);
4844
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4030
diff changeset
100 else
8390
49901b624316 optimize repmat for scalar & matrix case
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
101 ## indexing is now faster, so we use it rather than kron.
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11318
diff changeset
102 m = rows (A); n = columns (A);
8390
49901b624316 optimize repmat for scalar & matrix case
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
103 p = idx(1); q = idx(2);
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11318
diff changeset
104 x = reshape (A, m, 1, n, 1);
8390
49901b624316 optimize repmat for scalar & matrix case
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
105 x = x(:, ones (1, p), :, ones (1, q));
49901b624316 optimize repmat for scalar & matrix case
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
106 x = reshape (x, m*p, n*q);
4844
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4030
diff changeset
107 endif
3914
9eb96199e0f1 [project @ 2002-04-30 02:40:04 by jwe]
jwe
parents:
diff changeset
108 else
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11318
diff changeset
109 aidx = size (A);
8970
b37a6c27c23f simplify repmat
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
110 ## ensure matching size
b37a6c27c23f simplify repmat
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
111 idx(end+1:length (aidx)) = 1;
b37a6c27c23f simplify repmat
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
112 aidx(end+1:length (idx)) = 1;
b37a6c27c23f simplify repmat
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
113 ## create subscript array
b37a6c27c23f simplify repmat
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
114 cidx = cell (2, length (aidx));
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 8390
diff changeset
115 for i = 1:length (aidx)
8970
b37a6c27c23f simplify repmat
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
116 cidx{1,i} = ':';
b37a6c27c23f simplify repmat
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
117 cidx{2,i} = ones (1, idx (i));
4844
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4030
diff changeset
118 endfor
8970
b37a6c27c23f simplify repmat
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
119 aaidx = aidx;
17336
b81b9d079515 Use '##' for comments which stand alone on a line.
Rik <rik@octave.org>
parents: 15436
diff changeset
120 ## add singleton dims
8970
b37a6c27c23f simplify repmat
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
121 aaidx(2,:) = 1;
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11318
diff changeset
122 A = reshape (A, aaidx(:));
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11318
diff changeset
123 x = reshape (A (cidx{:}), idx .* aidx);
3914
9eb96199e0f1 [project @ 2002-04-30 02:40:04 by jwe]
jwe
parents:
diff changeset
124 endif
9eb96199e0f1 [project @ 2002-04-30 02:40:04 by jwe]
jwe
parents:
diff changeset
125
9eb96199e0f1 [project @ 2002-04-30 02:40:04 by jwe]
jwe
parents:
diff changeset
126 endfunction
6987
deb175b6e4a1 [project @ 2007-10-09 18:39:15 by jwe]
jwe
parents: 6046
diff changeset
127
17338
1c89599167a6 maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents: 17336
diff changeset
128
15436
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
129 # Tests for ML compatibility
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
130 %!shared x
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
131 %! x = [1 2 3];
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
132 %!assert (repmat (x, [3, 1]), repmat (x, 3, []))
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
133 %!assert (repmat (x, [3, 1]), repmat (x, [], 3))
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
134 %!assert (repmat (x, [1, 3]), repmat (x, [], [1, 3]))
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
135 %!assert (repmat (x, [1, 3]), repmat (x, [1, 3], []))
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
136 %!assert (repmat (x, [1 3]), repmat (x, [1 3; 3 3]))
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
137 %!assert (repmat (x, [1 1 2]), repmat (x, [1 1; 1 3; 2 1]))
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
138 %!assert (repmat (x, [1 3; 1 3], [1; 3]), repmat (x, [1 1 3]))
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
139 %!assert (repmat (x, [1 1], 4), repmat (x, [1 3; 1 3], [1; 4]))
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
140 %!assert (repmat (x, [1 1], 4), repmat (x, [1 3; 1 3], [1 2; 3 4]))
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
141 %!assert (repmat (x, [1 1], 4), repmat (x, [1 1 4]));
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
142 %!assert (repmat (x, [1 1], 4), repmat (x, 1, [1 4]));
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
143
6987
deb175b6e4a1 [project @ 2007-10-09 18:39:15 by jwe]
jwe
parents: 6046
diff changeset
144 # Test various methods of providing size parameters
deb175b6e4a1 [project @ 2007-10-09 18:39:15 by jwe]
jwe
parents: 6046
diff changeset
145 %!shared x
deb175b6e4a1 [project @ 2007-10-09 18:39:15 by jwe]
jwe
parents: 6046
diff changeset
146 %! x = [1 2;3 4];
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
147 %!assert (repmat (x, [1 1]), repmat (x, 1))
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
148 %!assert (repmat (x, [3 3]), repmat (x, 3))
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
149 %!assert (repmat (x, [1 1]), repmat (x, 1, 1))
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
150 %!assert (repmat (x, [1 3]), repmat (x, 1, 3))
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
151 %!assert (repmat (x, [3 1]), repmat (x, 3, 1))
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
152 %!assert (repmat (x, [3 3]), repmat (x, 3, 3))
6987
deb175b6e4a1 [project @ 2007-10-09 18:39:15 by jwe]
jwe
parents: 6046
diff changeset
153
deb175b6e4a1 [project @ 2007-10-09 18:39:15 by jwe]
jwe
parents: 6046
diff changeset
154 # Tests for numel==1 case:
deb175b6e4a1 [project @ 2007-10-09 18:39:15 by jwe]
jwe
parents: 6046
diff changeset
155 %!shared x, r
deb175b6e4a1 [project @ 2007-10-09 18:39:15 by jwe]
jwe
parents: 6046
diff changeset
156 %! x = [ 65 ];
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
157 %! r = kron (ones (2,2), x);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
158 %!assert (r, repmat (x, [2 2]))
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
159 %!assert (char (r), repmat (char (x), [2 2]))
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
160 %!assert (int8 (r), repmat (int8 (x), [2 2]))
6987
deb175b6e4a1 [project @ 2007-10-09 18:39:15 by jwe]
jwe
parents: 6046
diff changeset
161
deb175b6e4a1 [project @ 2007-10-09 18:39:15 by jwe]
jwe
parents: 6046
diff changeset
162 # Tests for ndims==2 case:
deb175b6e4a1 [project @ 2007-10-09 18:39:15 by jwe]
jwe
parents: 6046
diff changeset
163 %!shared x, r
deb175b6e4a1 [project @ 2007-10-09 18:39:15 by jwe]
jwe
parents: 6046
diff changeset
164 %! x = [ 65 66 67 ];
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
165 %! r = kron (ones (2,2), x);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
166 %!assert (r, repmat (x, [2 2]))
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
167 %!assert (char (r), repmat (char (x), [2 2]))
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
168 %!assert (int8 (r), repmat (int8 (x), [2 2]))
6987
deb175b6e4a1 [project @ 2007-10-09 18:39:15 by jwe]
jwe
parents: 6046
diff changeset
169
deb175b6e4a1 [project @ 2007-10-09 18:39:15 by jwe]
jwe
parents: 6046
diff changeset
170 # Tests for dim>2 case:
deb175b6e4a1 [project @ 2007-10-09 18:39:15 by jwe]
jwe
parents: 6046
diff changeset
171 %!shared x, r
deb175b6e4a1 [project @ 2007-10-09 18:39:15 by jwe]
jwe
parents: 6046
diff changeset
172 %! x = [ 65 66 67 ];
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
173 %! r = kron (ones (2,2), x);
6987
deb175b6e4a1 [project @ 2007-10-09 18:39:15 by jwe]
jwe
parents: 6046
diff changeset
174 %! r(:,:,2) = r(:,:,1);
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
175 %!assert (r, repmat (x, [2 2 2]))
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
176 %!assert (char (r), repmat (char (x), [2 2 2]))
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
177 %!assert (int8 (r), repmat (int8 (x), [2 2 2]))
6987
deb175b6e4a1 [project @ 2007-10-09 18:39:15 by jwe]
jwe
parents: 6046
diff changeset
178
deb175b6e4a1 [project @ 2007-10-09 18:39:15 by jwe]
jwe
parents: 6046
diff changeset
179 # Test that sparsity is kept
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
180 %!assert (sparse (4,4), repmat (sparse (2,2),[2 2]))
6987
deb175b6e4a1 [project @ 2007-10-09 18:39:15 by jwe]
jwe
parents: 6046
diff changeset
181
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
182 %!assert (size (repmat (".", -1, 1)), [0, 1])
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
183 %!assert (size (repmat (".", 1, -1)), [1, 0])
8508
dee629f14bfa repmat.m: handle negative dimensions properly
John W. Eaton <jwe@octave.org>
parents: 8507
diff changeset
184
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
185 %!assert (size (repmat (1, [1, 0])), [1, 0])
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
186 %!assert (size (repmat (1, [5, 0])), [5, 0])
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
187 %!assert (size (repmat (1, [0, 1])), [0, 1])
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
188 %!assert (size (repmat (1, [0, 5])), [0, 5])
11318
d7ea780b036f repmat: handle special case of replicating scalar using index vector containing zeros
John W. Eaton <jwe@octave.org>
parents: 10801
diff changeset
189
d7ea780b036f repmat: handle special case of replicating scalar using index vector containing zeros
John W. Eaton <jwe@octave.org>
parents: 10801
diff changeset
190 %!shared x
d7ea780b036f repmat: handle special case of replicating scalar using index vector containing zeros
John W. Eaton <jwe@octave.org>
parents: 10801
diff changeset
191 %! x = struct ("a", [], "b", []);
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
192 %!assert (size (repmat (x, [1, 0])), [1, 0])
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
193 %!assert (size (repmat (x, [5, 0])), [5, 0])
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
194 %!assert (size (repmat (x, [0, 1])), [0, 1])
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
195 %!assert (size (repmat (x, [0, 5])), [0, 5])
11318
d7ea780b036f repmat: handle special case of replicating scalar using index vector containing zeros
John W. Eaton <jwe@octave.org>
parents: 10801
diff changeset
196
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
197 %!assert (size (repmat ({1}, [1, 0])), [1, 0])
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
198 %!assert (size (repmat ({1}, [5, 0])), [5, 0])
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
199 %!assert (size (repmat ({1}, [0, 1])), [0, 1])
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
200 %!assert (size (repmat ({1}, [0, 5])), [0, 5])
11318
d7ea780b036f repmat: handle special case of replicating scalar using index vector containing zeros
John W. Eaton <jwe@octave.org>
parents: 10801
diff changeset
201
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
202 %!error (size (repmat (".", -1, -1)))
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
203