Mercurial > octave
changeset 23710:279a6bd429f4
rename a few more build scripts for consistency
* test/mk-bc-overloads-tst.sh: Rename from
test/build-bc-overload-tests.sh.
* test/mk-conv-tst.sh: Rename from test/build-conv-tests.sh.
* test/mk-sparse-tst.sh: Rename from test/build-sparse-tests.sh.
test/mk_bc_overloads_expected.m: Rename from
test/build_bc_overloads_expected.m.
* test/module.mk: Update.
* libinterp/mk-build-env-features.sh: Rename from
libinterp/build-env-features.sh.
* libinterp/module.mk: Update.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 27 Jun 2017 18:30:12 -0400 |
parents | 3b68aeeabc40 |
children | 5a97aafb12a9 |
files | libinterp/build-env-features.sh libinterp/mk-build-env-features.sh libinterp/module.mk test/build-bc-overload-tests.sh test/build-conv-tests.sh test/build-sparse-tests.sh test/build_bc_overloads_expected.m test/mk-bc-overloads-tst.sh test/mk-conv-tst.sh test/mk-sparse-tst.sh test/mk_bc_overloads_expected.m test/module.mk |
diffstat | 12 files changed, 1786 insertions(+), 1786 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/build-env-features.sh Tue Jun 27 15:10:58 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,80 +0,0 @@ -#! /bin/sh - -## Copyright (C) 2013-2017 John W. Eaton -## -## This file is part of Octave. -## -## Octave is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 3 of the License, or -## (at your option) any later version. -## -## Octave is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with Octave; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. - -## Attempt to get traditional sort behavior based on byte values. -LC_ALL=C -export LC_ALL - -set -e - -AWK=${AWK:-awk} - -cat << EOF -// DO NOT EDIT! Generated automatically from $conffile by Make." - -#if defined (HAVE_CONFIG_H) -# include "config.h" -#endif - -#include "build-env.h" -#include "ov.h" - -namespace octave -{ - namespace build_env - { - octave_scalar_map - features (void) - { - static bool initialized = false; - - static octave_scalar_map m; - - if (! initialized) - { - static octave_value ov_true = (true); - static octave_value ov_false = (false); - -EOF - -for conffile in "$@"; do - $AWK \ - '/# *define *(OCTAVE_HAVE|HAVE)_/ { - sub (/# *define */, "", $0); - sub (/(OCTAVE_HAVE|HAVE)_/, "", $1) - printf (" m.assign (\"%s\", ov_true);\n", $1); - } - /\/\* #undef (OCTAVE_HAVE|HAVE)_/ { - sub (/(OCTAVE_HAVE|HAVE)_/, "", $3); - printf (" m.assign (\"%s\", ov_false);\n", $3); - } { - }' $conffile -done | sort - -cat << EOF - - initialized = true; - } - - return m; - } - }; -}; -EOF
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libinterp/mk-build-env-features.sh Tue Jun 27 18:30:12 2017 -0400 @@ -0,0 +1,80 @@ +#! /bin/sh + +## Copyright (C) 2013-2017 John W. Eaton +## +## This file is part of Octave. +## +## Octave is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or +## (at your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## Attempt to get traditional sort behavior based on byte values. +LC_ALL=C +export LC_ALL + +set -e + +AWK=${AWK:-awk} + +cat << EOF +// DO NOT EDIT! Generated automatically from $conffile by Make." + +#if defined (HAVE_CONFIG_H) +# include "config.h" +#endif + +#include "build-env.h" +#include "ov.h" + +namespace octave +{ + namespace build_env + { + octave_scalar_map + features (void) + { + static bool initialized = false; + + static octave_scalar_map m; + + if (! initialized) + { + static octave_value ov_true = (true); + static octave_value ov_false = (false); + +EOF + +for conffile in "$@"; do + $AWK \ + '/# *define *(OCTAVE_HAVE|HAVE)_/ { + sub (/# *define */, "", $0); + sub (/(OCTAVE_HAVE|HAVE)_/, "", $1) + printf (" m.assign (\"%s\", ov_true);\n", $1); + } + /\/\* #undef (OCTAVE_HAVE|HAVE)_/ { + sub (/(OCTAVE_HAVE|HAVE)_/, "", $3); + printf (" m.assign (\"%s\", ov_false);\n", $3); + } { + }' $conffile +done | sort + +cat << EOF + + initialized = true; + } + + return m; + } + }; +}; +EOF
--- a/libinterp/module.mk Tue Jun 27 15:10:58 2017 -0400 +++ b/libinterp/module.mk Tue Jun 27 18:30:12 2017 -0400 @@ -81,9 +81,9 @@ %canon_reldir%_EXTRA_DIST += \ %reldir%/DOCSTRINGS \ %reldir%/build-env.in.cc \ - %reldir%/build-env-features.sh \ %reldir%/deprecated-config.h \ %reldir%/liboctinterp-build-info.in.cc \ + %reldir%/mk-build-env-features.sh \ %reldir%/mk-builtins.pl \ %reldir%/mk-doc.pl \ %reldir%/mk-pkg-add.sh \ @@ -235,9 +235,9 @@ %reldir%/build-env.cc: %reldir%/build-env.in.cc build-aux/subst-config-vals.sh | %reldir%/$(octave_dirstamp) $(AM_V_GEN)$(call simple-filter-rule,build-aux/subst-config-vals.sh) -%reldir%/build-env-features.cc: config.h %reldir%/build-env-features.sh | %reldir%/$(octave_dirstamp) +%reldir%/build-env-features.cc: config.h %reldir%/mk-build-env-features.sh | %reldir%/$(octave_dirstamp) $(AM_V_GEN)rm -f $@-t && \ - $(SHELL) $(srcdir)/%reldir%/build-env-features.sh $< > $@-t && \ + $(SHELL) $(srcdir)/%reldir%/mk-build-env-features.sh $< > $@-t && \ mv $@-t $@ %reldir%/version.h: %reldir%/version.in.h %reldir%/mk-version-h.sh | %reldir%/$(octave_dirstamp)
--- a/test/build-bc-overload-tests.sh Tue Jun 27 15:10:58 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,141 +0,0 @@ -#! /bin/sh - -# Copyright (C) 2010-2017 VZLU Prague -# -# This file is part of Octave. -# -# Octave is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. -# -# Octave is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Octave; see the file COPYING. If not, see -# <http://www.gnu.org/licenses/>. - -CLASSES=" - double - single - char - logical - int8 - int16 - int32 - int64 - uint8 - uint16 - uint32 - uint64 - struct - cell - function_handle -" - -if [ $# -eq 2 ]; then - output_dir="$1" - shift - case "$1" in - --list-files) - echo $output_dir/tbcover.m - echo $output_dir/bc-overloads.tst - for class in $CLASSES; do - echo $output_dir/@$class/tbcover.m - done - exit - ;; - --list-dirs) - for class in $CLASSES; do - echo $output_dir/@$class - done - exit - ;; - --list-classes) - echo $CLASSES - exit - ;; - *) - expected_results_file="$1" - ;; - esac -else - echo "usage: build-bc-overload-tests.sh output_dir option" 1>&2 - exit 1 -fi - -for class in $CLASSES; do - DIR="$output_dir/@$class" - test -d $DIR || mkdir $DIR || { echo "error: could not create $DIR"; exit; } - cat > $DIR/tbcover.m << EOF -% !!! DO NOT EDIT !!! -% generated automatically by build-bc-overload-tests.sh -function s = tbcover (x, y) - s = '$class'; -EOF -done - -cat > $output_dir/tbcover.m << EOF -% !!! DO NOT EDIT !!! -% generated automatically by build-bc-overload-tests.sh -function s = tbcover (x, y) - s = 'none'; -EOF - -if test "$1" = "overloads_only" ; then - exit -fi - -cat > $output_dir/bc-overloads.tst << EOF -## !!! DO NOT EDIT !!! -## THIS IS AN AUTOMATICALLY GENERATED FILE -## modify build-bc-overload-tests.sh to generate the tests you need. - -%!shared ex -%! ex.double = 1; -%! ex.single = single (1); -%! ex.logical = true; -%! ex.char = 'char'; -%! ex.int8 = int8 (1); -%! ex.int16 = int16 (1); -%! ex.int32 = int32 (1); -%! ex.int64 = int64 (1); -%! ex.uint8 = uint8 (1); -%! ex.uint16 = uint16 (1); -%! ex.uint32 = uint32 (1); -%! ex.uint64 = uint64 (1); -%! ex.cell = {}; -%! ex.struct = struct (); -%! ex.function_handle = @numel; - -EOF - -cat $expected_results_file | \ -while read cl1 cl2 clr ; do - cat >> $output_dir/bc-overloads.tst << EOF -%% Name call -%!assert (tbcover (ex.$cl1, ex.$cl2), "$clr") -%% Handle call -%!assert ((@tbcover) (ex.$cl1, ex.$cl2), "$clr") - -EOF -done - -cat >> $output_dir/bc-overloads.tst << EOF -%%test handles through cellfun -%!test -%! f = fieldnames (ex); -%! n = numel (f); -%! s = c1 = c2 = cell (n); -%! for i = 1:n -%! for j = 1:n -%! c1{i,j} = ex.(f{i}); -%! c2{i,j} = ex.(f{j}); -%! s{i,j} = tbcover (ex.(f{i}), ex.(f{j})); -%! endfor -%! endfor -%! assert (cellfun (@tbcover, c1, c2, "uniformoutput", false), s); -EOF
--- a/test/build-conv-tests.sh Tue Jun 27 15:10:58 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,195 +0,0 @@ -#!/bin/sh - -## Copyright (C) 2016-2017 John W. Eaton -## -## This file is part of Octave. -## -## Octave is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 3 of the License, or -## (at your option) any later version. -## -## Octave is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with Octave; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. - -cat <<EOF -## !!! DO NOT EDIT !!! -## THIS IS AN AUTOMATICALLY GENERATED FILE -## modify build-conv-tests.sh to generate the tests you need. - - -%!shared r,dq,sq,b,bm,dm,cdm,fdm,fcdm,pm,sm,sbm,scm,s,m,cs,cm,fs,fm,fcs,fcm,i8s,i16s,i32s,i64s,i8m,i16m,i32m,i64m,ui8s,ui16s,ui32s,ui64s,ui8m,ui16m,ui32m,ui64m -%!test -%! r = 1:5; -%! dq = "foo"; -%! sq = 'bar'; -%! b = true; -%! bm = rand (5) > 0.5; -%! dm = eye (5); -%! cdm = eye (5) * i; -%! fdm = eye (5, "single"); -%! fcdm = eye (5, "single") * single (i); -%! [~, ~, pm] = qr (rand (5)); -%! sm = sprand (5, 5, 0.1); -%! sbm = sparse (rand (5) > 0.5); -%! scm = sprand (5, 5, 0.1) * i; -%! s = rand (); -%! m = rand (5); -%! cs = 13 * i; -%! cm = rand (5) * i; -%! fs = rand ("single"); -%! fm = rand (5, "single"); -%! fcs = rand ("single") * single (i); -%! fcm = rand (5, "single") * single (i); -%! i8s = int8 (rand () * 10); -%! i16s = int16 (rand () * 10); -%! i32s = int32 (rand () * 10); -%! i64s = int64 (rand () * 10); -%! i8m = int8 (rand (5) * 10); -%! i16m = int16 (rand (5) * 10); -%! i32m = int32 (rand (5) * 10); -%! i64m = int64 (rand (5) * 10); -%! ui8s = uint8 (rand () * 10); -%! ui16s = uint16 (rand () * 10); -%! ui32s = uint32 (rand () * 10); -%! ui64s = uint64 (rand () * 10); -%! ui8m = uint8 (rand (5) * 10); -%! ui16m = uint16 (rand (5) * 10); -%! ui32m = uint32 (rand (5) * 10); -%! ui64m = uint64 (rand (5) * 10); -%! -%!assert (typeinfo (r), "range") -%!assert (typeinfo (dq), "string") -%!assert (typeinfo (sq), "sq_string") -%!assert (typeinfo (b), "bool") -%!assert (typeinfo (bm), "bool matrix") -%!assert (typeinfo (dm), "diagonal matrix") -%!assert (typeinfo (cdm), "complex diagonal matrix") -%!assert (typeinfo (fdm), "float diagonal matrix") -%!assert (typeinfo (fcdm), "float complex diagonal matrix") -%!assert (typeinfo (pm), "permutation matrix") -%!assert (typeinfo (sm), "sparse matrix") -%!assert (typeinfo (sbm), "sparse bool matrix") -%!assert (typeinfo (scm), "sparse complex matrix") -%!assert (typeinfo (s), "scalar") -%!assert (typeinfo (m), "matrix") -%!assert (typeinfo (cs), "complex scalar") -%!assert (typeinfo (cm), "complex matrix") -%!assert (typeinfo (fs), "float scalar") -%!assert (typeinfo (fm), "float matrix") -%!assert (typeinfo (fcs), "float complex scalar") -%!assert (typeinfo (fcm), "float complex matrix") -%!assert (typeinfo (i8s), "int8 scalar") -%!assert (typeinfo (i16s), "int16 scalar") -%!assert (typeinfo (i32s), "int32 scalar") -%!assert (typeinfo (i64s), "int64 scalar") -%!assert (typeinfo (i8m), "int8 matrix") -%!assert (typeinfo (i16m), "int16 matrix") -%!assert (typeinfo (i32m), "int32 matrix") -%!assert (typeinfo (i64m), "int64 matrix") -%!assert (typeinfo (ui8s), "uint8 scalar") -%!assert (typeinfo (ui16s), "uint16 scalar") -%!assert (typeinfo (ui32s), "uint32 scalar") -%!assert (typeinfo (ui64s), "uint64 scalar") -%!assert (typeinfo (ui8m), "uint8 matrix") -%!assert (typeinfo (ui16m), "uint16 matrix") -%!assert (typeinfo (ui32m), "uint32 matrix") -%!assert (typeinfo (ui64m), "uint64 matrix") -%! -%!assert (class (r), "double") -%!assert (class (dq), "char") -%!assert (class (sq), "char") -%!assert (class (b), "logical") -%!assert (class (bm), "logical") -%!assert (class (dm), "double") -%!assert (class (cdm), "double") -%!assert (class (fdm), "single") -%!assert (class (fcdm), "single") -%!assert (class (pm), "double") -%!assert (class (sm), "double") -%!assert (class (sbm), "logical") -%!assert (class (scm), "double") -%!assert (class (s), "double") -%!assert (class (m), "double") -%!assert (class (cs), "double") -%!assert (class (cm), "double") -%!assert (class (fs), "single") -%!assert (class (fm), "single") -%!assert (class (fcs), "single") -%!assert (class (fcm), "single") -%!assert (class (i8s), "int8") -%!assert (class (i16s), "int16") -%!assert (class (i32s), "int32") -%!assert (class (i64s), "int64") -%!assert (class (i8m), "int8") -%!assert (class (i16m), "int16") -%!assert (class (i32m), "int32") -%!assert (class (i64m), "int64") -%!assert (class (ui8s), "uint8") -%!assert (class (ui16s), "uint16") -%!assert (class (ui32s), "uint32") -%!assert (class (ui64s), "uint64") -%!assert (class (ui8m), "uint8") -%!assert (class (ui16m), "uint16") -%!assert (class (ui32m), "uint32") -%!assert (class (ui64m), "uint64") -EOF - -## There are no single or integer sparse matrices. - -sparse_vars="sm sbm scm" -sparse_conversions="double logical" - -for c in $sparse_conversions; do - echo "" - for v in $sparse_vars; do - echo "%!assert (class ($c ($v)), \"$c\")" - done -done - -char_vars="dq sq" -bool_vars="b bm" -real_vars="r s m fs fm dm fdm pm" -complex_vars="cs cm fcs fcm cdm fcdm" -signed_int_vars="i8s i16s i32s i64s i8m i16m i32m i64m" -unsigned_int_vars="ui8s ui16s ui32s ui64s ui8m ui16m ui32m ui64m" -int_vars="$signed_int_vars $unsigned_int_vars" - -bool_conversions="logical" -float_conversions="double single" -int_conversions="int8 int16 int32 int64 uint8 uint16 uint32 uint64" -all_conversions="$bool_conversions $float_conversions $int_conversions" - -## Strings can't be converted to logical. - -for v in $char_vars; do - echo "" - for c in $float_conversions $int_conversions; do - echo "%!assert (class ($c ($v)), \"$c\")" - done -done - -## Octave doesn't have complex integers. - -for v in $complex_vars; do - echo "" - for c in $bool_conversions $float_conversions; do - echo "%!assert (class ($c ($v)), \"$c\")" - done -done - -## Logical and real-value numeric values should be convertible to any -## double, single, logical or integer type. - -for v in $bool_vars $real_vars $int_vars; do - echo "" - for c in $all_conversions; do - echo "%!assert (class ($c ($v)), \"$c\")" - done -done
--- a/test/build-sparse-tests.sh Tue Jun 27 15:10:58 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1319 +0,0 @@ -#! /bin/sh - -# Copyright (C) 2006-2017 David Bateman -# -# This file is part of Octave. -# -# Octave is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. -# -# Octave is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Octave; see the file COPYING. If not, see -# <http://www.gnu.org/licenses/>. - -# Some tests are commented out because they are known to be broken! -# Search for "# fails" - -# ./build-sparse-tests.sh preset -# creates sparse.tst with preset tests. -# Use "test sparse.tst" from octave to run the tests. -# -# ./build-sparse-tests.sh random -# Creates sprandom.tst with randomly generated matrices. -# Use "test sprandom.tst" from octave to run the tests. - -# build-sparse-tests.sh generates tests for real and complex sparse matrices. -# Also, we want to run both fixed tests with known outputs (quick tests) -# and longer tests with unknown outputs (thorough tests). This requires -# two sets of tests -- one which uses preset matrices and another which -# uses randomly generated matrices. -# -# The tests are mostly identical for each case but the code is different, -# so it is important that the tests be run on all cases. Because our test -# harness doesn't have support for looping or macros (it is only needed -# for new data types), but sh does, we use sh to generate inline versions of -# the tests for each case. -# -# Our 'macros' use shared variables as parameters. This allows us to -# for example define A complex and include all the unary ops tests, -# then set A=real(A) and include all the unary ops tests. Thus the -# same tests work for real and complex. For binary tests it is even -# more complicated because we want full X sparse, sparse X full and -# sparse X sparse tested. -# -# We use the following macros: -# -# gen_section -# place a separator in the test file -# gen_function -# define the function definion -# helper gen_specific -# specific tests such as error handling and null input -# helper gen_eat_zeros -# make sure sparse-scalar ops which generate 0 work -# gen_specific_tests -# specific and eat zeros tests -# helper gen_ordering_tests -# ordered comparison operators for real valued tests -# helper gen_sparsesparse_ordering_tests -# ordered comparison operators for real valued sparse-sparse tests -# helper gen_elementop_tests -# element-wise matrix binary operators, including scalar-matrix ops. -# horizontal/vertical concatenation are here as well. -# helper gen_sparsesparse_elementop_tests -# element-wise matrix binary operators, for sparse-sparse ops. -# horizontal/vertical concatenation are here as well. -# helper gen_divop_tests -# left and right matrix division operators of rectangular matrices. -# Needs QR solvers -# helper gen_square_divop_tests -# left and right matrix division operators of square matrices. -# helper gen_matrixop_tests -# rectangular matrix binary operators: * -# helper gen_matrixdiag_tests -# Tests extract of diag and creation of diagonal matrices using -# diag and spdiags functions -# helper gen_matrixreshape_tests -# Test the reshape function on sparse matrices -# helper print_mapper_test -# sub-helper function of gen_mapper_tests to print individual tests -# helper gen_mapper_tests -# Tests all of the one argument mapper functions. There are a few -# specific tests that abs, real and imag return real values. -# helper gen_unaryop_tests -# functions and operators which transform a single matrix -# helper gen_save_tests -# Tests the load/save functionality for ascii/binary and hdf5 formats -# gen_scalar_tests -# element ops for real and complex scalar and sparse -# gen_rectangular_tests -# unary, element, and matrix tests for a and full/sparse b -# gen_square_tests -# operations which require square matrices: lu, inv, \ -# A square non-singular matrix is defined from the rectangular -# inputs A and B. -# gen_assembly_tests -# test for sparse constructors with 'sum' vs. 'unique' -# gen_select_tests -# indexing and assignment tests -# gen_solver_tests -# Tests the solve function with triangular/banded, etc matrices - -case $1 in - random) preset=false ;; - preset) preset=true ;; - '') preset=true ;; - *) echo "build-sparse-tests.sh random|preset" && exit 1 ;; -esac - -# create initial file -cat <<EOF -## !!! DO NOT EDIT !!! -## THIS IS AN AUTOMATICALLY GENERATED FILE -## modify build-sparse-tests.sh to generate the tests you need. -EOF - - -# define all functions - - -# ======================================================= -# Section separator - -gen_section() { -cat <<EOF - -# ============================================================== - -EOF -} - - -# ======================================================= -# Specific preset tests - -# ======================================================= -# If a sparse operation yields zeros, then those elements -# of the returned sparse matrix should be eaten. -gen_eat_zeros() { -cat <<EOF -%% Make sure newly introduced zeros get eaten -%!assert (nnz (sparse ([bf,bf,1]).^realmax), 1) -%!assert (nnz (sparse ([1,bf,bf]).^realmax), 1) -%!assert (nnz (sparse ([bf,bf,bf]).^realmax), 0) - -%!assert (nnz (sparse ([bf;bf;1]).^realmax), 1) -%!assert (nnz (sparse ([1;bf;bf]).^realmax), 1) -%!assert (nnz (sparse ([0.5;bf;bf]).^realmax), 0) - -%!assert (nnz (sparse ([bf,bf,1])*realmin), 1) -%!assert (nnz (sparse ([1,bf,bf])*realmin), 1) -%!assert (nnz (sparse ([bf,bf,bf])*realmin), 0) - -%!assert (nnz (sparse ([bf;bf;1])*realmin), 1) -%!assert (nnz (sparse ([1;bf;bf])*realmin), 1) -%!assert (nnz (sparse ([bf;bf;bf])*realmin), 0) - -EOF -} - -gen_specific() { -cat <<EOF - -%!test # segfault test from edd@debian.org -%! n = 510; -%! sparse (kron ((1:n)', ones (n,1)), kron (ones (n,1), (1:n)'), ones (n)); - -%% segfault tests from Fabian@isas-berlin.de -%% Note that the last four do not fail, but rather give a warning -%% of a singular matrix, which is consistent with the full matrix -%% behavior. They are therefore disabled. -%!testif HAVE_UMFPACK -%! assert (inv (sparse ([1,1;1,1+i])), sparse ([1-1i,1i;1i,-1i]), 10*eps); -%#!error inv ( sparse ([1,1;1,1] ) ); -%#!error inv ( sparse ([0,0;0,1] ) ); -%#!error inv ( sparse ([0,0;0,1+i]) ); -%#!error inv ( sparse ([0,0;0,0] ) ); - -%% error handling in constructor -%!error sparse (1,[2,3],[1,2,3]) -%!error sparse ([1,1],[1,1],[1,2],3,3,"invalid") -%!error sparse ([1,3],[1,-4],[3,5],2,2) -%!error sparse ([1,3],[1,-4],[3,5i],2,2) -%!error sparse (-1,-1,1) -EOF -} - - -gen_specific_tests() { - gen_section - gen_specific - gen_section - echo '%!shared bf' - echo '%!test bf=realmin;' - gen_eat_zeros - echo '%!test bf=realmin+realmin*1i;' - gen_eat_zeros - cat <<EOF -%!assert (nnz (sparse ([-1,realmin,realmin]).^1.5), 1) -%!assert (nnz (sparse ([-1,realmin,realmin,1]).^1.5), 2) - -## Make sure scalar v==0 doesn't confuse matters -%!assert (nnz (sparse (1,1,0)), 0) -%!assert (nnz (sparse (eye (3))*0), 0) -%!assert (nnz (sparse (eye (3))-sparse (eye (3))), 0) - -%!test -%! wdbz = warning ("query", "Octave:divide-by-zero"); -%! warning ("off", "Octave:divide-by-zero"); -%! assert (full (sparse (eye (3))/0), full (eye (3)/0)); -%! warning (wdbz.state, "Octave:divide-by-zero"); - -EOF -} - - -# ======================================================= -# Main function definition - -gen_function() { - if $preset; then - cat <<EOF -## -## test_sparse -## -## run preset sparse tests. All should pass. -function [passes, tests] = test_sparse - disp ("writing test output to sptest.log"); - test ("sparse.tst", "normal", "sptest.log"); -endfunction - -EOF - else - cat <<EOF -## -## test_sprandom -## -## total_passes=0; total_tests=0; -## for i=1:10 -## [passes,tests] = sprandomtest; -## total_passes += passes; -## total_tests += tests; -## end -## The test log is appended to sprandomtest.log -function [passes,total] = test_sprandom - warning ("untested --- fix the source in build-sparse-tests.sh"); - disp ("appending test output to sprandomtest.log"); - fid = fopen ("sprandomtest.log", "at"); - test ("sprandom.tst", "normal", fid); - ##[passes, total] = test ("sprandomtest", "normal", fid); - fclose (fid); -endfunction - -EOF - fi - -} - - -# ======================================================= -# matrix ops - -# test ordered comparisons: uses as,af,bs,bf -gen_ordering_tests() { - cat <<EOF -%% real values can be ordered (uses as,af) -%!assert (as<=bf, sparse (af<=bf)) -%!assert (bf<=as, sparse (bf<=af)) - -%!assert (as>=bf, sparse (af>=bf)) -%!assert (bf>=as, sparse (bf>=af)) - -%!assert (as<bf, sparse (af<bf)) -%!assert (bf<as, sparse (bf<af)) - -%!assert (as>bf, sparse (af>bf)) -%!assert (bf>as, sparse (bf>af)) - -EOF -} - -gen_sparsesparse_ordering_tests() { - cat <<EOF -%!assert (as<=bs, sparse (af<=bf)) -%!assert (as>=bs, sparse (af>=bf)) -%!assert (as<bs, sparse (af<bf)) -%!assert (as>bs, sparse (af>bf)) -EOF -} - -# test element-wise binary operations: uses as,af,bs,bf,scalar -gen_elementop_tests() { - cat <<EOF -%% Elementwise binary tests (uses as,af,bs,bf,scalar) -%!assert (as==bs, sparse (af==bf)) -%!assert (bf==as, sparse (bf==af)) - -%!assert (as!=bf, sparse (af!=bf)) -%!assert (bf!=as, sparse (bf!=af)) - -%!assert (as+bf, af+bf) -%!assert (bf+as, bf+af) - -%!assert (as-bf, af-bf) -%!assert (bf-as, bf-af) - -%!assert (as.*bf, sparse (af.*bf)) -%!assert (bf.*as, sparse (bf.*af)) - -%!assert (as./bf, sparse (af./bf), 100*eps) -%!assert (bf.\as, sparse (bf.\af), 100*eps) - -%!test -%! sv = as.^bf; -%! fv = af.^bf; -%! idx = find (af!=0); -%! assert (sv(:)(idx), sparse (fv(:)(idx)), 100*eps); - -EOF -} - -gen_sparsesparse_elementop_tests() { - cat <<EOF -%!assert (as==bs, sparse (af==bf)) -%!assert (as!=bs, sparse (af!=bf)) -%!assert (as+bs, sparse (af+bf)) -%!assert (as-bs, sparse (af-bf)) -%!assert (as.*bs, sparse (af.*bf)) -%!xtest assert (as./bs, sparse (af./bf), 100*eps) -%!test -%! sv = as.^bs; -%! fv = af.^bf; -%! idx = find (af!=0); -%! assert(sv(:)(idx), sparse (fv(:)(idx)), 100*eps); - -EOF -} - -# test matrix-matrix left and right division: uses as,af,bs,bf -gen_divop_tests() { - cat <<EOF -%% Matrix-matrix operators (uses af,as,bs,bf) -%!assert (as/bf, af/bf, 100*eps) -%!assert (af/bs, af/bf, 100*eps) -%!assert (as/bs, sparse (af/bf), 100*eps) -%!assert (bs\af', bf\af', 100*eps) -%!assert (bf\as', bf\af', 100*eps) -%!assert (bs\as', sparse (bf\af'), 100*eps) - -EOF -} - -# test matrix-matrix left and right division: uses as,af,bs,bf -gen_square_divop_tests() { - cat <<EOF -%% Matrix-matrix operators (uses af,as,bs,bf) -%!assert (as/bf, af/bf, 100*eps) -%!assert (af/bs, af/bf, 100*eps) -%!assert (as/bs, sparse (af/bf), 100*eps) -%!assert (bs\af', bf\af', 100*eps) -%!assert (bf\as', bf\af', 100*eps) -%!assert (bs\as', sparse (bf\af'), 100*eps) - -EOF -} - -# test matrix-matrix operations: uses as,af,bs,bf -gen_matrixop_tests() { - cat <<EOF -%% Matrix-matrix operators (uses af,as,bs,bf) -%!assert (as*bf', af*bf') -%!assert (af*bs', af*bf') -%!assert (as*bs', sparse (af*bf')) - -EOF -} - -# test diagonal operations -gen_matrixdiag_tests() { - cat <<EOF -%% Matrix diagonal tests (uses af,as,bf,bs) -%!assert (diag (as), sparse (diag (af))) -%!assert (diag (bs), sparse (diag (bf))) -%!assert (diag (as,1), sparse (diag (af,1))) -%!assert (diag (bs,1), sparse (diag (bf,1))) -%!assert (diag (as,-1), sparse (diag (af,-1))) -%!assert (diag (bs,-1), sparse (diag (bf,-1))) -%!assert (diag (as(:)), sparse (diag (af(:)))) -%!assert (diag (as(:),1), sparse (diag (af(:),1))) -%!assert (diag (as(:),-1), sparse (diag (af(:),-1))) -%!assert (diag (as(:)'), sparse (diag (af(:)'))) -%!assert (diag (as(:)',1), sparse (diag (af(:)',1))) -%!assert (diag (as(:)',-1), sparse (diag (af(:)',-1))) -%!assert (spdiags (as,[0,1]), [diag(af,0), diag(af,1)]) -%!test -%! [tb,tc] = spdiags (as); -%! assert (spdiags (tb,tc,sparse (zeros (size (as)))), as); -%! assert (spdiags (tb,tc,size (as,1),size (as,2)), as); - -EOF -} - -# test matrix reshape operations -gen_matrixreshape_tests() { - cat <<EOF -%% Matrix diagonal tests (uses af,as,bf,bs) -%!assert (reshape (as,1,prod(size(as))), sparse (reshape (af,1,prod(size(af))))) -%!assert (reshape (as,prod(size(as)),1), sparse (reshape (af,prod(size(af)),1))) -%!assert (reshape (as,fliplr(size(as))), sparse (reshape (af,fliplr(size(af))))) -%!assert (reshape (bs,1,prod(size(as))), sparse (reshape (bf,1,prod(size(af))))) -%!assert (reshape (bs,prod(size(as)),1), sparse (reshape (bf,prod(size(af)),1))) -%!assert (reshape (bs,fliplr(size(as))), sparse (reshape (bf,fliplr(size(af))))) - -EOF -} - -# test mapper matrix operations: uses as,af -print_mapper_test() { -echo "%!assert ($1(as), sparse ($1(af)))" -} - -print_real_mapper_test() { - cat <<EOF -%!test -%! wn2s = warning ("query", "Octave:num-to-str"); -%! warning ("off", "Octave:num-to-str"); -%! if (isreal (af)) -%! if ($2) -%! assert ($1(as), sparse ($1(af))); -%! else -%! assert ($1(as), $1(af)); -%! endif -%! endif -%! warning (wn2s.state, "Octave:num-to-str"); - -EOF -} - -gen_mapper_tests() { -echo "%% Unary matrix tests (uses af,as)" -print_mapper_test abs -print_mapper_test acos -print_mapper_test acosh -print_mapper_test angle -print_mapper_test arg -print_mapper_test asin -print_mapper_test asinh -print_mapper_test atan -print_mapper_test atanh -print_mapper_test ceil -print_mapper_test conj -print_mapper_test cos -print_mapper_test cosh -print_mapper_test exp -print_mapper_test isfinite -print_mapper_test fix -print_mapper_test floor -print_mapper_test imag -print_mapper_test isinf -print_mapper_test isna -print_mapper_test isnan -print_mapper_test log -#print_mapper_test log10 ## fails with different NaN, not a problem -print_mapper_test real -print_mapper_test round -print_mapper_test sign -print_mapper_test sin -print_mapper_test sinh -print_mapper_test sqrt -print_mapper_test tan -print_mapper_test tanh - -# Specific tests for certain mapper functions - cat <<EOF -%!assert (issparse (abs (as)) && isreal (abs (as))) -%!assert (issparse (real (as)) && isreal (real (as))) -%!assert (issparse (imag (as)) && isreal (imag (as))) - -EOF -} - -gen_real_mapper_tests() { -echo "%% Unary matrix tests (uses af,as)" -print_real_mapper_test erf 1 -print_real_mapper_test erfc 1 -#print_real_mapper_test gamma 1 -print_real_mapper_test isalnum 0 -print_real_mapper_test isalpha 0 -print_real_mapper_test isascii 0 -print_real_mapper_test iscntrl 0 -print_real_mapper_test isdigit 0 -print_real_mapper_test isgraph 0 -print_real_mapper_test islower 0 -print_real_mapper_test isprint 0 -print_real_mapper_test ispunct 0 -print_real_mapper_test isspace 0 -print_real_mapper_test isupper 0 -print_real_mapper_test isxdigit 0 -#print_real_mapper_test gammaln 1 - -# Specific tests for certain mapper functions - cat <<EOF - -%!test -%! wn2s = warning ("query", "Octave:num-to-str"); -%! warning ("off", "Octave:num-to-str"); -%! if (isreal (af)) -%! assert (toascii (as), toascii (af)); -%! assert (tolower (as), as); -%! assert (toupper (as), as); -%! endif -%! warning (wn2s.state, "Octave:num-to-str"); - -EOF -} - -# test matrix operations: uses as,af -gen_unaryop_tests() { - cat <<EOF -%% Unary matrix tests (uses af,as) -%!assert (issparse (as)) -%!assert (!issparse (af)) -%!assert (! (issparse (af) && iscomplex (af))) -%!assert (! (issparse (af) && isreal (af))) -%!assert (sum (as), sparse (sum (af))) -%!assert (sum (as,1), sparse (sum (af,1))) -%!assert (sum (as,2), sparse (sum (af,2))) -%!assert (cumsum (as), sparse (cumsum (af))) -%!assert (cumsum (as,1), sparse (cumsum (af,1))) -%!assert (cumsum (as,2), sparse (cumsum (af,2))) -%!assert (sumsq (as), sparse (sumsq (af))) -%!assert (sumsq (as,1), sparse (sumsq (af,1))) -%!assert (sumsq (as,2), sparse (sumsq (af,2))) -%!assert (prod (as), sparse (prod (af))) -%!assert (prod (as,1), sparse (prod (af,1))) -%!assert (prod (as,2), sparse (prod (af,2))) -%!assert (cumprod (as), sparse (cumprod (af))) -%!assert (cumprod (as,1), sparse (cumprod (af,1))) -%!assert (cumprod (as,2), sparse (cumprod (af,2))) - -%!assert (min (as), sparse (min (af))) -%!assert (full (min (as(:))), min (af(:))) -%!assert (min (as,[],1), sparse (min (af,[],1))) -%!assert (min (as,[],2), sparse (min (af,[],2))) -%!assert (min (as,[],1), sparse (min (af,[],1))) -%!assert (min (as,0), sparse (min (af,0))) -%!assert (min (as,bs), sparse (min (af,bf))) -%!assert (max (as), sparse (max (af))) -%!assert (full (max (as(:))), max (af(:))) -%!assert (max (as,[],1), sparse (max (af,[],1))) -%!assert (max (as,[],2), sparse (max (af,[],2))) -%!assert (max (as,[],1), sparse (max (af,[],1))) -%!assert (max (as,0), sparse (max (af,0))) -%!assert (max (as,bs), sparse (max (af,bf))) - -%!assert (as==as) -%!assert (as==af) -%!assert (af==as) -%!test -%! [ii,jj,vv,nr,nc] = find (as); -%! assert (af, full (sparse (ii,jj,vv,nr,nc))); -%!assert (nnz (as), sum (af(:)!=0)) -%!assert (nnz (as), nnz (af)) -%!assert (issparse (as.')) -%!assert (issparse (as')) -%!assert (issparse (-as)) -%!assert (!as, sparse (!af)) -%!assert (as.', sparse (af.')) -%!assert (as', sparse (af')) -%!assert (-as, sparse (-af)) -%!assert (!as, sparse (!af)) -%!error [i,j] = size (af);as(i-1,j+1); -%!error [i,j] = size (af);as(i+1,j-1); -%!test -%! [Is,Js,Vs] = find (as); -%! [If,Jf,Vf] = find (af); -%! assert (Is, If); -%! assert (Js, Jf); -%! assert (Vs, Vf); -%!error as(0,1) -%!error as(1,0) -%!assert (find (as), find (af)) -%!test -%! [i,j,v] = find (as); -%! [m,n] = size (as); -%! x = sparse (i,j,v,m,n); -%! assert (x, as); -%!test -%! [i,j,v,m,n] = find (as); -%! x = sparse (i,j,v,m,n); -%! assert (x, as); -%!assert (issparse (horzcat (as,as))) -%!assert (issparse (vertcat (as,as))) -%!assert (issparse (cat (1,as,as))) -%!assert (issparse (cat (2,as,as))) -%!assert (issparse ([as,as])) -%!assert (issparse ([as;as])) -%!assert (horzcat (as,as), sparse ([af,af])) -%!assert (vertcat (as,as), sparse ([af;af])) -%!assert (horzcat (as,as,as), sparse ([af,af,af])) -%!assert (vertcat (as,as,as), sparse ([af;af;af])) -%!assert ([as,as], sparse ([af,af])) -%!assert ([as;as], sparse ([af;af])) -%!assert ([as,as,as], sparse ([af,af,af])) -%!assert ([as;as;as], sparse ([af;af;af])) -%!assert (cat (2,as,as), sparse ([af,af])) -%!assert (cat (1,as,as), sparse ([af;af])) -%!assert (cat (2,as,as,as), sparse ([af,af,af])) -%!assert (cat (1,as,as,as), sparse ([af;af;af])) -%!assert (issparse ([as,af])) -%!assert (issparse ([af,as])) -%!assert ([as,af], sparse ([af,af])) -%!assert ([as;af], sparse ([af;af])) - -EOF -} - -# operations which require square matrices. -gen_square_tests() { -# The \ and / operator tests on square matrices - gen_square_divop_tests - - cat <<EOF -%!testif HAVE_UMFPACK -%! assert(det(bs+speye(size(bs))), det(bf+eye(size(bf))), 100*eps*abs(det(bf+eye(size(bf))))); - -%!testif HAVE_UMFPACK -%! [l,u] = lu (sparse ([1,1;1,1])); -%! assert (l*u, [1,1;1,1], 10*eps); - -%!testif HAVE_UMFPACK -%! [l,u] = lu (sparse ([1,1;1,1+i])); -%! assert (l, sparse ([1,2,2],[1,1,2],1), 10*eps); -%! assert (u, sparse ([1,1,2],[1,2,2],[1,1,1i]), 10*eps); - -%!testif HAVE_UMFPACK # permuted LU -%! [L,U] = lu (bs); -%! assert (L*U, bs, 1e-10); - -%!testif HAVE_UMFPACK # simple LU + row permutations -%! [L,U,P] = lu (bs); -%! assert (P'*L*U, bs, 1e-10); -%! ## triangularity -%! [i,j,v] = find (L); -%! assert (i-j>=0); -%! [i,j,v] = find (U); -%! assert (j-i>=0); - -%!testif HAVE_UMFPACK # simple LU + row/col permutations -%! [L,U,P,Q] = lu (bs); -%! assert (P'*L*U*Q', bs, 1e-10); -%! ## triangularity -%! [i,j,v] = find (L); -%! assert (i-j>=0); -%! [i,j,v] = find (U); -%! assert (j-i>=0); - -%!testif HAVE_UMFPACK # LU with vector permutations -%! [L,U,P,Q] = lu (bs,'vector'); -%! assert (L(P,:)*U(:,Q), bs, 1e-10); -%! ## triangularity -%! [i,j,v] = find (L); -%! assert (i-j>=0); -%! [i,j,v] = find (U); -%! assert (j-i>=0); - -%!testif HAVE_UMFPACK # LU with scaling -%! [L,U,P,Q,R] = lu (bs); -%! assert (R*P'*L*U*Q', bs, 1e-10); -%! ## triangularity -%! [i,j,v] = find (L); -%! assert (i-j>=0); -%! [i,j,v] = find (U); -%! assert (j-i>=0); - -%!testif HAVE_UMFPACK # inverse -%! assert (inv (bs)*bs, sparse (eye (rows (bs))), 1e-10); - -%!assert (bf\as', bf\af', 100*eps) -%!assert (bs\af', bf\af', 100*eps) -%!assert (bs\as', sparse (bf\af'), 100*eps) - -EOF -} - -# Cholesky tests -gen_cholesky_tests() { - cat <<EOF -%!testif HAVE_CHOLMOD -%! assert (chol (bs)'*chol (bs), bs, 1e-10); -%!testif HAVE_CHOLMOD -%! assert (chol (bs,'lower')*chol (bs,'lower')', bs, 1e-10); -%!testif HAVE_CHOLMOD -%! assert (chol (bs,'lower'), chol (bs)', 1e-10); - -%!testif HAVE_CHOLMOD # Return Partial Cholesky factorization -%! [RS,PS] = chol (bs); -%! assert (RS'*RS, bs, 1e-10); -%! assert (PS, 0); -%! [LS,PS] = chol (bs,'lower'); -%! assert (LS*LS', bs, 1e-10); -%! assert (PS, 0); - -%!testif HAVE_CHOLMOD # Permuted Cholesky factorization -%! [RS,PS,QS] = chol (bs); -%! assert (RS'*RS, QS*bs*QS', 1e-10); -%! assert (PS, 0); -%! [LS,PS,QS] = chol (bs,'lower'); -%! assert (LS*LS', QS*bs*QS', 1e-10); -%! assert (PS, 0); - -EOF -} - -# test scalar operations: uses af and real scalar bf; modifies as,bf,bs -gen_scalar_tests() { - echo '%!test as = sparse (af);' - echo '%!test bs = bf;' - gen_elementop_tests - gen_ordering_tests - echo '%!test bf = bf+1i;' - echo '%!test bs = bf;' - gen_elementop_tests -} - -# test matrix operations: uses af and bf; modifies as,bs -gen_rectangular_tests() { - echo '%!test as = sparse(af);' - echo '%!test bs = sparse(bf);' - gen_mapper_tests - gen_real_mapper_tests - gen_unaryop_tests - gen_elementop_tests - gen_sparsesparse_elementop_tests - gen_matrixop_tests - # gen_divop_tests # Disable rectangular \ and / for now - gen_matrixdiag_tests - gen_matrixreshape_tests - cat <<EOF -%!testif HAVE_UMFPACK # permuted LU -%! [L,U] = lu (bs); -%! assert (L*U, bs, 1e-10); - -%!testif HAVE_UMFPACK # simple LU + row permutations -%! [L,U,P] = lu (bs); -%! assert (P'*L*U, bs, 1e-10); -%! ## triangularity -%! [i,j,v] = find (L); -%! assert (i-j>=0); -%! [i,j,v] = find (U); -%! assert (j-i>=0); - -%!testif HAVE_UMFPACK # simple LU + row/col permutations -%! [L,U,P,Q] = lu (bs); -%! assert (P'*L*U*Q', bs, 1e-10); -%! ## triangularity -%! [i,j,v] = find (L); -%! assert (i-j>=0); -%! [i,j,v] = find (U); -%! assert (j-i>=0); - -%!testif HAVE_UMFPACK # LU with vector permutations -%! [L,U,P,Q] = lu (bs,'vector'); -%! assert (L (P,:)*U (:,Q), bs, 1e-10); -%! ## triangularity -%! [i,j,v] = find (L); -%! assert (i-j>=0); -%! [i,j,v] = find (U); -%! assert (j-i>=0); - -%!testif HAVE_UMFPACK # LU with scaling -%! [L,U,P,Q,R] = lu (bs); -%! assert (R*P'*L*U*Q', bs, 1e-10); -%! ## triangularity -%! [i,j,v] = find (L); -%! assert (i-j>=0); -%! [i,j,v] = find (U); -%! assert (j-i>=0); - -EOF -} - - -# ======================================================= -# sparse assembly tests - -gen_assembly_tests() { -cat <<EOF -%%Assembly tests -%!test -%! m = max ([m;r(:)]); -%! n = max ([n;c(:)]); -%! funiq = fsum = zeros (m,n); -%! funiq(r(:) + m*(c(:)-1) ) = ones (size (r(:))); -%! funiq = sparse (funiq); -%! for k=1:length (r) -%! fsum(r(k),c(k)) += 1; -%! endfor -%! fsum = sparse (fsum); -%!assert (sparse (r,c,1), sparse (fsum(1:max(r), 1:max(c)))) -%!assert (sparse (r,c,1,"sum"), sparse (fsum(1:max (r),1:max (c)))) -%!assert (sparse (r,c,1,"unique"), sparse (funiq(1:max (r),1:max (c)))) -%!assert (sparse (r,c,1,m,n), sparse (fsum)) -%!assert (sparse (r,c,1,m,n,"sum"), sparse (fsum)) -%!assert (sparse (r,c,1,m,n,"unique"), sparse (funiq)) - -%!assert (sparse (r,c,1i), sparse (fsum(1:max (r),1:max (c))*1i)) -%!assert (sparse (r,c,1i,"sum"), sparse (fsum(1:max (r),1:max (c))*1i)) -%!assert (sparse (r,c,1i,"unique"), sparse (funiq(1:max (r),1:max (c))*1i)) -%!assert (sparse (r,c,1i,m,n), sparse (fsum*1i)) -%!assert (sparse (r,c,1i,m,n,"sum"), sparse (fsum*1i)) -%!assert (sparse (r,c,1i,m,n,"unique"), sparse (funiq*1i)) - -%!test -%! if (issparse (funiq)) -%! assert (sparse (full (1i*funiq)), sparse (1i*funiq)); -%! endif - -%!assert (sparse (full (funiq)), funiq) - - -EOF -} - -# ======================================================= -# sparse selection tests - -gen_scalar_select_tests () { - cat <<EOF -%!assert (sparse (42)([1,1]), sparse ([42,42])) -%!assert (sparse (42*1i)([1,1]), sparse ([42,42].*1i)) -EOF -} - -gen_select_tests() { - cat <<EOF -%!test as = sparse (af); - -%% Point tests -%!test idx = ridx(:) + rows (as) * (cidx (:)-1); -%!assert (sparse (as(idx)), sparse (af(idx))) -%!assert (as(idx), sparse (af(idx))) -%!assert (as(idx'), sparse (af(idx'))) -%!assert (as(flipud (idx(:))), sparse (af(flipud (idx(:))))) -%!assert (as([idx,idx]), sparse (af([idx,idx]))) -%!assert (as(reshape ([idx;idx], [1,length(idx),2])), sparse(af(reshape ([idx;idx], [1,length(idx),2])))) - -%% Slice tests -%!assert (as(ridx,cidx), sparse (af(ridx,cidx))) -%!assert (as(ridx,:), sparse (af(ridx,:))) -%!assert (as(:,cidx), sparse (af(:,cidx))) -%!assert (as(:,:), sparse (af(:,:))) -%!assert (as((size (as,1):-1:1),:), sparse (af((size (af,1):-1:1),:))) -%!assert (as(:,(size (as,2):-1:1)), sparse (af(:, (size (af,2):-1:1)))) - -%% Indexing tests -%!assert (full (as([1,1],:)), af([1,1],:)) -%!assert (full (as(:,[1,1])), af(:,[1,1])) -%!test -%! [i,j,v] = find (as); -%! assert (as(i(1),j(1))([1,1]), sparse ([v(1), v(1)])); - -%% Assignment test -%!test -%! ts = as; ts(:,:) = ts(fliplr (1:size (as,1)),:); -%! tf = af; tf(:,:) = tf(fliplr (1:size (af,1)),:); -%! assert (ts, sparse (tf)); -%!test -%! ts = as; ts(fliplr (1:size (as,1)),:) = ts; -%! tf = af; tf(fliplr (1:size (af,1)),:) = tf; -%! assert (ts, sparse (tf)); -%!test -%! ts = as; ts(:,fliplr (1:size (as,2))) = ts; -%! tf = af; tf(:,fliplr (1:size (af,2))) = tf; -%! assert (ts, sparse (tf)); -%!test -%! ts(fliplr (1:size (as,1))) = as(:,1); -%! tf(fliplr (1:size (af,1))) = af(:,1); -%! assert (ts, sparse (tf)); - -%% Deletion tests -%!test -%! ts = as; ts(1,:) = []; tf = af; tf(1,:) = []; -%! assert (ts, sparse (tf)); -%!test -%! ts = as; ts(:,1) = []; tf = af; tf(:,1) = []; -%! assert (ts, sparse (tf)); - -%% Test "end" keyword -%!assert (full (as(end)), af(end)) -%!assert (full (as(1,end)), af(1,end)) -%!assert (full (as(end,1)), af(end,1)) -%!assert (full (as(end,end)), af(end,end)) -%!assert (as(2:end,2:end), sparse (af(2:end,2:end))) -%!assert (as(1:end-1,1:end-1), sparse (af(1:end-1,1:end-1))) -EOF -} - -# ======================================================= -# sparse save and load tests - -gen_save_tests() { - cat <<EOF -%!test # save ascii -%! savefile = tempname (); -%! as_save = as; -%! save ("-text", savefile, "bf", "as_save", "af"); -%! clear as_save; -%! load (savefile, "as_save"); -%! unlink (savefile); -%! assert (as_save, sparse (af)); -%!test # save binary -%! savefile = tempname (); -%! as_save = as; -%! save ("-binary", savefile, "bf", "as_save", "af"); -%! clear as_save; -%! load (savefile, "as_save"); -%! unlink (savefile); -%! assert (as_save, sparse (af)); -%!testif HAVE_HDF5 # save hdf5 -%! savefile = tempname (); -%! as_save = as; -%! save ("-hdf5", savefile, "bf", "as_save", "af"); -%! clear as_save; -%! load (savefile, "as_save"); -%! unlink (savefile); -%! assert (as_save, sparse (af)); -## FIXME: We should skip (or mark as a known bug) the test for -## saving sparse matrices to MAT files when using 64-bit indexing since -## that is not implemented yet. -%!test # save matlab -%! savefile = tempname (); -%! as_save = as; -%! save ("-mat", savefile, "bf", "as_save", "af"); -%! clear as_save; -%! load (savefile, "as_save"); -%! unlink (savefile); -%! assert (as_save, sparse (af)); -EOF -} - -# ============================================================= -# Specific solver tests for matrices that will test all of the solver -# code. Uses alpha and beta -gen_solver_tests() { - -if $preset; then - cat <<EOF -%! n=8; -%! lf=diag (1:n); lf(n-1,1)=0.5*alpha; lf(n,2)=0.25*alpha; ls=sparse (lf); -%! uf=diag (1:n); uf(1,n-1)=2*alpha; uf(2,n)=alpha; us=sparse (uf); -%! ts=spdiags (ones (n,3),-1:1,n,n) + diag (1:n); tf = full (ts); -EOF -else - cat <<EOF -%! n = floor (lognrnd (8,2)+1)'; -%! ls = tril (sprandn (8,8,0.2),-1).*alpha + n*speye (8); lf = full (ls); -%! us = triu (sprandn (8,8,0.2),1).*alpha + n*speye (8); uf = full (us); -%! ts = spdiags (randn (8,3),-1:1,8,8).*alpha; tf = full (ts); -EOF -fi - -cat <<EOF -%! df = diag (1:n).* alpha; ds = sparse (df); -%! pdf = df(randperm (n), randperm (n)); -%! pds = sparse (pdf); -%! plf = lf(randperm (n), randperm (n)); -%! pls = sparse (plf); -%! puf = uf(randperm (n), randperm (n)); -%! pus = sparse (puf); -%! bs = spdiags (repmat ([1:n]',1,4),-2:1,n,n).*alpha; -%! bf = full (bs); -%! cf = lf + lf'; cs = sparse (cf); -%! bcf = bf + bf'; bcs = sparse (bcf); -%! tcf = tf + tf'; tcs = sparse (tcf); -%! xf = diag (1:n) + fliplr (diag (1:n)).*beta; -%! xs = sparse (xf); -%!assert (ds\xf, df\xf, 1e-10) -%!assert (ds\xs, sparse (df\xf), 1e-10) -%!assert (pds\xf, pdf\xf, 1e-10) -%!assert (pds\xs, sparse (pdf\xf), 1e-10) -%!assert (ls\xf, lf\xf, 1e-10) -%!assert (sparse (ls\xs), sparse (lf\xf), 1e-10) -%!testif HAVE_UMFPACK -%! assert (pls\xf, plf\xf, 1e-10); -%!testif HAVE_UMFPACK -%! assert (sparse (pls\xs), sparse (plf\xf), 1e-10); -%!assert (us\xf, uf\xf, 1e-10) -%!assert (sparse (us\xs), sparse (uf\xf), 1e-10) -%!testif HAVE_UMFPACK -%! assert (pus\xf, puf\xf, 1e-10); -%!testif HAVE_UMFPACK -%! assert (sparse (pus\xs), sparse (puf\xf), 1e-10); -%!assert (bs\xf, bf\xf, 1e-10) -%!assert (sparse (bs\xs), sparse (bf\xf), 1e-10) -%!testif HAVE_UMFPACK -%! assert (cs\xf, cf\xf, 1e-10); -%!testif HAVE_UMFPACK -%! assert (sparse (cs\xs), sparse (cf\xf), 1e-10); -%!testif HAVE_UMFPACK -%! assert (bcs\xf, bcf\xf, 1e-10); -%!testif HAVE_UMFPACK -%! assert (sparse (bcs\xs), sparse (bcf\xf), 1e-10); -%!assert (ts\xf, tf\xf, 1e-10) -%!assert (sparse (ts\xs), sparse (tf\xf), 1e-10) -%!assert (tcs\xf, tcf\xf, 1e-10) -%!assert (sparse (tcs\xs), sparse (tcf\xf), 1e-10) - -EOF - -cat <<EOF -%% QR solver tests - -%!function f (a, sz, feps) -%! b = randn (sz); -%! x = a \ b; -%! assert (a * x, b, feps); -%! b = randn (sz) + 1i*randn (sz); -%! x = a \ b; -%! assert (a * x, b, feps); -%! b = sprandn (sz(1),sz(2),0.2); -%! x = a \ b; -%! assert (sparse (a * x), b, feps); -%! b = sprandn (sz(1),sz(2),0.2) + 1i*sprandn (sz(1),sz(2),0.2); -%! x = a \ b; -%! assert (sparse (a * x), b, feps); -%!endfunction -%!testif HAVE_UMFPACK -%! a = alpha*sprandn (10,11,0.2) + speye (10,11); -%! f (a,[10,2],1e-10); -%! ## Test this by forcing matrix_type, as can't get a certain -%! ## result for over-determined systems. -%! a = alpha*sprandn (10,10,0.2) + speye (10,10); -%! matrix_type (a, "Singular"); -%! f (a,[10,2],1e-10); - -%% Rectanguar solver tests that don't use QR - -%!test -%! ds = alpha * spdiags ([1:11]',0,10,11); -%! df = full (ds); -%! xf = beta * ones (10,2); -%! xs = speye (10,10); -%!assert (ds\xf, df\xf, 100*eps) -%!assert (ds\xs, sparse (df\xs), 100*eps) -%!test -%! pds = ds([2,1,3:10],:); -%! pdf = full (pds); -%!assert (pds\xf, pdf\xf, 100*eps) -%!assert (pds\xs, sparse (pdf\xs), 100*eps) -%!test -%! ds = alpha * spdiags ([1:11]',0,11,10); -%! df = full (ds); -%! xf = beta * ones (11,2); -%! xs = speye (11,11); -%!assert (ds\xf, df\xf, 100*eps) -%!assert (ds\xs, sparse (df\xs), 100*eps) -%!test -%! pds = ds([2,1,3:11],:); -%! pdf = full (pds); -%!assert (pds\xf, pdf\xf, 100*eps) -%!assert (pds\xs, sparse (pdf\xs), 100*eps) -%!test -%! us = alpha*[[speye(10,10);sparse(1,10)],[[1,1];sparse(9,2);[1,1]]]; -%!testif HAVE_UMFPACK -%! assert (us*(us\xf), xf, 100*eps); -%!testif HAVE_UMFPACK -%! assert (us*(us\xs), xs, 100*eps); -%!test -%! pus = us(:,[2,1,3:12]); -%!testif HAVE_UMFPACK -%! assert (pus*(pus\xf), xf, 100*eps); -%!testif HAVE_UMFPACK -%! assert (pus*(pus\xs), xs, 100*eps); -%!test -%! us = alpha*[speye(11,9),[1;sparse(8,1);1;0]]; -%!testif HAVE_CXSPARSE -%! [c,r] = qr (us, xf); -%! assert (us\xf, r\c, 100*eps); -%!testif HAVE_UMFPACK -%! [c,r] = qr (us, xs); -%! r = matrix_type (r, "Singular"); ## Force Matrix Type -%! assert (us\xs, r\c, 100*eps); -%!test -%! pus = us(:,[1:8,10,9]); -%!testif HAVE_UMFPACK -%! [c,r] = qr (pus, xf); -%! r = matrix_type (r, "Singular"); ## Force Matrix Type -%! assert (pus\xf, r\c, 100*eps); -%!testif HAVE_UMFPACK -%! [c,r] = qr (pus, xs); -%! r = matrix_type (r, "Singular"); ## Force Matrix Type -%! assert (pus\xs, r\c, 100*eps); -%!test -%! ls = alpha*[speye(9,11);[1, sparse(1,8),1,0]]; -%! xf = beta * ones (10,2); -%! xs = speye (10,10); -%!assert (ls*(ls\xf), xf, 100*eps) -%!assert (ls*(ls\xs), xs, 100*eps) -%!test -%! pls = ls([1:8,10,9],:); -%!assert (pls*(pls\xf), xf, 100*eps) -%!assert (pls*(pls\xs), xs, 100*eps) -%!test -%! ls = alpha*[speye(10,10), sparse(10,1);[1;1], sparse(2,9),[1;1]]; -%! xf = beta * ones (12,2); -%! xs = speye (12,12); -%!testif HAVE_UMFPACK -%! [c,r] = qr (ls, xf); -%! assert (ls\xf, r\c, 100*eps); -%!testif HAVE_UMFPACK -%! [c,r] = qr (ls, xs); -%! r = matrix_type (r, "Singular"); ## Force Matrix Type -%! assert (ls\xs, r\c, 100*eps); -%!testif HAVE_CXSPARSE -%! pls = ls(:,[1:8,10,9]); -%!testif HAVE_UMFPACK -%! [c,r] = qr (pls, xf); -%! r = matrix_type (r, "Singular"); ## Force Matrix Type -%! assert (pls\xf, r\c, 100*eps); -%!testif HAVE_UMFPACK -%! [c,r] = qr (pls, xs); -%! r = matrix_type (r, "Singular"); ## Force Matrix Type -%! assert (pls\xs, r\c, 100*eps); - -EOF -} - - -# ============================================================= -# Putting it all together: defining the combined tests - - -# initial function -gen_function -gen_section - -# specific tests -if $preset; then - gen_specific_tests - gen_section -fi - -# scalar operations -echo '%!shared as,af,bs,bf' -if $preset; then - echo '%!test af=[1+1i,2-1i,0,0;0,0,0,3+2i;0,0,0,4];' - echo '%!test bf=3;' -else - cat <<EOF -%!test -%! % generate m,n from 1 to <5000 -%! m = floor (lognrnd (8,2)+1); -%! n = floor (lognrnd (8,2)+1); -%! as = sprandn (m,n,0.3); -%! af = full (as + 1i*sprandn (as)); -%! bf = randn; -EOF -fi - -gen_scalar_tests -gen_section - -# rectangular operations -if $preset; then - echo '%!test af=[1+1i,2-1i,0,0;0,0,0,3+2i;0,0,0,4];' - echo '%!test bf=[0,1-1i,0,0;2+1i,0,0,0;3-1i,2+3i,0,0];' -else - cat <<EOF -%!test -%! m = floor (lognrnd (8,2)+1); -%! n = floor (lognrnd (8,2)+1); -%! as = sprandn (m,n,0.3); -%! af = full (as + 1i*sprandn (as)); -%! bs = sprandn (m,n,0.3); -%! bf = full (bs + 1i*sprandn (bs)); -EOF -fi - -gen_rectangular_tests -gen_section -gen_save_tests -gen_section -echo '%!test bf = real (bf);' -gen_rectangular_tests -gen_section -gen_sparsesparse_ordering_tests -gen_section -echo '%!test af = real (af);' -gen_rectangular_tests -gen_section -gen_save_tests -gen_section -echo '%!test bf = bf+1i*(bf!=0);' -gen_rectangular_tests -gen_section - -# square operations -if $preset; then - echo '%!test af = [1+1i,2-1i,0,0;0,0,0,3+2i;0,0,0,4];' - echo '%! as = sparse (af);' - echo '%!test bf = [0,1-1i,0,0;2+1i,0,0,0;3-1i,2+3i,0,0];' -else - cat <<EOF -%!test -%! m = floor (lognrnd (8,2)+1); -%! n = floor (lognrnd (8,2)+1); -%! as = sprandn (m,n,0.3); -%! af = full (as + 1i*sprandn (as)); -%! bs = sprandn (m,n,0.3); -%! bf = full (bs + 1i*sprandn (bs)); -EOF -fi - -cat <<EOF -%!test ;# invertible matrix -%! bf = af'*bf+max (abs ([af(:);bf(:)]))*sparse (eye (columns (as))); -%! bs = sparse (bf); - -EOF - -gen_square_tests -gen_section -echo '%!test bf = real (bf);' -echo '%! bs = sparse (bf);' -gen_square_tests -gen_section -echo '%!test af = real (af);' -echo '%! as = sparse (af);' -gen_square_tests -gen_section -echo '%!test bf = bf+1i*(bf!=0);' -echo '%! bs = sparse (bf);' -gen_square_tests -gen_section - -# cholesky tests -if $preset; then - echo '%!test bf = [5,0,1+1i,0;0,5,0,1-2i;1-1i,0,5,0;0,1+2i,0,5];' - echo '%! bs = sparse (bf);' -else - echo '# This has a small chance of failing to create a positive definite matrix' - echo '%!test n = floor (lognrnd (8,2)+1)' - echo '%! bs = n*speye (n,n) + sprandn (n,n,0.3);' - echo '%! bf = full (bs);' -fi - -gen_cholesky_tests -gen_section -echo '%!test bf = real (bf);' -echo '%! bs = sparse (bf);' -gen_cholesky_tests -gen_section - -# assembly tests -echo '%!shared r,c,m,n,fsum,funiq' -if $use_preset; then - cat <<EOF -%!test -%! r = [1,1,2,1,2,3]; -%! c = [2,1,1,1,2,1]; -%! m = n = 0; -EOF -else - cat <<EOF -%!test -%! % generate m,n from 1 to <5000 -%! m = floor (lognrnd (8,2)+1); -%! n = floor (lognrnd (8,2)+1); -%! nz = ceil ((m+n)/2); -%! r = floor (rand (5,nz)*n)+1; -%! c = floor (rand (5,nn)*m)+1; -EOF -fi -gen_assembly_tests #includes real and complex tests -gen_section - -# slicing tests -echo '%!shared ridx,cidx,idx,as,af' -if $use_preset; then - cat <<EOF -%!test -%! af = [1+1i,2-1i,0,0;0,0,0,3+2i;0,0,0,4]; -%! ridx = [1,3]; -%! cidx = [2,3]; -EOF -else - cat <<EOF -%!test -%! % generate m,n from 1 to <5000 -%! m = floor (lognrnd (8,2)+1); -%! n = floor (lognrnd (8,2)+1); -%! as = sprandn (m,n,0.3); -%! af = full (as + 1i*sprandn (as)); -%! ridx = ceil (m*rand (1,ceil (rand*m)); -%! cidx = ceil (n*rand (1,ceil (rand*n)); -EOF -fi -gen_scalar_select_tests -gen_select_tests -echo '%!test af = real (af);' -gen_select_tests -gen_section -echo '%!shared alpha,beta,df,pdf,lf,plf,uf,puf,bf,cf,bcf,tf,tcf,xf,ds,pds,ls,pls,us,pus,bs,cs,bcs,ts,tcs,xs' -echo '%!test alpha=1; beta=1;' -gen_solver_tests -echo '%!test alpha=1; beta=1i;' -gen_solver_tests -echo '%!test alpha=1i; beta=1;' -gen_solver_tests -echo '%!test alpha=1i; beta=1i;' -gen_solver_tests -gen_section
--- a/test/build_bc_overloads_expected.m Tue Jun 27 15:10:58 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,35 +0,0 @@ -% this script is intended to be Matlab compatible -% first, run the script -% -% ./build_bc_overloads_tests.sh overloads_only -% -% to generate the overloaded functions. -% -ex.double = 1; -ex.single = single (1); -ex.logical = true; -ex.char = 'char'; -ex.int8 = int8 (1); -ex.int16 = int16 (1); -ex.int32 = int32 (1); -ex.int64 = int64 (1); -ex.uint8 = uint8 (1); -ex.uint16 = uint16 (1); -ex.uint32 = uint32 (1); -ex.uint64 = uint64 (1); -ex.cell = {}; -ex.struct = struct (); -ex.function_handle = @numel; - -f = fieldnames (ex); -n = numel (f); - -fid = fopen ('bc_overloads_expected','w'); -fid -for i = 1:n - for j = 1:n - s = tbcover (ex.(f{i}), ex.(f{j})); - fprintf (fid, '%s %s %s\n', f{i}, f{j}, s); - end -end -fclose (fid)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/mk-bc-overloads-tst.sh Tue Jun 27 18:30:12 2017 -0400 @@ -0,0 +1,141 @@ +#! /bin/sh + +# Copyright (C) 2010-2017 VZLU Prague +# +# This file is part of Octave. +# +# Octave is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Octave is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Octave; see the file COPYING. If not, see +# <http://www.gnu.org/licenses/>. + +CLASSES=" + double + single + char + logical + int8 + int16 + int32 + int64 + uint8 + uint16 + uint32 + uint64 + struct + cell + function_handle +" + +if [ $# -eq 2 ]; then + output_dir="$1" + shift + case "$1" in + --list-files) + echo $output_dir/tbcover.m + echo $output_dir/bc-overloads.tst + for class in $CLASSES; do + echo $output_dir/@$class/tbcover.m + done + exit + ;; + --list-dirs) + for class in $CLASSES; do + echo $output_dir/@$class + done + exit + ;; + --list-classes) + echo $CLASSES + exit + ;; + *) + expected_results_file="$1" + ;; + esac +else + echo "usage: build-bc-overload-tests.sh output_dir option" 1>&2 + exit 1 +fi + +for class in $CLASSES; do + DIR="$output_dir/@$class" + test -d $DIR || mkdir $DIR || { echo "error: could not create $DIR"; exit; } + cat > $DIR/tbcover.m << EOF +% !!! DO NOT EDIT !!! +% generated automatically by build-bc-overload-tests.sh +function s = tbcover (x, y) + s = '$class'; +EOF +done + +cat > $output_dir/tbcover.m << EOF +% !!! DO NOT EDIT !!! +% generated automatically by build-bc-overload-tests.sh +function s = tbcover (x, y) + s = 'none'; +EOF + +if test "$1" = "overloads_only" ; then + exit +fi + +cat > $output_dir/bc-overloads.tst << EOF +## !!! DO NOT EDIT !!! +## THIS IS AN AUTOMATICALLY GENERATED FILE +## modify build-bc-overload-tests.sh to generate the tests you need. + +%!shared ex +%! ex.double = 1; +%! ex.single = single (1); +%! ex.logical = true; +%! ex.char = 'char'; +%! ex.int8 = int8 (1); +%! ex.int16 = int16 (1); +%! ex.int32 = int32 (1); +%! ex.int64 = int64 (1); +%! ex.uint8 = uint8 (1); +%! ex.uint16 = uint16 (1); +%! ex.uint32 = uint32 (1); +%! ex.uint64 = uint64 (1); +%! ex.cell = {}; +%! ex.struct = struct (); +%! ex.function_handle = @numel; + +EOF + +cat $expected_results_file | \ +while read cl1 cl2 clr ; do + cat >> $output_dir/bc-overloads.tst << EOF +%% Name call +%!assert (tbcover (ex.$cl1, ex.$cl2), "$clr") +%% Handle call +%!assert ((@tbcover) (ex.$cl1, ex.$cl2), "$clr") + +EOF +done + +cat >> $output_dir/bc-overloads.tst << EOF +%%test handles through cellfun +%!test +%! f = fieldnames (ex); +%! n = numel (f); +%! s = c1 = c2 = cell (n); +%! for i = 1:n +%! for j = 1:n +%! c1{i,j} = ex.(f{i}); +%! c2{i,j} = ex.(f{j}); +%! s{i,j} = tbcover (ex.(f{i}), ex.(f{j})); +%! endfor +%! endfor +%! assert (cellfun (@tbcover, c1, c2, "uniformoutput", false), s); +EOF
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/mk-conv-tst.sh Tue Jun 27 18:30:12 2017 -0400 @@ -0,0 +1,195 @@ +#!/bin/sh + +## Copyright (C) 2016-2017 John W. Eaton +## +## This file is part of Octave. +## +## Octave is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or +## (at your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +cat <<EOF +## !!! DO NOT EDIT !!! +## THIS IS AN AUTOMATICALLY GENERATED FILE +## modify build-conv-tests.sh to generate the tests you need. + + +%!shared r,dq,sq,b,bm,dm,cdm,fdm,fcdm,pm,sm,sbm,scm,s,m,cs,cm,fs,fm,fcs,fcm,i8s,i16s,i32s,i64s,i8m,i16m,i32m,i64m,ui8s,ui16s,ui32s,ui64s,ui8m,ui16m,ui32m,ui64m +%!test +%! r = 1:5; +%! dq = "foo"; +%! sq = 'bar'; +%! b = true; +%! bm = rand (5) > 0.5; +%! dm = eye (5); +%! cdm = eye (5) * i; +%! fdm = eye (5, "single"); +%! fcdm = eye (5, "single") * single (i); +%! [~, ~, pm] = qr (rand (5)); +%! sm = sprand (5, 5, 0.1); +%! sbm = sparse (rand (5) > 0.5); +%! scm = sprand (5, 5, 0.1) * i; +%! s = rand (); +%! m = rand (5); +%! cs = 13 * i; +%! cm = rand (5) * i; +%! fs = rand ("single"); +%! fm = rand (5, "single"); +%! fcs = rand ("single") * single (i); +%! fcm = rand (5, "single") * single (i); +%! i8s = int8 (rand () * 10); +%! i16s = int16 (rand () * 10); +%! i32s = int32 (rand () * 10); +%! i64s = int64 (rand () * 10); +%! i8m = int8 (rand (5) * 10); +%! i16m = int16 (rand (5) * 10); +%! i32m = int32 (rand (5) * 10); +%! i64m = int64 (rand (5) * 10); +%! ui8s = uint8 (rand () * 10); +%! ui16s = uint16 (rand () * 10); +%! ui32s = uint32 (rand () * 10); +%! ui64s = uint64 (rand () * 10); +%! ui8m = uint8 (rand (5) * 10); +%! ui16m = uint16 (rand (5) * 10); +%! ui32m = uint32 (rand (5) * 10); +%! ui64m = uint64 (rand (5) * 10); +%! +%!assert (typeinfo (r), "range") +%!assert (typeinfo (dq), "string") +%!assert (typeinfo (sq), "sq_string") +%!assert (typeinfo (b), "bool") +%!assert (typeinfo (bm), "bool matrix") +%!assert (typeinfo (dm), "diagonal matrix") +%!assert (typeinfo (cdm), "complex diagonal matrix") +%!assert (typeinfo (fdm), "float diagonal matrix") +%!assert (typeinfo (fcdm), "float complex diagonal matrix") +%!assert (typeinfo (pm), "permutation matrix") +%!assert (typeinfo (sm), "sparse matrix") +%!assert (typeinfo (sbm), "sparse bool matrix") +%!assert (typeinfo (scm), "sparse complex matrix") +%!assert (typeinfo (s), "scalar") +%!assert (typeinfo (m), "matrix") +%!assert (typeinfo (cs), "complex scalar") +%!assert (typeinfo (cm), "complex matrix") +%!assert (typeinfo (fs), "float scalar") +%!assert (typeinfo (fm), "float matrix") +%!assert (typeinfo (fcs), "float complex scalar") +%!assert (typeinfo (fcm), "float complex matrix") +%!assert (typeinfo (i8s), "int8 scalar") +%!assert (typeinfo (i16s), "int16 scalar") +%!assert (typeinfo (i32s), "int32 scalar") +%!assert (typeinfo (i64s), "int64 scalar") +%!assert (typeinfo (i8m), "int8 matrix") +%!assert (typeinfo (i16m), "int16 matrix") +%!assert (typeinfo (i32m), "int32 matrix") +%!assert (typeinfo (i64m), "int64 matrix") +%!assert (typeinfo (ui8s), "uint8 scalar") +%!assert (typeinfo (ui16s), "uint16 scalar") +%!assert (typeinfo (ui32s), "uint32 scalar") +%!assert (typeinfo (ui64s), "uint64 scalar") +%!assert (typeinfo (ui8m), "uint8 matrix") +%!assert (typeinfo (ui16m), "uint16 matrix") +%!assert (typeinfo (ui32m), "uint32 matrix") +%!assert (typeinfo (ui64m), "uint64 matrix") +%! +%!assert (class (r), "double") +%!assert (class (dq), "char") +%!assert (class (sq), "char") +%!assert (class (b), "logical") +%!assert (class (bm), "logical") +%!assert (class (dm), "double") +%!assert (class (cdm), "double") +%!assert (class (fdm), "single") +%!assert (class (fcdm), "single") +%!assert (class (pm), "double") +%!assert (class (sm), "double") +%!assert (class (sbm), "logical") +%!assert (class (scm), "double") +%!assert (class (s), "double") +%!assert (class (m), "double") +%!assert (class (cs), "double") +%!assert (class (cm), "double") +%!assert (class (fs), "single") +%!assert (class (fm), "single") +%!assert (class (fcs), "single") +%!assert (class (fcm), "single") +%!assert (class (i8s), "int8") +%!assert (class (i16s), "int16") +%!assert (class (i32s), "int32") +%!assert (class (i64s), "int64") +%!assert (class (i8m), "int8") +%!assert (class (i16m), "int16") +%!assert (class (i32m), "int32") +%!assert (class (i64m), "int64") +%!assert (class (ui8s), "uint8") +%!assert (class (ui16s), "uint16") +%!assert (class (ui32s), "uint32") +%!assert (class (ui64s), "uint64") +%!assert (class (ui8m), "uint8") +%!assert (class (ui16m), "uint16") +%!assert (class (ui32m), "uint32") +%!assert (class (ui64m), "uint64") +EOF + +## There are no single or integer sparse matrices. + +sparse_vars="sm sbm scm" +sparse_conversions="double logical" + +for c in $sparse_conversions; do + echo "" + for v in $sparse_vars; do + echo "%!assert (class ($c ($v)), \"$c\")" + done +done + +char_vars="dq sq" +bool_vars="b bm" +real_vars="r s m fs fm dm fdm pm" +complex_vars="cs cm fcs fcm cdm fcdm" +signed_int_vars="i8s i16s i32s i64s i8m i16m i32m i64m" +unsigned_int_vars="ui8s ui16s ui32s ui64s ui8m ui16m ui32m ui64m" +int_vars="$signed_int_vars $unsigned_int_vars" + +bool_conversions="logical" +float_conversions="double single" +int_conversions="int8 int16 int32 int64 uint8 uint16 uint32 uint64" +all_conversions="$bool_conversions $float_conversions $int_conversions" + +## Strings can't be converted to logical. + +for v in $char_vars; do + echo "" + for c in $float_conversions $int_conversions; do + echo "%!assert (class ($c ($v)), \"$c\")" + done +done + +## Octave doesn't have complex integers. + +for v in $complex_vars; do + echo "" + for c in $bool_conversions $float_conversions; do + echo "%!assert (class ($c ($v)), \"$c\")" + done +done + +## Logical and real-value numeric values should be convertible to any +## double, single, logical or integer type. + +for v in $bool_vars $real_vars $int_vars; do + echo "" + for c in $all_conversions; do + echo "%!assert (class ($c ($v)), \"$c\")" + done +done
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/mk-sparse-tst.sh Tue Jun 27 18:30:12 2017 -0400 @@ -0,0 +1,1319 @@ +#! /bin/sh + +# Copyright (C) 2006-2017 David Bateman +# +# This file is part of Octave. +# +# Octave is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Octave is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Octave; see the file COPYING. If not, see +# <http://www.gnu.org/licenses/>. + +# Some tests are commented out because they are known to be broken! +# Search for "# fails" + +# ./build-sparse-tests.sh preset +# creates sparse.tst with preset tests. +# Use "test sparse.tst" from octave to run the tests. +# +# ./build-sparse-tests.sh random +# Creates sprandom.tst with randomly generated matrices. +# Use "test sprandom.tst" from octave to run the tests. + +# build-sparse-tests.sh generates tests for real and complex sparse matrices. +# Also, we want to run both fixed tests with known outputs (quick tests) +# and longer tests with unknown outputs (thorough tests). This requires +# two sets of tests -- one which uses preset matrices and another which +# uses randomly generated matrices. +# +# The tests are mostly identical for each case but the code is different, +# so it is important that the tests be run on all cases. Because our test +# harness doesn't have support for looping or macros (it is only needed +# for new data types), but sh does, we use sh to generate inline versions of +# the tests for each case. +# +# Our 'macros' use shared variables as parameters. This allows us to +# for example define A complex and include all the unary ops tests, +# then set A=real(A) and include all the unary ops tests. Thus the +# same tests work for real and complex. For binary tests it is even +# more complicated because we want full X sparse, sparse X full and +# sparse X sparse tested. +# +# We use the following macros: +# +# gen_section +# place a separator in the test file +# gen_function +# define the function definion +# helper gen_specific +# specific tests such as error handling and null input +# helper gen_eat_zeros +# make sure sparse-scalar ops which generate 0 work +# gen_specific_tests +# specific and eat zeros tests +# helper gen_ordering_tests +# ordered comparison operators for real valued tests +# helper gen_sparsesparse_ordering_tests +# ordered comparison operators for real valued sparse-sparse tests +# helper gen_elementop_tests +# element-wise matrix binary operators, including scalar-matrix ops. +# horizontal/vertical concatenation are here as well. +# helper gen_sparsesparse_elementop_tests +# element-wise matrix binary operators, for sparse-sparse ops. +# horizontal/vertical concatenation are here as well. +# helper gen_divop_tests +# left and right matrix division operators of rectangular matrices. +# Needs QR solvers +# helper gen_square_divop_tests +# left and right matrix division operators of square matrices. +# helper gen_matrixop_tests +# rectangular matrix binary operators: * +# helper gen_matrixdiag_tests +# Tests extract of diag and creation of diagonal matrices using +# diag and spdiags functions +# helper gen_matrixreshape_tests +# Test the reshape function on sparse matrices +# helper print_mapper_test +# sub-helper function of gen_mapper_tests to print individual tests +# helper gen_mapper_tests +# Tests all of the one argument mapper functions. There are a few +# specific tests that abs, real and imag return real values. +# helper gen_unaryop_tests +# functions and operators which transform a single matrix +# helper gen_save_tests +# Tests the load/save functionality for ascii/binary and hdf5 formats +# gen_scalar_tests +# element ops for real and complex scalar and sparse +# gen_rectangular_tests +# unary, element, and matrix tests for a and full/sparse b +# gen_square_tests +# operations which require square matrices: lu, inv, \ +# A square non-singular matrix is defined from the rectangular +# inputs A and B. +# gen_assembly_tests +# test for sparse constructors with 'sum' vs. 'unique' +# gen_select_tests +# indexing and assignment tests +# gen_solver_tests +# Tests the solve function with triangular/banded, etc matrices + +case $1 in + random) preset=false ;; + preset) preset=true ;; + '') preset=true ;; + *) echo "build-sparse-tests.sh random|preset" && exit 1 ;; +esac + +# create initial file +cat <<EOF +## !!! DO NOT EDIT !!! +## THIS IS AN AUTOMATICALLY GENERATED FILE +## modify build-sparse-tests.sh to generate the tests you need. +EOF + + +# define all functions + + +# ======================================================= +# Section separator + +gen_section() { +cat <<EOF + +# ============================================================== + +EOF +} + + +# ======================================================= +# Specific preset tests + +# ======================================================= +# If a sparse operation yields zeros, then those elements +# of the returned sparse matrix should be eaten. +gen_eat_zeros() { +cat <<EOF +%% Make sure newly introduced zeros get eaten +%!assert (nnz (sparse ([bf,bf,1]).^realmax), 1) +%!assert (nnz (sparse ([1,bf,bf]).^realmax), 1) +%!assert (nnz (sparse ([bf,bf,bf]).^realmax), 0) + +%!assert (nnz (sparse ([bf;bf;1]).^realmax), 1) +%!assert (nnz (sparse ([1;bf;bf]).^realmax), 1) +%!assert (nnz (sparse ([0.5;bf;bf]).^realmax), 0) + +%!assert (nnz (sparse ([bf,bf,1])*realmin), 1) +%!assert (nnz (sparse ([1,bf,bf])*realmin), 1) +%!assert (nnz (sparse ([bf,bf,bf])*realmin), 0) + +%!assert (nnz (sparse ([bf;bf;1])*realmin), 1) +%!assert (nnz (sparse ([1;bf;bf])*realmin), 1) +%!assert (nnz (sparse ([bf;bf;bf])*realmin), 0) + +EOF +} + +gen_specific() { +cat <<EOF + +%!test # segfault test from edd@debian.org +%! n = 510; +%! sparse (kron ((1:n)', ones (n,1)), kron (ones (n,1), (1:n)'), ones (n)); + +%% segfault tests from Fabian@isas-berlin.de +%% Note that the last four do not fail, but rather give a warning +%% of a singular matrix, which is consistent with the full matrix +%% behavior. They are therefore disabled. +%!testif HAVE_UMFPACK +%! assert (inv (sparse ([1,1;1,1+i])), sparse ([1-1i,1i;1i,-1i]), 10*eps); +%#!error inv ( sparse ([1,1;1,1] ) ); +%#!error inv ( sparse ([0,0;0,1] ) ); +%#!error inv ( sparse ([0,0;0,1+i]) ); +%#!error inv ( sparse ([0,0;0,0] ) ); + +%% error handling in constructor +%!error sparse (1,[2,3],[1,2,3]) +%!error sparse ([1,1],[1,1],[1,2],3,3,"invalid") +%!error sparse ([1,3],[1,-4],[3,5],2,2) +%!error sparse ([1,3],[1,-4],[3,5i],2,2) +%!error sparse (-1,-1,1) +EOF +} + + +gen_specific_tests() { + gen_section + gen_specific + gen_section + echo '%!shared bf' + echo '%!test bf=realmin;' + gen_eat_zeros + echo '%!test bf=realmin+realmin*1i;' + gen_eat_zeros + cat <<EOF +%!assert (nnz (sparse ([-1,realmin,realmin]).^1.5), 1) +%!assert (nnz (sparse ([-1,realmin,realmin,1]).^1.5), 2) + +## Make sure scalar v==0 doesn't confuse matters +%!assert (nnz (sparse (1,1,0)), 0) +%!assert (nnz (sparse (eye (3))*0), 0) +%!assert (nnz (sparse (eye (3))-sparse (eye (3))), 0) + +%!test +%! wdbz = warning ("query", "Octave:divide-by-zero"); +%! warning ("off", "Octave:divide-by-zero"); +%! assert (full (sparse (eye (3))/0), full (eye (3)/0)); +%! warning (wdbz.state, "Octave:divide-by-zero"); + +EOF +} + + +# ======================================================= +# Main function definition + +gen_function() { + if $preset; then + cat <<EOF +## +## test_sparse +## +## run preset sparse tests. All should pass. +function [passes, tests] = test_sparse + disp ("writing test output to sptest.log"); + test ("sparse.tst", "normal", "sptest.log"); +endfunction + +EOF + else + cat <<EOF +## +## test_sprandom +## +## total_passes=0; total_tests=0; +## for i=1:10 +## [passes,tests] = sprandomtest; +## total_passes += passes; +## total_tests += tests; +## end +## The test log is appended to sprandomtest.log +function [passes,total] = test_sprandom + warning ("untested --- fix the source in build-sparse-tests.sh"); + disp ("appending test output to sprandomtest.log"); + fid = fopen ("sprandomtest.log", "at"); + test ("sprandom.tst", "normal", fid); + ##[passes, total] = test ("sprandomtest", "normal", fid); + fclose (fid); +endfunction + +EOF + fi + +} + + +# ======================================================= +# matrix ops + +# test ordered comparisons: uses as,af,bs,bf +gen_ordering_tests() { + cat <<EOF +%% real values can be ordered (uses as,af) +%!assert (as<=bf, sparse (af<=bf)) +%!assert (bf<=as, sparse (bf<=af)) + +%!assert (as>=bf, sparse (af>=bf)) +%!assert (bf>=as, sparse (bf>=af)) + +%!assert (as<bf, sparse (af<bf)) +%!assert (bf<as, sparse (bf<af)) + +%!assert (as>bf, sparse (af>bf)) +%!assert (bf>as, sparse (bf>af)) + +EOF +} + +gen_sparsesparse_ordering_tests() { + cat <<EOF +%!assert (as<=bs, sparse (af<=bf)) +%!assert (as>=bs, sparse (af>=bf)) +%!assert (as<bs, sparse (af<bf)) +%!assert (as>bs, sparse (af>bf)) +EOF +} + +# test element-wise binary operations: uses as,af,bs,bf,scalar +gen_elementop_tests() { + cat <<EOF +%% Elementwise binary tests (uses as,af,bs,bf,scalar) +%!assert (as==bs, sparse (af==bf)) +%!assert (bf==as, sparse (bf==af)) + +%!assert (as!=bf, sparse (af!=bf)) +%!assert (bf!=as, sparse (bf!=af)) + +%!assert (as+bf, af+bf) +%!assert (bf+as, bf+af) + +%!assert (as-bf, af-bf) +%!assert (bf-as, bf-af) + +%!assert (as.*bf, sparse (af.*bf)) +%!assert (bf.*as, sparse (bf.*af)) + +%!assert (as./bf, sparse (af./bf), 100*eps) +%!assert (bf.\as, sparse (bf.\af), 100*eps) + +%!test +%! sv = as.^bf; +%! fv = af.^bf; +%! idx = find (af!=0); +%! assert (sv(:)(idx), sparse (fv(:)(idx)), 100*eps); + +EOF +} + +gen_sparsesparse_elementop_tests() { + cat <<EOF +%!assert (as==bs, sparse (af==bf)) +%!assert (as!=bs, sparse (af!=bf)) +%!assert (as+bs, sparse (af+bf)) +%!assert (as-bs, sparse (af-bf)) +%!assert (as.*bs, sparse (af.*bf)) +%!xtest assert (as./bs, sparse (af./bf), 100*eps) +%!test +%! sv = as.^bs; +%! fv = af.^bf; +%! idx = find (af!=0); +%! assert(sv(:)(idx), sparse (fv(:)(idx)), 100*eps); + +EOF +} + +# test matrix-matrix left and right division: uses as,af,bs,bf +gen_divop_tests() { + cat <<EOF +%% Matrix-matrix operators (uses af,as,bs,bf) +%!assert (as/bf, af/bf, 100*eps) +%!assert (af/bs, af/bf, 100*eps) +%!assert (as/bs, sparse (af/bf), 100*eps) +%!assert (bs\af', bf\af', 100*eps) +%!assert (bf\as', bf\af', 100*eps) +%!assert (bs\as', sparse (bf\af'), 100*eps) + +EOF +} + +# test matrix-matrix left and right division: uses as,af,bs,bf +gen_square_divop_tests() { + cat <<EOF +%% Matrix-matrix operators (uses af,as,bs,bf) +%!assert (as/bf, af/bf, 100*eps) +%!assert (af/bs, af/bf, 100*eps) +%!assert (as/bs, sparse (af/bf), 100*eps) +%!assert (bs\af', bf\af', 100*eps) +%!assert (bf\as', bf\af', 100*eps) +%!assert (bs\as', sparse (bf\af'), 100*eps) + +EOF +} + +# test matrix-matrix operations: uses as,af,bs,bf +gen_matrixop_tests() { + cat <<EOF +%% Matrix-matrix operators (uses af,as,bs,bf) +%!assert (as*bf', af*bf') +%!assert (af*bs', af*bf') +%!assert (as*bs', sparse (af*bf')) + +EOF +} + +# test diagonal operations +gen_matrixdiag_tests() { + cat <<EOF +%% Matrix diagonal tests (uses af,as,bf,bs) +%!assert (diag (as), sparse (diag (af))) +%!assert (diag (bs), sparse (diag (bf))) +%!assert (diag (as,1), sparse (diag (af,1))) +%!assert (diag (bs,1), sparse (diag (bf,1))) +%!assert (diag (as,-1), sparse (diag (af,-1))) +%!assert (diag (bs,-1), sparse (diag (bf,-1))) +%!assert (diag (as(:)), sparse (diag (af(:)))) +%!assert (diag (as(:),1), sparse (diag (af(:),1))) +%!assert (diag (as(:),-1), sparse (diag (af(:),-1))) +%!assert (diag (as(:)'), sparse (diag (af(:)'))) +%!assert (diag (as(:)',1), sparse (diag (af(:)',1))) +%!assert (diag (as(:)',-1), sparse (diag (af(:)',-1))) +%!assert (spdiags (as,[0,1]), [diag(af,0), diag(af,1)]) +%!test +%! [tb,tc] = spdiags (as); +%! assert (spdiags (tb,tc,sparse (zeros (size (as)))), as); +%! assert (spdiags (tb,tc,size (as,1),size (as,2)), as); + +EOF +} + +# test matrix reshape operations +gen_matrixreshape_tests() { + cat <<EOF +%% Matrix diagonal tests (uses af,as,bf,bs) +%!assert (reshape (as,1,prod(size(as))), sparse (reshape (af,1,prod(size(af))))) +%!assert (reshape (as,prod(size(as)),1), sparse (reshape (af,prod(size(af)),1))) +%!assert (reshape (as,fliplr(size(as))), sparse (reshape (af,fliplr(size(af))))) +%!assert (reshape (bs,1,prod(size(as))), sparse (reshape (bf,1,prod(size(af))))) +%!assert (reshape (bs,prod(size(as)),1), sparse (reshape (bf,prod(size(af)),1))) +%!assert (reshape (bs,fliplr(size(as))), sparse (reshape (bf,fliplr(size(af))))) + +EOF +} + +# test mapper matrix operations: uses as,af +print_mapper_test() { +echo "%!assert ($1(as), sparse ($1(af)))" +} + +print_real_mapper_test() { + cat <<EOF +%!test +%! wn2s = warning ("query", "Octave:num-to-str"); +%! warning ("off", "Octave:num-to-str"); +%! if (isreal (af)) +%! if ($2) +%! assert ($1(as), sparse ($1(af))); +%! else +%! assert ($1(as), $1(af)); +%! endif +%! endif +%! warning (wn2s.state, "Octave:num-to-str"); + +EOF +} + +gen_mapper_tests() { +echo "%% Unary matrix tests (uses af,as)" +print_mapper_test abs +print_mapper_test acos +print_mapper_test acosh +print_mapper_test angle +print_mapper_test arg +print_mapper_test asin +print_mapper_test asinh +print_mapper_test atan +print_mapper_test atanh +print_mapper_test ceil +print_mapper_test conj +print_mapper_test cos +print_mapper_test cosh +print_mapper_test exp +print_mapper_test isfinite +print_mapper_test fix +print_mapper_test floor +print_mapper_test imag +print_mapper_test isinf +print_mapper_test isna +print_mapper_test isnan +print_mapper_test log +#print_mapper_test log10 ## fails with different NaN, not a problem +print_mapper_test real +print_mapper_test round +print_mapper_test sign +print_mapper_test sin +print_mapper_test sinh +print_mapper_test sqrt +print_mapper_test tan +print_mapper_test tanh + +# Specific tests for certain mapper functions + cat <<EOF +%!assert (issparse (abs (as)) && isreal (abs (as))) +%!assert (issparse (real (as)) && isreal (real (as))) +%!assert (issparse (imag (as)) && isreal (imag (as))) + +EOF +} + +gen_real_mapper_tests() { +echo "%% Unary matrix tests (uses af,as)" +print_real_mapper_test erf 1 +print_real_mapper_test erfc 1 +#print_real_mapper_test gamma 1 +print_real_mapper_test isalnum 0 +print_real_mapper_test isalpha 0 +print_real_mapper_test isascii 0 +print_real_mapper_test iscntrl 0 +print_real_mapper_test isdigit 0 +print_real_mapper_test isgraph 0 +print_real_mapper_test islower 0 +print_real_mapper_test isprint 0 +print_real_mapper_test ispunct 0 +print_real_mapper_test isspace 0 +print_real_mapper_test isupper 0 +print_real_mapper_test isxdigit 0 +#print_real_mapper_test gammaln 1 + +# Specific tests for certain mapper functions + cat <<EOF + +%!test +%! wn2s = warning ("query", "Octave:num-to-str"); +%! warning ("off", "Octave:num-to-str"); +%! if (isreal (af)) +%! assert (toascii (as), toascii (af)); +%! assert (tolower (as), as); +%! assert (toupper (as), as); +%! endif +%! warning (wn2s.state, "Octave:num-to-str"); + +EOF +} + +# test matrix operations: uses as,af +gen_unaryop_tests() { + cat <<EOF +%% Unary matrix tests (uses af,as) +%!assert (issparse (as)) +%!assert (!issparse (af)) +%!assert (! (issparse (af) && iscomplex (af))) +%!assert (! (issparse (af) && isreal (af))) +%!assert (sum (as), sparse (sum (af))) +%!assert (sum (as,1), sparse (sum (af,1))) +%!assert (sum (as,2), sparse (sum (af,2))) +%!assert (cumsum (as), sparse (cumsum (af))) +%!assert (cumsum (as,1), sparse (cumsum (af,1))) +%!assert (cumsum (as,2), sparse (cumsum (af,2))) +%!assert (sumsq (as), sparse (sumsq (af))) +%!assert (sumsq (as,1), sparse (sumsq (af,1))) +%!assert (sumsq (as,2), sparse (sumsq (af,2))) +%!assert (prod (as), sparse (prod (af))) +%!assert (prod (as,1), sparse (prod (af,1))) +%!assert (prod (as,2), sparse (prod (af,2))) +%!assert (cumprod (as), sparse (cumprod (af))) +%!assert (cumprod (as,1), sparse (cumprod (af,1))) +%!assert (cumprod (as,2), sparse (cumprod (af,2))) + +%!assert (min (as), sparse (min (af))) +%!assert (full (min (as(:))), min (af(:))) +%!assert (min (as,[],1), sparse (min (af,[],1))) +%!assert (min (as,[],2), sparse (min (af,[],2))) +%!assert (min (as,[],1), sparse (min (af,[],1))) +%!assert (min (as,0), sparse (min (af,0))) +%!assert (min (as,bs), sparse (min (af,bf))) +%!assert (max (as), sparse (max (af))) +%!assert (full (max (as(:))), max (af(:))) +%!assert (max (as,[],1), sparse (max (af,[],1))) +%!assert (max (as,[],2), sparse (max (af,[],2))) +%!assert (max (as,[],1), sparse (max (af,[],1))) +%!assert (max (as,0), sparse (max (af,0))) +%!assert (max (as,bs), sparse (max (af,bf))) + +%!assert (as==as) +%!assert (as==af) +%!assert (af==as) +%!test +%! [ii,jj,vv,nr,nc] = find (as); +%! assert (af, full (sparse (ii,jj,vv,nr,nc))); +%!assert (nnz (as), sum (af(:)!=0)) +%!assert (nnz (as), nnz (af)) +%!assert (issparse (as.')) +%!assert (issparse (as')) +%!assert (issparse (-as)) +%!assert (!as, sparse (!af)) +%!assert (as.', sparse (af.')) +%!assert (as', sparse (af')) +%!assert (-as, sparse (-af)) +%!assert (!as, sparse (!af)) +%!error [i,j] = size (af);as(i-1,j+1); +%!error [i,j] = size (af);as(i+1,j-1); +%!test +%! [Is,Js,Vs] = find (as); +%! [If,Jf,Vf] = find (af); +%! assert (Is, If); +%! assert (Js, Jf); +%! assert (Vs, Vf); +%!error as(0,1) +%!error as(1,0) +%!assert (find (as), find (af)) +%!test +%! [i,j,v] = find (as); +%! [m,n] = size (as); +%! x = sparse (i,j,v,m,n); +%! assert (x, as); +%!test +%! [i,j,v,m,n] = find (as); +%! x = sparse (i,j,v,m,n); +%! assert (x, as); +%!assert (issparse (horzcat (as,as))) +%!assert (issparse (vertcat (as,as))) +%!assert (issparse (cat (1,as,as))) +%!assert (issparse (cat (2,as,as))) +%!assert (issparse ([as,as])) +%!assert (issparse ([as;as])) +%!assert (horzcat (as,as), sparse ([af,af])) +%!assert (vertcat (as,as), sparse ([af;af])) +%!assert (horzcat (as,as,as), sparse ([af,af,af])) +%!assert (vertcat (as,as,as), sparse ([af;af;af])) +%!assert ([as,as], sparse ([af,af])) +%!assert ([as;as], sparse ([af;af])) +%!assert ([as,as,as], sparse ([af,af,af])) +%!assert ([as;as;as], sparse ([af;af;af])) +%!assert (cat (2,as,as), sparse ([af,af])) +%!assert (cat (1,as,as), sparse ([af;af])) +%!assert (cat (2,as,as,as), sparse ([af,af,af])) +%!assert (cat (1,as,as,as), sparse ([af;af;af])) +%!assert (issparse ([as,af])) +%!assert (issparse ([af,as])) +%!assert ([as,af], sparse ([af,af])) +%!assert ([as;af], sparse ([af;af])) + +EOF +} + +# operations which require square matrices. +gen_square_tests() { +# The \ and / operator tests on square matrices + gen_square_divop_tests + + cat <<EOF +%!testif HAVE_UMFPACK +%! assert(det(bs+speye(size(bs))), det(bf+eye(size(bf))), 100*eps*abs(det(bf+eye(size(bf))))); + +%!testif HAVE_UMFPACK +%! [l,u] = lu (sparse ([1,1;1,1])); +%! assert (l*u, [1,1;1,1], 10*eps); + +%!testif HAVE_UMFPACK +%! [l,u] = lu (sparse ([1,1;1,1+i])); +%! assert (l, sparse ([1,2,2],[1,1,2],1), 10*eps); +%! assert (u, sparse ([1,1,2],[1,2,2],[1,1,1i]), 10*eps); + +%!testif HAVE_UMFPACK # permuted LU +%! [L,U] = lu (bs); +%! assert (L*U, bs, 1e-10); + +%!testif HAVE_UMFPACK # simple LU + row permutations +%! [L,U,P] = lu (bs); +%! assert (P'*L*U, bs, 1e-10); +%! ## triangularity +%! [i,j,v] = find (L); +%! assert (i-j>=0); +%! [i,j,v] = find (U); +%! assert (j-i>=0); + +%!testif HAVE_UMFPACK # simple LU + row/col permutations +%! [L,U,P,Q] = lu (bs); +%! assert (P'*L*U*Q', bs, 1e-10); +%! ## triangularity +%! [i,j,v] = find (L); +%! assert (i-j>=0); +%! [i,j,v] = find (U); +%! assert (j-i>=0); + +%!testif HAVE_UMFPACK # LU with vector permutations +%! [L,U,P,Q] = lu (bs,'vector'); +%! assert (L(P,:)*U(:,Q), bs, 1e-10); +%! ## triangularity +%! [i,j,v] = find (L); +%! assert (i-j>=0); +%! [i,j,v] = find (U); +%! assert (j-i>=0); + +%!testif HAVE_UMFPACK # LU with scaling +%! [L,U,P,Q,R] = lu (bs); +%! assert (R*P'*L*U*Q', bs, 1e-10); +%! ## triangularity +%! [i,j,v] = find (L); +%! assert (i-j>=0); +%! [i,j,v] = find (U); +%! assert (j-i>=0); + +%!testif HAVE_UMFPACK # inverse +%! assert (inv (bs)*bs, sparse (eye (rows (bs))), 1e-10); + +%!assert (bf\as', bf\af', 100*eps) +%!assert (bs\af', bf\af', 100*eps) +%!assert (bs\as', sparse (bf\af'), 100*eps) + +EOF +} + +# Cholesky tests +gen_cholesky_tests() { + cat <<EOF +%!testif HAVE_CHOLMOD +%! assert (chol (bs)'*chol (bs), bs, 1e-10); +%!testif HAVE_CHOLMOD +%! assert (chol (bs,'lower')*chol (bs,'lower')', bs, 1e-10); +%!testif HAVE_CHOLMOD +%! assert (chol (bs,'lower'), chol (bs)', 1e-10); + +%!testif HAVE_CHOLMOD # Return Partial Cholesky factorization +%! [RS,PS] = chol (bs); +%! assert (RS'*RS, bs, 1e-10); +%! assert (PS, 0); +%! [LS,PS] = chol (bs,'lower'); +%! assert (LS*LS', bs, 1e-10); +%! assert (PS, 0); + +%!testif HAVE_CHOLMOD # Permuted Cholesky factorization +%! [RS,PS,QS] = chol (bs); +%! assert (RS'*RS, QS*bs*QS', 1e-10); +%! assert (PS, 0); +%! [LS,PS,QS] = chol (bs,'lower'); +%! assert (LS*LS', QS*bs*QS', 1e-10); +%! assert (PS, 0); + +EOF +} + +# test scalar operations: uses af and real scalar bf; modifies as,bf,bs +gen_scalar_tests() { + echo '%!test as = sparse (af);' + echo '%!test bs = bf;' + gen_elementop_tests + gen_ordering_tests + echo '%!test bf = bf+1i;' + echo '%!test bs = bf;' + gen_elementop_tests +} + +# test matrix operations: uses af and bf; modifies as,bs +gen_rectangular_tests() { + echo '%!test as = sparse(af);' + echo '%!test bs = sparse(bf);' + gen_mapper_tests + gen_real_mapper_tests + gen_unaryop_tests + gen_elementop_tests + gen_sparsesparse_elementop_tests + gen_matrixop_tests + # gen_divop_tests # Disable rectangular \ and / for now + gen_matrixdiag_tests + gen_matrixreshape_tests + cat <<EOF +%!testif HAVE_UMFPACK # permuted LU +%! [L,U] = lu (bs); +%! assert (L*U, bs, 1e-10); + +%!testif HAVE_UMFPACK # simple LU + row permutations +%! [L,U,P] = lu (bs); +%! assert (P'*L*U, bs, 1e-10); +%! ## triangularity +%! [i,j,v] = find (L); +%! assert (i-j>=0); +%! [i,j,v] = find (U); +%! assert (j-i>=0); + +%!testif HAVE_UMFPACK # simple LU + row/col permutations +%! [L,U,P,Q] = lu (bs); +%! assert (P'*L*U*Q', bs, 1e-10); +%! ## triangularity +%! [i,j,v] = find (L); +%! assert (i-j>=0); +%! [i,j,v] = find (U); +%! assert (j-i>=0); + +%!testif HAVE_UMFPACK # LU with vector permutations +%! [L,U,P,Q] = lu (bs,'vector'); +%! assert (L (P,:)*U (:,Q), bs, 1e-10); +%! ## triangularity +%! [i,j,v] = find (L); +%! assert (i-j>=0); +%! [i,j,v] = find (U); +%! assert (j-i>=0); + +%!testif HAVE_UMFPACK # LU with scaling +%! [L,U,P,Q,R] = lu (bs); +%! assert (R*P'*L*U*Q', bs, 1e-10); +%! ## triangularity +%! [i,j,v] = find (L); +%! assert (i-j>=0); +%! [i,j,v] = find (U); +%! assert (j-i>=0); + +EOF +} + + +# ======================================================= +# sparse assembly tests + +gen_assembly_tests() { +cat <<EOF +%%Assembly tests +%!test +%! m = max ([m;r(:)]); +%! n = max ([n;c(:)]); +%! funiq = fsum = zeros (m,n); +%! funiq(r(:) + m*(c(:)-1) ) = ones (size (r(:))); +%! funiq = sparse (funiq); +%! for k=1:length (r) +%! fsum(r(k),c(k)) += 1; +%! endfor +%! fsum = sparse (fsum); +%!assert (sparse (r,c,1), sparse (fsum(1:max(r), 1:max(c)))) +%!assert (sparse (r,c,1,"sum"), sparse (fsum(1:max (r),1:max (c)))) +%!assert (sparse (r,c,1,"unique"), sparse (funiq(1:max (r),1:max (c)))) +%!assert (sparse (r,c,1,m,n), sparse (fsum)) +%!assert (sparse (r,c,1,m,n,"sum"), sparse (fsum)) +%!assert (sparse (r,c,1,m,n,"unique"), sparse (funiq)) + +%!assert (sparse (r,c,1i), sparse (fsum(1:max (r),1:max (c))*1i)) +%!assert (sparse (r,c,1i,"sum"), sparse (fsum(1:max (r),1:max (c))*1i)) +%!assert (sparse (r,c,1i,"unique"), sparse (funiq(1:max (r),1:max (c))*1i)) +%!assert (sparse (r,c,1i,m,n), sparse (fsum*1i)) +%!assert (sparse (r,c,1i,m,n,"sum"), sparse (fsum*1i)) +%!assert (sparse (r,c,1i,m,n,"unique"), sparse (funiq*1i)) + +%!test +%! if (issparse (funiq)) +%! assert (sparse (full (1i*funiq)), sparse (1i*funiq)); +%! endif + +%!assert (sparse (full (funiq)), funiq) + + +EOF +} + +# ======================================================= +# sparse selection tests + +gen_scalar_select_tests () { + cat <<EOF +%!assert (sparse (42)([1,1]), sparse ([42,42])) +%!assert (sparse (42*1i)([1,1]), sparse ([42,42].*1i)) +EOF +} + +gen_select_tests() { + cat <<EOF +%!test as = sparse (af); + +%% Point tests +%!test idx = ridx(:) + rows (as) * (cidx (:)-1); +%!assert (sparse (as(idx)), sparse (af(idx))) +%!assert (as(idx), sparse (af(idx))) +%!assert (as(idx'), sparse (af(idx'))) +%!assert (as(flipud (idx(:))), sparse (af(flipud (idx(:))))) +%!assert (as([idx,idx]), sparse (af([idx,idx]))) +%!assert (as(reshape ([idx;idx], [1,length(idx),2])), sparse(af(reshape ([idx;idx], [1,length(idx),2])))) + +%% Slice tests +%!assert (as(ridx,cidx), sparse (af(ridx,cidx))) +%!assert (as(ridx,:), sparse (af(ridx,:))) +%!assert (as(:,cidx), sparse (af(:,cidx))) +%!assert (as(:,:), sparse (af(:,:))) +%!assert (as((size (as,1):-1:1),:), sparse (af((size (af,1):-1:1),:))) +%!assert (as(:,(size (as,2):-1:1)), sparse (af(:, (size (af,2):-1:1)))) + +%% Indexing tests +%!assert (full (as([1,1],:)), af([1,1],:)) +%!assert (full (as(:,[1,1])), af(:,[1,1])) +%!test +%! [i,j,v] = find (as); +%! assert (as(i(1),j(1))([1,1]), sparse ([v(1), v(1)])); + +%% Assignment test +%!test +%! ts = as; ts(:,:) = ts(fliplr (1:size (as,1)),:); +%! tf = af; tf(:,:) = tf(fliplr (1:size (af,1)),:); +%! assert (ts, sparse (tf)); +%!test +%! ts = as; ts(fliplr (1:size (as,1)),:) = ts; +%! tf = af; tf(fliplr (1:size (af,1)),:) = tf; +%! assert (ts, sparse (tf)); +%!test +%! ts = as; ts(:,fliplr (1:size (as,2))) = ts; +%! tf = af; tf(:,fliplr (1:size (af,2))) = tf; +%! assert (ts, sparse (tf)); +%!test +%! ts(fliplr (1:size (as,1))) = as(:,1); +%! tf(fliplr (1:size (af,1))) = af(:,1); +%! assert (ts, sparse (tf)); + +%% Deletion tests +%!test +%! ts = as; ts(1,:) = []; tf = af; tf(1,:) = []; +%! assert (ts, sparse (tf)); +%!test +%! ts = as; ts(:,1) = []; tf = af; tf(:,1) = []; +%! assert (ts, sparse (tf)); + +%% Test "end" keyword +%!assert (full (as(end)), af(end)) +%!assert (full (as(1,end)), af(1,end)) +%!assert (full (as(end,1)), af(end,1)) +%!assert (full (as(end,end)), af(end,end)) +%!assert (as(2:end,2:end), sparse (af(2:end,2:end))) +%!assert (as(1:end-1,1:end-1), sparse (af(1:end-1,1:end-1))) +EOF +} + +# ======================================================= +# sparse save and load tests + +gen_save_tests() { + cat <<EOF +%!test # save ascii +%! savefile = tempname (); +%! as_save = as; +%! save ("-text", savefile, "bf", "as_save", "af"); +%! clear as_save; +%! load (savefile, "as_save"); +%! unlink (savefile); +%! assert (as_save, sparse (af)); +%!test # save binary +%! savefile = tempname (); +%! as_save = as; +%! save ("-binary", savefile, "bf", "as_save", "af"); +%! clear as_save; +%! load (savefile, "as_save"); +%! unlink (savefile); +%! assert (as_save, sparse (af)); +%!testif HAVE_HDF5 # save hdf5 +%! savefile = tempname (); +%! as_save = as; +%! save ("-hdf5", savefile, "bf", "as_save", "af"); +%! clear as_save; +%! load (savefile, "as_save"); +%! unlink (savefile); +%! assert (as_save, sparse (af)); +## FIXME: We should skip (or mark as a known bug) the test for +## saving sparse matrices to MAT files when using 64-bit indexing since +## that is not implemented yet. +%!test # save matlab +%! savefile = tempname (); +%! as_save = as; +%! save ("-mat", savefile, "bf", "as_save", "af"); +%! clear as_save; +%! load (savefile, "as_save"); +%! unlink (savefile); +%! assert (as_save, sparse (af)); +EOF +} + +# ============================================================= +# Specific solver tests for matrices that will test all of the solver +# code. Uses alpha and beta +gen_solver_tests() { + +if $preset; then + cat <<EOF +%! n=8; +%! lf=diag (1:n); lf(n-1,1)=0.5*alpha; lf(n,2)=0.25*alpha; ls=sparse (lf); +%! uf=diag (1:n); uf(1,n-1)=2*alpha; uf(2,n)=alpha; us=sparse (uf); +%! ts=spdiags (ones (n,3),-1:1,n,n) + diag (1:n); tf = full (ts); +EOF +else + cat <<EOF +%! n = floor (lognrnd (8,2)+1)'; +%! ls = tril (sprandn (8,8,0.2),-1).*alpha + n*speye (8); lf = full (ls); +%! us = triu (sprandn (8,8,0.2),1).*alpha + n*speye (8); uf = full (us); +%! ts = spdiags (randn (8,3),-1:1,8,8).*alpha; tf = full (ts); +EOF +fi + +cat <<EOF +%! df = diag (1:n).* alpha; ds = sparse (df); +%! pdf = df(randperm (n), randperm (n)); +%! pds = sparse (pdf); +%! plf = lf(randperm (n), randperm (n)); +%! pls = sparse (plf); +%! puf = uf(randperm (n), randperm (n)); +%! pus = sparse (puf); +%! bs = spdiags (repmat ([1:n]',1,4),-2:1,n,n).*alpha; +%! bf = full (bs); +%! cf = lf + lf'; cs = sparse (cf); +%! bcf = bf + bf'; bcs = sparse (bcf); +%! tcf = tf + tf'; tcs = sparse (tcf); +%! xf = diag (1:n) + fliplr (diag (1:n)).*beta; +%! xs = sparse (xf); +%!assert (ds\xf, df\xf, 1e-10) +%!assert (ds\xs, sparse (df\xf), 1e-10) +%!assert (pds\xf, pdf\xf, 1e-10) +%!assert (pds\xs, sparse (pdf\xf), 1e-10) +%!assert (ls\xf, lf\xf, 1e-10) +%!assert (sparse (ls\xs), sparse (lf\xf), 1e-10) +%!testif HAVE_UMFPACK +%! assert (pls\xf, plf\xf, 1e-10); +%!testif HAVE_UMFPACK +%! assert (sparse (pls\xs), sparse (plf\xf), 1e-10); +%!assert (us\xf, uf\xf, 1e-10) +%!assert (sparse (us\xs), sparse (uf\xf), 1e-10) +%!testif HAVE_UMFPACK +%! assert (pus\xf, puf\xf, 1e-10); +%!testif HAVE_UMFPACK +%! assert (sparse (pus\xs), sparse (puf\xf), 1e-10); +%!assert (bs\xf, bf\xf, 1e-10) +%!assert (sparse (bs\xs), sparse (bf\xf), 1e-10) +%!testif HAVE_UMFPACK +%! assert (cs\xf, cf\xf, 1e-10); +%!testif HAVE_UMFPACK +%! assert (sparse (cs\xs), sparse (cf\xf), 1e-10); +%!testif HAVE_UMFPACK +%! assert (bcs\xf, bcf\xf, 1e-10); +%!testif HAVE_UMFPACK +%! assert (sparse (bcs\xs), sparse (bcf\xf), 1e-10); +%!assert (ts\xf, tf\xf, 1e-10) +%!assert (sparse (ts\xs), sparse (tf\xf), 1e-10) +%!assert (tcs\xf, tcf\xf, 1e-10) +%!assert (sparse (tcs\xs), sparse (tcf\xf), 1e-10) + +EOF + +cat <<EOF +%% QR solver tests + +%!function f (a, sz, feps) +%! b = randn (sz); +%! x = a \ b; +%! assert (a * x, b, feps); +%! b = randn (sz) + 1i*randn (sz); +%! x = a \ b; +%! assert (a * x, b, feps); +%! b = sprandn (sz(1),sz(2),0.2); +%! x = a \ b; +%! assert (sparse (a * x), b, feps); +%! b = sprandn (sz(1),sz(2),0.2) + 1i*sprandn (sz(1),sz(2),0.2); +%! x = a \ b; +%! assert (sparse (a * x), b, feps); +%!endfunction +%!testif HAVE_UMFPACK +%! a = alpha*sprandn (10,11,0.2) + speye (10,11); +%! f (a,[10,2],1e-10); +%! ## Test this by forcing matrix_type, as can't get a certain +%! ## result for over-determined systems. +%! a = alpha*sprandn (10,10,0.2) + speye (10,10); +%! matrix_type (a, "Singular"); +%! f (a,[10,2],1e-10); + +%% Rectanguar solver tests that don't use QR + +%!test +%! ds = alpha * spdiags ([1:11]',0,10,11); +%! df = full (ds); +%! xf = beta * ones (10,2); +%! xs = speye (10,10); +%!assert (ds\xf, df\xf, 100*eps) +%!assert (ds\xs, sparse (df\xs), 100*eps) +%!test +%! pds = ds([2,1,3:10],:); +%! pdf = full (pds); +%!assert (pds\xf, pdf\xf, 100*eps) +%!assert (pds\xs, sparse (pdf\xs), 100*eps) +%!test +%! ds = alpha * spdiags ([1:11]',0,11,10); +%! df = full (ds); +%! xf = beta * ones (11,2); +%! xs = speye (11,11); +%!assert (ds\xf, df\xf, 100*eps) +%!assert (ds\xs, sparse (df\xs), 100*eps) +%!test +%! pds = ds([2,1,3:11],:); +%! pdf = full (pds); +%!assert (pds\xf, pdf\xf, 100*eps) +%!assert (pds\xs, sparse (pdf\xs), 100*eps) +%!test +%! us = alpha*[[speye(10,10);sparse(1,10)],[[1,1];sparse(9,2);[1,1]]]; +%!testif HAVE_UMFPACK +%! assert (us*(us\xf), xf, 100*eps); +%!testif HAVE_UMFPACK +%! assert (us*(us\xs), xs, 100*eps); +%!test +%! pus = us(:,[2,1,3:12]); +%!testif HAVE_UMFPACK +%! assert (pus*(pus\xf), xf, 100*eps); +%!testif HAVE_UMFPACK +%! assert (pus*(pus\xs), xs, 100*eps); +%!test +%! us = alpha*[speye(11,9),[1;sparse(8,1);1;0]]; +%!testif HAVE_CXSPARSE +%! [c,r] = qr (us, xf); +%! assert (us\xf, r\c, 100*eps); +%!testif HAVE_UMFPACK +%! [c,r] = qr (us, xs); +%! r = matrix_type (r, "Singular"); ## Force Matrix Type +%! assert (us\xs, r\c, 100*eps); +%!test +%! pus = us(:,[1:8,10,9]); +%!testif HAVE_UMFPACK +%! [c,r] = qr (pus, xf); +%! r = matrix_type (r, "Singular"); ## Force Matrix Type +%! assert (pus\xf, r\c, 100*eps); +%!testif HAVE_UMFPACK +%! [c,r] = qr (pus, xs); +%! r = matrix_type (r, "Singular"); ## Force Matrix Type +%! assert (pus\xs, r\c, 100*eps); +%!test +%! ls = alpha*[speye(9,11);[1, sparse(1,8),1,0]]; +%! xf = beta * ones (10,2); +%! xs = speye (10,10); +%!assert (ls*(ls\xf), xf, 100*eps) +%!assert (ls*(ls\xs), xs, 100*eps) +%!test +%! pls = ls([1:8,10,9],:); +%!assert (pls*(pls\xf), xf, 100*eps) +%!assert (pls*(pls\xs), xs, 100*eps) +%!test +%! ls = alpha*[speye(10,10), sparse(10,1);[1;1], sparse(2,9),[1;1]]; +%! xf = beta * ones (12,2); +%! xs = speye (12,12); +%!testif HAVE_UMFPACK +%! [c,r] = qr (ls, xf); +%! assert (ls\xf, r\c, 100*eps); +%!testif HAVE_UMFPACK +%! [c,r] = qr (ls, xs); +%! r = matrix_type (r, "Singular"); ## Force Matrix Type +%! assert (ls\xs, r\c, 100*eps); +%!testif HAVE_CXSPARSE +%! pls = ls(:,[1:8,10,9]); +%!testif HAVE_UMFPACK +%! [c,r] = qr (pls, xf); +%! r = matrix_type (r, "Singular"); ## Force Matrix Type +%! assert (pls\xf, r\c, 100*eps); +%!testif HAVE_UMFPACK +%! [c,r] = qr (pls, xs); +%! r = matrix_type (r, "Singular"); ## Force Matrix Type +%! assert (pls\xs, r\c, 100*eps); + +EOF +} + + +# ============================================================= +# Putting it all together: defining the combined tests + + +# initial function +gen_function +gen_section + +# specific tests +if $preset; then + gen_specific_tests + gen_section +fi + +# scalar operations +echo '%!shared as,af,bs,bf' +if $preset; then + echo '%!test af=[1+1i,2-1i,0,0;0,0,0,3+2i;0,0,0,4];' + echo '%!test bf=3;' +else + cat <<EOF +%!test +%! % generate m,n from 1 to <5000 +%! m = floor (lognrnd (8,2)+1); +%! n = floor (lognrnd (8,2)+1); +%! as = sprandn (m,n,0.3); +%! af = full (as + 1i*sprandn (as)); +%! bf = randn; +EOF +fi + +gen_scalar_tests +gen_section + +# rectangular operations +if $preset; then + echo '%!test af=[1+1i,2-1i,0,0;0,0,0,3+2i;0,0,0,4];' + echo '%!test bf=[0,1-1i,0,0;2+1i,0,0,0;3-1i,2+3i,0,0];' +else + cat <<EOF +%!test +%! m = floor (lognrnd (8,2)+1); +%! n = floor (lognrnd (8,2)+1); +%! as = sprandn (m,n,0.3); +%! af = full (as + 1i*sprandn (as)); +%! bs = sprandn (m,n,0.3); +%! bf = full (bs + 1i*sprandn (bs)); +EOF +fi + +gen_rectangular_tests +gen_section +gen_save_tests +gen_section +echo '%!test bf = real (bf);' +gen_rectangular_tests +gen_section +gen_sparsesparse_ordering_tests +gen_section +echo '%!test af = real (af);' +gen_rectangular_tests +gen_section +gen_save_tests +gen_section +echo '%!test bf = bf+1i*(bf!=0);' +gen_rectangular_tests +gen_section + +# square operations +if $preset; then + echo '%!test af = [1+1i,2-1i,0,0;0,0,0,3+2i;0,0,0,4];' + echo '%! as = sparse (af);' + echo '%!test bf = [0,1-1i,0,0;2+1i,0,0,0;3-1i,2+3i,0,0];' +else + cat <<EOF +%!test +%! m = floor (lognrnd (8,2)+1); +%! n = floor (lognrnd (8,2)+1); +%! as = sprandn (m,n,0.3); +%! af = full (as + 1i*sprandn (as)); +%! bs = sprandn (m,n,0.3); +%! bf = full (bs + 1i*sprandn (bs)); +EOF +fi + +cat <<EOF +%!test ;# invertible matrix +%! bf = af'*bf+max (abs ([af(:);bf(:)]))*sparse (eye (columns (as))); +%! bs = sparse (bf); + +EOF + +gen_square_tests +gen_section +echo '%!test bf = real (bf);' +echo '%! bs = sparse (bf);' +gen_square_tests +gen_section +echo '%!test af = real (af);' +echo '%! as = sparse (af);' +gen_square_tests +gen_section +echo '%!test bf = bf+1i*(bf!=0);' +echo '%! bs = sparse (bf);' +gen_square_tests +gen_section + +# cholesky tests +if $preset; then + echo '%!test bf = [5,0,1+1i,0;0,5,0,1-2i;1-1i,0,5,0;0,1+2i,0,5];' + echo '%! bs = sparse (bf);' +else + echo '# This has a small chance of failing to create a positive definite matrix' + echo '%!test n = floor (lognrnd (8,2)+1)' + echo '%! bs = n*speye (n,n) + sprandn (n,n,0.3);' + echo '%! bf = full (bs);' +fi + +gen_cholesky_tests +gen_section +echo '%!test bf = real (bf);' +echo '%! bs = sparse (bf);' +gen_cholesky_tests +gen_section + +# assembly tests +echo '%!shared r,c,m,n,fsum,funiq' +if $use_preset; then + cat <<EOF +%!test +%! r = [1,1,2,1,2,3]; +%! c = [2,1,1,1,2,1]; +%! m = n = 0; +EOF +else + cat <<EOF +%!test +%! % generate m,n from 1 to <5000 +%! m = floor (lognrnd (8,2)+1); +%! n = floor (lognrnd (8,2)+1); +%! nz = ceil ((m+n)/2); +%! r = floor (rand (5,nz)*n)+1; +%! c = floor (rand (5,nn)*m)+1; +EOF +fi +gen_assembly_tests #includes real and complex tests +gen_section + +# slicing tests +echo '%!shared ridx,cidx,idx,as,af' +if $use_preset; then + cat <<EOF +%!test +%! af = [1+1i,2-1i,0,0;0,0,0,3+2i;0,0,0,4]; +%! ridx = [1,3]; +%! cidx = [2,3]; +EOF +else + cat <<EOF +%!test +%! % generate m,n from 1 to <5000 +%! m = floor (lognrnd (8,2)+1); +%! n = floor (lognrnd (8,2)+1); +%! as = sprandn (m,n,0.3); +%! af = full (as + 1i*sprandn (as)); +%! ridx = ceil (m*rand (1,ceil (rand*m)); +%! cidx = ceil (n*rand (1,ceil (rand*n)); +EOF +fi +gen_scalar_select_tests +gen_select_tests +echo '%!test af = real (af);' +gen_select_tests +gen_section +echo '%!shared alpha,beta,df,pdf,lf,plf,uf,puf,bf,cf,bcf,tf,tcf,xf,ds,pds,ls,pls,us,pus,bs,cs,bcs,ts,tcs,xs' +echo '%!test alpha=1; beta=1;' +gen_solver_tests +echo '%!test alpha=1; beta=1i;' +gen_solver_tests +echo '%!test alpha=1i; beta=1;' +gen_solver_tests +echo '%!test alpha=1i; beta=1i;' +gen_solver_tests +gen_section
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/mk_bc_overloads_expected.m Tue Jun 27 18:30:12 2017 -0400 @@ -0,0 +1,35 @@ +% this script is intended to be Matlab compatible +% first, run the script +% +% ./build_bc_overloads_tests.sh overloads_only +% +% to generate the overloaded functions. +% +ex.double = 1; +ex.single = single (1); +ex.logical = true; +ex.char = 'char'; +ex.int8 = int8 (1); +ex.int16 = int16 (1); +ex.int32 = int32 (1); +ex.int64 = int64 (1); +ex.uint8 = uint8 (1); +ex.uint16 = uint16 (1); +ex.uint32 = uint32 (1); +ex.uint64 = uint64 (1); +ex.cell = {}; +ex.struct = struct (); +ex.function_handle = @numel; + +f = fieldnames (ex); +n = numel (f); + +fid = fopen ('bc_overloads_expected','w'); +fid +for i = 1:n + for j = 1:n + s = tbcover (ex.(f{i}), ex.(f{j})); + fprintf (fid, '%s %s %s\n', f{i}, f{j}, s); + end +end +fclose (fid)
--- a/test/module.mk Tue Jun 27 15:10:58 2017 -0400 +++ b/test/module.mk Tue Jun 27 18:30:12 2017 -0400 @@ -115,27 +115,27 @@ @echo "" .PHONY: coverage -%reldir%/sparse.tst: %reldir%/build-sparse-tests.sh | %reldir%/$(octave_dirstamp) +%reldir%/sparse.tst: %reldir%/mk-sparse-tst.sh | %reldir%/$(octave_dirstamp) $(AM_V_GEN)rm -f $@-t $@ && \ - $(SHELL) $(srcdir)/%reldir%/build-sparse-tests.sh > $@-t && \ + $(SHELL) $(srcdir)/%reldir%/mk-sparse-tst.sh > $@-t && \ mv $@-t $@ -%reldir%/conv.tst: %reldir%/build-conv-tests.sh | %reldir%/$(octave_dirstamp) +%reldir%/conv.tst: %reldir%/mk-conv-tst.sh | %reldir%/$(octave_dirstamp) $(AM_V_GEN)rm -f $@-t $@ && \ - $(SHELL) $(srcdir)/%reldir%/build-conv-tests.sh > $@-t && \ + $(SHELL) $(srcdir)/%reldir%/mk-conv-tst.sh > $@-t && \ mv $@-t $@ GENERATED_BC_OVERLOADS_DIRS := \ - $(shell $(SHELL) $(srcdir)/%reldir%/build-bc-overload-tests.sh test --list-dirs) + $(shell $(SHELL) $(srcdir)/%reldir%/mk-bc-overloads-tst.sh test --list-dirs) GENERATED_BC_OVERLOADS_FILES := \ - $(shell $(SHELL) $(srcdir)/%reldir%/build-bc-overload-tests.sh test --list-files) + $(shell $(SHELL) $(srcdir)/%reldir%/mk-bc-overloads-tst.sh test --list-files) -$(GENERATED_BC_OVERLOADS_FILES): %reldir%/.bc-overload-tests-stamp +$(GENERATED_BC_OVERLOADS_FILES): %reldir%/mk-bc-overloads-tst-stamp -%reldir%/.bc-overload-tests-stamp: %reldir%/build-bc-overload-tests.sh %reldir%/bc-overloads-expected | %reldir%/$(octave_dirstamp) +%reldir%/.bc-overload-tests-stamp: %reldir%/mk-bc-overloads-tst.sh %reldir%/bc-overloads-expected | %reldir%/$(octave_dirstamp) $(AM_V_GEN)rm -f $@ && \ - $(SHELL) $(srcdir)/%reldir%/build-bc-overload-tests.sh test $(srcdir)/%reldir%/bc-overloads-expected && \ + $(SHELL) $(srcdir)/%reldir%/mk-bc-overloads-tst.sh test $(srcdir)/%reldir%/bc-overloads-expected && \ touch $@ GENERATED_TEST_FILES = \ @@ -174,11 +174,11 @@ BUILT_SOURCES += $(GENERATED_TEST_FILES) %canon_reldir%_EXTRA_DIST += \ - %reldir%/build-conv-tests.sh \ - %reldir%/build-sparse-tests.sh \ - %reldir%/build-bc-overload-tests.sh \ %reldir%/bc-overloads-expected \ - %reldir%/build_bc_overloads_expected.m \ + %reldir%/mk-bc-overloads-tst.sh \ + %reldir%/mk-conv-tst.sh \ + %reldir%/mk-sparse-tst.sh \ + %reldir%/mk_bc_overloads_expected.m \ %reldir%/show-failures.awk \ $(TEST_FILES)