# HG changeset patch # User jwe # Date 765932488 0 # Node ID e3228e053d063ce2293ff32faee0009be53c971d # Parent 167ea9ebd5a092d2a837c69fd215716835aa3580 [project @ 1994-04-09 23:01:20 by jwe] diff -r 167ea9ebd5a0 -r e3228e053d06 src/pt-const.h --- a/src/pt-const.h Wed Apr 06 18:41:44 1994 +0000 +++ b/src/pt-const.h Sat Apr 09 23:01:28 1994 +0000 @@ -77,7 +77,8 @@ // the tree_constant_rep class #define REP_RHS_MATRIX(tc,m,cm,nr,nc) \ - int nr, nc; \ + int nr = 0; \ + int nc = 0; \ Matrix m; \ ComplexMatrix cm; \ if ((tc).const_type () == tree_constant_rep::complex_matrix_constant) \ @@ -86,12 +87,14 @@ nr = (cm).rows (); \ nc = (cm).columns (); \ } \ - else \ + else if ((tc).const_type () == tree_constant_rep::matrix_constant) \ { \ m = (tc).matrix_value (); \ nr = (m).rows (); \ nc = (m).columns (); \ - } + } \ + else \ + abort (); // Assign a real or complex value to a tree_constant. // @@ -129,17 +132,11 @@ Matrix m; \ ComplexMatrix cm; \ if (type_tag == tree_constant_rep::matrix_constant) \ - { \ - (m).resize ((nr), (nc)); \ - } \ + (m).resize ((nr), (nc)); \ else if (type_tag == complex_matrix_constant) \ - { \ - (cm).resize ((nr), (nc)); \ - } \ + (cm).resize ((nr), (nc)); \ else \ - { \ - abort (); \ - } + abort (); \ // Assign a real or complex matrix to a tree constant. diff -r 167ea9ebd5a0 -r e3228e053d06 src/tc-assign.cc --- a/src/tc-assign.cc Wed Apr 06 18:41:44 1994 +0000 +++ b/src/tc-assign.cc Sat Apr 09 23:01:28 1994 +0000 @@ -1,7 +1,7 @@ // tc-assign.cc -*- C++ -*- /* -Copyright (C) 1992, 1993 John W. Eaton +Copyright (C) 1992, 1993, 1994 John W. Eaton This file is part of Octave. @@ -284,20 +284,36 @@ if (nr <= 1 || nc <= 1) { - maybe_resize (ii.max () - 1); + maybe_resize (ii.max ()); if (error_state) return; } - else if (range_max_check (ii.max () - 1, len) < 0) + else if (range_max_check (ii.max (), len) < 0) return; - if (ii.capacity () != rhs_nr * rhs_nc) + int ilen = ii.capacity (); + + if (ilen != rhs_nr * rhs_nc) { ::error ("A(matrix) = X: X and matrix must have the same number"); ::error ("of elements"); - return; } - fortran_style_matrix_assignment (rhs, ii); + else if (ilen == 1 && rhs.is_scalar_type ()) + { + int nr = rows (); + int idx = ii.elem (0); + int ii = fortran_row (idx + 1, nr) - 1; + int jj = fortran_column (idx + 1, nr) - 1; + + if (rhs.const_type () == scalar_constant) + matrix->elem (ii, jj) = rhs.double_value (); + else if (rhs.const_type () == complex_scalar_constant) + complex_matrix->elem (ii, jj) = rhs.complex_value (); + else + panic_impossible (); + } + else + fortran_style_matrix_assignment (rhs, ii); } break; case string_constant: @@ -506,7 +522,45 @@ else panic_impossible (); } - else + else if (rhs.is_scalar_type ()) + { + int nr = rows (); + int nc = columns (); + + if (iv.capacity () == 1) + { + int idx = iv.elem (0); + + if (nr == 1) + { + REP_ELEM_ASSIGN (0, idx, rhs.double_value (), + rhs.complex_value (), rhs.is_real_type ()); + } + else if (nc == 1) + { + REP_ELEM_ASSIGN (idx, 0, rhs.double_value (), + rhs.complex_value (), rhs.is_real_type ()); + } + else + panic_impossible (); + } + else + { + if (nr == 1) + { + ::error ("A(matrix) = X: where A is a row vector, X must also be a"); + ::error ("row vector with the same number of elements as matrix"); + } + else if (nc == 1) + { + ::error ("A(matrix) = X: where A is a column vector, X must also be a"); + ::error ("column vector with the same number of elements as matrix"); + } + else + panic_impossible (); + } + } + else if (rhs.is_matrix_type ()) { REP_RHS_MATRIX (rhs, rhs_m, rhs_cm, rhs_nr, rhs_nc); @@ -543,6 +597,8 @@ else panic_impossible (); } + else + panic_impossible (); } void @@ -570,7 +626,25 @@ else panic_impossible (); } - else + else if (rhs.is_scalar_type ()) + { + int nr = rows (); + int nc = columns (); + + if (nr == 1) + { + ::error ("A(range) = X: where A is a row vector, X must also be a"); + ::error ("row vector with the same number of elements as range"); + } + else if (nc == 1) + { + ::error ("A(range) = X: where A is a column vector, X must also be a"); + ::error ("column vector with the same number of elements as range"); + } + else + panic_impossible (); + } + else if (rhs.is_matrix_type ()) { REP_RHS_MATRIX (rhs, rhs_m, rhs_cm, rhs_nr, rhs_nc); @@ -618,14 +692,15 @@ else panic_impossible (); } + else + panic_impossible (); } void tree_constant_rep::fortran_style_matrix_assignment (tree_constant& rhs, tree_constant_rep::constant_type mci) { - assert (rhs.is_matrix_type ()); - assert (mci == tree_constant_rep::magic_colon); + assert (rhs.is_matrix_type () && mci == tree_constant_rep::magic_colon); int nr = rows (); int nc = columns (); @@ -1351,6 +1426,7 @@ idx_vector& jv) { REP_RHS_MATRIX (rhs, rhs_m, rhs_cm, rhs_nr, rhs_nc); + for (int j = 0; j < jv.capacity (); j++) REP_ELEM_ASSIGN (i, jv.elem (j), rhs_m.elem (0, j), rhs_cm.elem (0, j), rhs.is_real_type ()); @@ -1393,7 +1469,7 @@ REP_ELEM_ASSIGN (i, j, rhs_m.elem (0, j), rhs_cm.elem (0, j), rhs.is_real_type ()); } - else if (rhs.const_type () == scalar_constant && nc == 1) + else if (rhs.is_scalar_type () && nc == 1) { REP_ELEM_ASSIGN (i, 0, rhs.double_value (), rhs.complex_value (), rhs.is_real_type ()); @@ -1599,7 +1675,7 @@ REP_ELEM_ASSIGN (i, j, rhs_m.elem (i, 0), rhs_cm.elem (i, 0), rhs.is_real_type ()); } - else if (rhs.const_type () == scalar_constant && nr == 1) + else if (rhs.is_scalar_type () && nr == 1) { REP_ELEM_ASSIGN (0, j, rhs.double_value (), rhs.complex_value (), rhs.is_real_type ());