# HG changeset patch # User John W. Eaton # Date 1360458340 18000 # Node ID b8157404614f272dd978cae48bbdb969de082117 # Parent 85b8a1d435d65869553f435280d169c593dd21d8 fix file names * build-bc-overload-tests.sh: Rename from build_bc_overload_tests.sh. * bc-overloads-expected: Rename from bc_overloads_expected. * build-sparse-tests.sh: Rename from build_sparse_tests.sh. * Makefile.am: Update. diff -r 85b8a1d435d6 -r b8157404614f test/bc-overloads-expected --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/bc-overloads-expected Sat Feb 09 20:05:40 2013 -0500 @@ -0,0 +1,225 @@ +double double double +double single single +double logical double +double char double +double int8 int8 +double int16 int16 +double int32 int32 +double int64 int64 +double uint8 uint8 +double uint16 uint16 +double uint32 uint32 +double uint64 uint64 +double cell cell +double struct struct +double function_handle function_handle +single double single +single single single +single logical single +single char single +single int8 int8 +single int16 int16 +single int32 int32 +single int64 int64 +single uint8 uint8 +single uint16 uint16 +single uint32 uint32 +single uint64 uint64 +single cell cell +single struct struct +single function_handle function_handle +logical double double +logical single single +logical logical logical +logical char char +logical int8 int8 +logical int16 int16 +logical int32 int32 +logical int64 int64 +logical uint8 uint8 +logical uint16 uint16 +logical uint32 uint32 +logical uint64 uint64 +logical cell cell +logical struct struct +logical function_handle function_handle +char double char +char single single +char logical char +char char char +char int8 int8 +char int16 int16 +char int32 int32 +char int64 int64 +char uint8 uint8 +char uint16 uint16 +char uint32 uint32 +char uint64 uint64 +char cell cell +char struct struct +char function_handle function_handle +int8 double int8 +int8 single int8 +int8 logical int8 +int8 char int8 +int8 int8 int8 +int8 int16 int8 +int8 int32 int8 +int8 int64 int8 +int8 uint8 int8 +int8 uint16 int8 +int8 uint32 int8 +int8 uint64 int8 +int8 cell cell +int8 struct struct +int8 function_handle function_handle +int16 double int16 +int16 single int16 +int16 logical int16 +int16 char int16 +int16 int8 int16 +int16 int16 int16 +int16 int32 int16 +int16 int64 int16 +int16 uint8 int16 +int16 uint16 int16 +int16 uint32 int16 +int16 uint64 int16 +int16 cell cell +int16 struct struct +int16 function_handle function_handle +int32 double int32 +int32 single int32 +int32 logical int32 +int32 char int32 +int32 int8 int32 +int32 int16 int32 +int32 int32 int32 +int32 int64 int32 +int32 uint8 int32 +int32 uint16 int32 +int32 uint32 int32 +int32 uint64 int32 +int32 cell cell +int32 struct struct +int32 function_handle function_handle +int64 double int64 +int64 single int64 +int64 logical int64 +int64 char int64 +int64 int8 int64 +int64 int16 int64 +int64 int32 int64 +int64 int64 int64 +int64 uint8 int64 +int64 uint16 int64 +int64 uint32 int64 +int64 uint64 int64 +int64 cell cell +int64 struct struct +int64 function_handle function_handle +uint8 double uint8 +uint8 single uint8 +uint8 logical uint8 +uint8 char uint8 +uint8 int8 uint8 +uint8 int16 uint8 +uint8 int32 uint8 +uint8 int64 uint8 +uint8 uint8 uint8 +uint8 uint16 uint8 +uint8 uint32 uint8 +uint8 uint64 uint8 +uint8 cell cell +uint8 struct struct +uint8 function_handle function_handle +uint16 double uint16 +uint16 single uint16 +uint16 logical uint16 +uint16 char uint16 +uint16 int8 uint16 +uint16 int16 uint16 +uint16 int32 uint16 +uint16 int64 uint16 +uint16 uint8 uint16 +uint16 uint16 uint16 +uint16 uint32 uint16 +uint16 uint64 uint16 +uint16 cell cell +uint16 struct struct +uint16 function_handle function_handle +uint32 double uint32 +uint32 single uint32 +uint32 logical uint32 +uint32 char uint32 +uint32 int8 uint32 +uint32 int16 uint32 +uint32 int32 uint32 +uint32 int64 uint32 +uint32 uint8 uint32 +uint32 uint16 uint32 +uint32 uint32 uint32 +uint32 uint64 uint32 +uint32 cell cell +uint32 struct struct +uint32 function_handle function_handle +uint64 double uint64 +uint64 single uint64 +uint64 logical uint64 +uint64 char uint64 +uint64 int8 uint64 +uint64 int16 uint64 +uint64 int32 uint64 +uint64 int64 uint64 +uint64 uint8 uint64 +uint64 uint16 uint64 +uint64 uint32 uint64 +uint64 uint64 uint64 +uint64 cell cell +uint64 struct struct +uint64 function_handle function_handle +cell double cell +cell single cell +cell logical cell +cell char cell +cell int8 cell +cell int16 cell +cell int32 cell +cell int64 cell +cell uint8 cell +cell uint16 cell +cell uint32 cell +cell uint64 cell +cell cell cell +cell struct cell +cell function_handle function_handle +struct double struct +struct single struct +struct logical struct +struct char struct +struct int8 struct +struct int16 struct +struct int32 struct +struct int64 struct +struct uint8 struct +struct uint16 struct +struct uint32 struct +struct uint64 struct +struct cell struct +struct struct struct +struct function_handle function_handle +function_handle double function_handle +function_handle single function_handle +function_handle logical function_handle +function_handle char function_handle +function_handle int8 function_handle +function_handle int16 function_handle +function_handle int32 function_handle +function_handle int64 function_handle +function_handle uint8 function_handle +function_handle uint16 function_handle +function_handle uint32 function_handle +function_handle uint64 function_handle +function_handle cell function_handle +function_handle struct function_handle +function_handle function_handle function_handle diff -r 85b8a1d435d6 -r b8157404614f test/bc_overloads_expected --- a/test/bc_overloads_expected Sat Feb 09 19:54:05 2013 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,225 +0,0 @@ -double double double -double single single -double logical double -double char double -double int8 int8 -double int16 int16 -double int32 int32 -double int64 int64 -double uint8 uint8 -double uint16 uint16 -double uint32 uint32 -double uint64 uint64 -double cell cell -double struct struct -double function_handle function_handle -single double single -single single single -single logical single -single char single -single int8 int8 -single int16 int16 -single int32 int32 -single int64 int64 -single uint8 uint8 -single uint16 uint16 -single uint32 uint32 -single uint64 uint64 -single cell cell -single struct struct -single function_handle function_handle -logical double double -logical single single -logical logical logical -logical char char -logical int8 int8 -logical int16 int16 -logical int32 int32 -logical int64 int64 -logical uint8 uint8 -logical uint16 uint16 -logical uint32 uint32 -logical uint64 uint64 -logical cell cell -logical struct struct -logical function_handle function_handle -char double char -char single single -char logical char -char char char -char int8 int8 -char int16 int16 -char int32 int32 -char int64 int64 -char uint8 uint8 -char uint16 uint16 -char uint32 uint32 -char uint64 uint64 -char cell cell -char struct struct -char function_handle function_handle -int8 double int8 -int8 single int8 -int8 logical int8 -int8 char int8 -int8 int8 int8 -int8 int16 int8 -int8 int32 int8 -int8 int64 int8 -int8 uint8 int8 -int8 uint16 int8 -int8 uint32 int8 -int8 uint64 int8 -int8 cell cell -int8 struct struct -int8 function_handle function_handle -int16 double int16 -int16 single int16 -int16 logical int16 -int16 char int16 -int16 int8 int16 -int16 int16 int16 -int16 int32 int16 -int16 int64 int16 -int16 uint8 int16 -int16 uint16 int16 -int16 uint32 int16 -int16 uint64 int16 -int16 cell cell -int16 struct struct -int16 function_handle function_handle -int32 double int32 -int32 single int32 -int32 logical int32 -int32 char int32 -int32 int8 int32 -int32 int16 int32 -int32 int32 int32 -int32 int64 int32 -int32 uint8 int32 -int32 uint16 int32 -int32 uint32 int32 -int32 uint64 int32 -int32 cell cell -int32 struct struct -int32 function_handle function_handle -int64 double int64 -int64 single int64 -int64 logical int64 -int64 char int64 -int64 int8 int64 -int64 int16 int64 -int64 int32 int64 -int64 int64 int64 -int64 uint8 int64 -int64 uint16 int64 -int64 uint32 int64 -int64 uint64 int64 -int64 cell cell -int64 struct struct -int64 function_handle function_handle -uint8 double uint8 -uint8 single uint8 -uint8 logical uint8 -uint8 char uint8 -uint8 int8 uint8 -uint8 int16 uint8 -uint8 int32 uint8 -uint8 int64 uint8 -uint8 uint8 uint8 -uint8 uint16 uint8 -uint8 uint32 uint8 -uint8 uint64 uint8 -uint8 cell cell -uint8 struct struct -uint8 function_handle function_handle -uint16 double uint16 -uint16 single uint16 -uint16 logical uint16 -uint16 char uint16 -uint16 int8 uint16 -uint16 int16 uint16 -uint16 int32 uint16 -uint16 int64 uint16 -uint16 uint8 uint16 -uint16 uint16 uint16 -uint16 uint32 uint16 -uint16 uint64 uint16 -uint16 cell cell -uint16 struct struct -uint16 function_handle function_handle -uint32 double uint32 -uint32 single uint32 -uint32 logical uint32 -uint32 char uint32 -uint32 int8 uint32 -uint32 int16 uint32 -uint32 int32 uint32 -uint32 int64 uint32 -uint32 uint8 uint32 -uint32 uint16 uint32 -uint32 uint32 uint32 -uint32 uint64 uint32 -uint32 cell cell -uint32 struct struct -uint32 function_handle function_handle -uint64 double uint64 -uint64 single uint64 -uint64 logical uint64 -uint64 char uint64 -uint64 int8 uint64 -uint64 int16 uint64 -uint64 int32 uint64 -uint64 int64 uint64 -uint64 uint8 uint64 -uint64 uint16 uint64 -uint64 uint32 uint64 -uint64 uint64 uint64 -uint64 cell cell -uint64 struct struct -uint64 function_handle function_handle -cell double cell -cell single cell -cell logical cell -cell char cell -cell int8 cell -cell int16 cell -cell int32 cell -cell int64 cell -cell uint8 cell -cell uint16 cell -cell uint32 cell -cell uint64 cell -cell cell cell -cell struct cell -cell function_handle function_handle -struct double struct -struct single struct -struct logical struct -struct char struct -struct int8 struct -struct int16 struct -struct int32 struct -struct int64 struct -struct uint8 struct -struct uint16 struct -struct uint32 struct -struct uint64 struct -struct cell struct -struct struct struct -struct function_handle function_handle -function_handle double function_handle -function_handle single function_handle -function_handle logical function_handle -function_handle char function_handle -function_handle int8 function_handle -function_handle int16 function_handle -function_handle int32 function_handle -function_handle int64 function_handle -function_handle uint8 function_handle -function_handle uint16 function_handle -function_handle uint32 function_handle -function_handle uint64 function_handle -function_handle cell function_handle -function_handle struct function_handle -function_handle function_handle function_handle diff -r 85b8a1d435d6 -r b8157404614f test/build-bc-overload-tests.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/build-bc-overload-tests.sh Sat Feb 09 20:05:40 2013 -0500 @@ -0,0 +1,139 @@ +#! /bin/sh + +# Copyright (C) 2010-2012 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 +# . + +CLASSES=" + double + single + char + logical + int8 + int16 + int32 + int64 + uint8 + uint16 + uint32 + uint64 + struct + cell + function_handle +" + +if [ $# -eq 1 ]; then + case "$1" in + --list-files) + echo tbcover.m + echo test_bc_overloads.m + for class in $CLASSES; do + echo @$class/tbcover.m + done + exit + ;; + --list-dirs) + for class in $CLASSES; do + echo @$class + done + exit + ;; + --list-classes) + echo $CLASSES + exit + ;; + *) + expected_results_file="$1" + ;; + esac +else + echo "usage: build_bc_overload_tests.sh expected-results-file" 1>&2 + exit 1 +fi + +for class in $CLASSES; do + 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 > 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 > test_bc_overloads.m << 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 >> test_bc_overloads.m << EOF +%% Name call +%!assert (tbcover (ex.$cl1, ex.$cl2), "$clr") +%% Handle call +%!assert ((@tbcover) (ex.$cl1, ex.$cl2), "$clr") + +EOF +done + +cat >> test_bc_overloads.m << 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 diff -r 85b8a1d435d6 -r b8157404614f test/build-sparse-tests.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/build-sparse-tests.sh Sat Feb 09 20:05:40 2013 -0500 @@ -0,0 +1,1326 @@ +#!/bin/sh + +# Copyright (C) 2006-2012 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 +# . + +# Some tests are commented out because they are known to be broken! +# Search for "# fails" + +# ./build_sparse_tests.sh preset +# creates test_sparse.m with preset tests. +# Use "test test_sparse" from octave to run the tests. +# +# ./build_sparse_tests.sh random +# Creates test_sprandom.m with randomly generated matrices. +# Use "test test_sprandom" 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 + +if $preset; then + TESTS=test_sparse.m +else + TESTS=test_sprandom.m +fi + +# create initial file +cat >$TESTS <>$TESTS <>$TESTS <>$TESTS <> $TESTS + echo '%!test bf=realmin;' >> $TESTS + gen_eat_zeros + echo '%!test bf=realmin+realmin*1i;' >> $TESTS + gen_eat_zeros + cat >>$TESTS <>$TESTS <>$TESTS <>$TESTS <=bf, sparse (af>=bf)) +%!assert (bf>=as, sparse (bf>=af)) + +%!assert (asbf, sparse (af>bf)) +%!assert (bf>as, sparse (bf>af)) + +EOF +} + +gen_sparsesparse_ordering_tests() { + cat >>$TESTS <=bs, sparse (af>=bf)) +%!assert (asbs, sparse (af>bf)) +EOF +} + +# test element-wise binary operations: uses as,af,bs,bf,scalar +gen_elementop_tests() { + cat >>$TESTS <>$TESTS <>$TESTS <>$TESTS <>$TESTS <>$TESTS <>$TESTS <>$TESTS +} + +print_real_mapper_test() { + cat >>$TESTS <>$TESTS +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 finite +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 >>$TESTS <>$TESTS +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 lgamma 1 + +# Specific tests for certain mapper functions + cat >>$TESTS <>$TESTS <>$TESTS <=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 >>$TESTS <> $TESTS + echo '%!test bs=bf;' >> $TESTS + gen_elementop_tests + gen_ordering_tests + echo '%!test bf=bf+1i;' >>$TESTS + echo '%!test bs=bf;' >> $TESTS + gen_elementop_tests +} + +# test matrix operations: uses af and bf; modifies as,bs +gen_rectangular_tests() { + echo '%!test as=sparse(af);' >> $TESTS + echo '%!test bs=sparse(bf);' >>$TESTS + 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 >>$TESTS <=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 >>$TESTS <>$TESTS <>$TESTS <>$TESTS <>$TESTS <>$TESTS <>$TESTS <>$TESTS <> $TESTS +if $preset; then + echo '%!test af=[1+1i,2-1i,0,0;0,0,0,3+2i;0,0,0,4];' >> $TESTS + echo '%!test bf=3;' >>$TESTS +else + cat >>$TESTS <> $TESTS + echo '%!test bf=[0,1-1i,0,0;2+1i,0,0,0;3-1i,2+3i,0,0];' >> $TESTS +else + cat >>$TESTS <> $TESTS +gen_rectangular_tests +gen_section +gen_sparsesparse_ordering_tests +gen_section +echo '%!test af=real(af);' >> $TESTS +gen_rectangular_tests +gen_section +gen_save_tests +gen_section +echo '%!test bf=bf+1i*(bf~=0);' >> $TESTS +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];' >> $TESTS + echo '%! as=sparse(af);' >> $TESTS + echo '%!test bf=[0,1-1i,0,0;2+1i,0,0,0;3-1i,2+3i,0,0];' >> $TESTS +else + cat >>$TESTS <>$TESTS <> $TESTS +echo '%! bs=sparse(bf);' >> $TESTS +gen_square_tests +gen_section +echo '%!test af=real(af);' >> $TESTS +echo '%! as=sparse(af);' >> $TESTS +gen_square_tests +gen_section +echo '%!test bf=bf+1i*(bf~=0);' >> $TESTS +echo '%! bs=sparse(bf);' >> $TESTS +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];' >> $TESTS + echo '%! bs=sparse(bf);' >> $TESTS +else + echo '# This has a small chance of failing to create a positive definite matrix' >> $TESTS + echo '%!test n=floor (lognrnd (8,2)+1)' >> $TESTS + echo '%! bs = n*speye (n,n) + sprandn (n,n,0.3);' >> $TESTS + echo '%! bf = full (bs);' >> $TESTS +fi + +gen_cholesky_tests +gen_section +echo '%!test bf=real(bf);' >> $TESTS +echo '%! bs=sparse(bf);' >> $TESTS +gen_cholesky_tests +gen_section + +# assembly tests +echo '%!shared r,c,m,n,fsum,funiq' >>$TESTS +if $use_preset; then + cat >>$TESTS <>$TESTS <>$TESTS +if $use_preset; then + cat >>$TESTS <>$TESTS <> $TESTS +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' >>$TESTS +echo '%!test alpha=1;beta=1;' >> $TESTS +gen_solver_tests +echo '%!test alpha=1;beta=1i;' >> $TESTS +gen_solver_tests +echo '%!test alpha=1i;beta=1;' >> $TESTS +gen_solver_tests +echo '%!test alpha=1i;beta=1i;' >> $TESTS +gen_solver_tests +gen_section diff -r 85b8a1d435d6 -r b8157404614f test/build_bc_overload_tests.sh --- a/test/build_bc_overload_tests.sh Sat Feb 09 19:54:05 2013 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,139 +0,0 @@ -#! /bin/sh - -# Copyright (C) 2010-2012 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 -# . - -CLASSES=" - double - single - char - logical - int8 - int16 - int32 - int64 - uint8 - uint16 - uint32 - uint64 - struct - cell - function_handle -" - -if [ $# -eq 1 ]; then - case "$1" in - --list-files) - echo tbcover.m - echo test_bc_overloads.m - for class in $CLASSES; do - echo @$class/tbcover.m - done - exit - ;; - --list-dirs) - for class in $CLASSES; do - echo @$class - done - exit - ;; - --list-classes) - echo $CLASSES - exit - ;; - *) - expected_results_file="$1" - ;; - esac -else - echo "usage: build_bc_overload_tests.sh expected-results-file" 1>&2 - exit 1 -fi - -for class in $CLASSES; do - 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 > 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 > test_bc_overloads.m << 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 >> test_bc_overloads.m << EOF -%% Name call -%!assert (tbcover (ex.$cl1, ex.$cl2), "$clr") -%% Handle call -%!assert ((@tbcover) (ex.$cl1, ex.$cl2), "$clr") - -EOF -done - -cat >> test_bc_overloads.m << 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 diff -r 85b8a1d435d6 -r b8157404614f test/build_sparse_tests.sh --- a/test/build_sparse_tests.sh Sat Feb 09 19:54:05 2013 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1326 +0,0 @@ -#!/bin/sh - -# Copyright (C) 2006-2012 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 -# . - -# Some tests are commented out because they are known to be broken! -# Search for "# fails" - -# ./build_sparse_tests.sh preset -# creates test_sparse.m with preset tests. -# Use "test test_sparse" from octave to run the tests. -# -# ./build_sparse_tests.sh random -# Creates test_sprandom.m with randomly generated matrices. -# Use "test test_sprandom" 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 - -if $preset; then - TESTS=test_sparse.m -else - TESTS=test_sprandom.m -fi - -# create initial file -cat >$TESTS <>$TESTS <>$TESTS <>$TESTS <> $TESTS - echo '%!test bf=realmin;' >> $TESTS - gen_eat_zeros - echo '%!test bf=realmin+realmin*1i;' >> $TESTS - gen_eat_zeros - cat >>$TESTS <>$TESTS <>$TESTS <>$TESTS <=bf, sparse (af>=bf)) -%!assert (bf>=as, sparse (bf>=af)) - -%!assert (asbf, sparse (af>bf)) -%!assert (bf>as, sparse (bf>af)) - -EOF -} - -gen_sparsesparse_ordering_tests() { - cat >>$TESTS <=bs, sparse (af>=bf)) -%!assert (asbs, sparse (af>bf)) -EOF -} - -# test element-wise binary operations: uses as,af,bs,bf,scalar -gen_elementop_tests() { - cat >>$TESTS <>$TESTS <>$TESTS <>$TESTS <>$TESTS <>$TESTS <>$TESTS <>$TESTS -} - -print_real_mapper_test() { - cat >>$TESTS <>$TESTS -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 finite -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 >>$TESTS <>$TESTS -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 lgamma 1 - -# Specific tests for certain mapper functions - cat >>$TESTS <>$TESTS <>$TESTS <=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 >>$TESTS <> $TESTS - echo '%!test bs=bf;' >> $TESTS - gen_elementop_tests - gen_ordering_tests - echo '%!test bf=bf+1i;' >>$TESTS - echo '%!test bs=bf;' >> $TESTS - gen_elementop_tests -} - -# test matrix operations: uses af and bf; modifies as,bs -gen_rectangular_tests() { - echo '%!test as=sparse(af);' >> $TESTS - echo '%!test bs=sparse(bf);' >>$TESTS - 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 >>$TESTS <=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 >>$TESTS <>$TESTS <>$TESTS <>$TESTS <>$TESTS <>$TESTS <>$TESTS <>$TESTS <> $TESTS -if $preset; then - echo '%!test af=[1+1i,2-1i,0,0;0,0,0,3+2i;0,0,0,4];' >> $TESTS - echo '%!test bf=3;' >>$TESTS -else - cat >>$TESTS <> $TESTS - echo '%!test bf=[0,1-1i,0,0;2+1i,0,0,0;3-1i,2+3i,0,0];' >> $TESTS -else - cat >>$TESTS <> $TESTS -gen_rectangular_tests -gen_section -gen_sparsesparse_ordering_tests -gen_section -echo '%!test af=real(af);' >> $TESTS -gen_rectangular_tests -gen_section -gen_save_tests -gen_section -echo '%!test bf=bf+1i*(bf~=0);' >> $TESTS -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];' >> $TESTS - echo '%! as=sparse(af);' >> $TESTS - echo '%!test bf=[0,1-1i,0,0;2+1i,0,0,0;3-1i,2+3i,0,0];' >> $TESTS -else - cat >>$TESTS <>$TESTS <> $TESTS -echo '%! bs=sparse(bf);' >> $TESTS -gen_square_tests -gen_section -echo '%!test af=real(af);' >> $TESTS -echo '%! as=sparse(af);' >> $TESTS -gen_square_tests -gen_section -echo '%!test bf=bf+1i*(bf~=0);' >> $TESTS -echo '%! bs=sparse(bf);' >> $TESTS -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];' >> $TESTS - echo '%! bs=sparse(bf);' >> $TESTS -else - echo '# This has a small chance of failing to create a positive definite matrix' >> $TESTS - echo '%!test n=floor (lognrnd (8,2)+1)' >> $TESTS - echo '%! bs = n*speye (n,n) + sprandn (n,n,0.3);' >> $TESTS - echo '%! bf = full (bs);' >> $TESTS -fi - -gen_cholesky_tests -gen_section -echo '%!test bf=real(bf);' >> $TESTS -echo '%! bs=sparse(bf);' >> $TESTS -gen_cholesky_tests -gen_section - -# assembly tests -echo '%!shared r,c,m,n,fsum,funiq' >>$TESTS -if $use_preset; then - cat >>$TESTS <>$TESTS <>$TESTS -if $use_preset; then - cat >>$TESTS <>$TESTS <> $TESTS -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' >>$TESTS -echo '%!test alpha=1;beta=1;' >> $TESTS -gen_solver_tests -echo '%!test alpha=1;beta=1i;' >> $TESTS -gen_solver_tests -echo '%!test alpha=1i;beta=1;' >> $TESTS -gen_solver_tests -echo '%!test alpha=1i;beta=1i;' >> $TESTS -gen_solver_tests -gen_section