comparison src/pt-mat.cc @ 12048:4dc74edc8321 release-3-2-x

avoid complex -> real conversion when constructing arrays with []
author John W. Eaton <jwe@octave.org>
date Sat, 25 Jul 2009 16:26:01 +0200
parents e1695d65a5ca
children 34d6f005db4b
comparison
equal deleted inserted replaced
12047:e929449b9b03 12048:4dc74edc8321
39 #include "pt-walk.h" 39 #include "pt-walk.h"
40 #include "utils.h" 40 #include "utils.h"
41 #include "ov.h" 41 #include "ov.h"
42 #include "variables.h" 42 #include "variables.h"
43 43
44 #include "ov-cx-mat.h"
45 #include "ov-flt-cx-mat.h"
44 #include "ov-re-sparse.h" 46 #include "ov-re-sparse.h"
45 #include "ov-cx-sparse.h" 47 #include "ov-cx-sparse.h"
46 48
47 // The character to fill with when creating string arrays. 49 // The character to fill with when creating string arrays.
48 char Vstring_fill_char = ' '; 50 char Vstring_fill_char = ' ';
764 #define DO_SINGLE_TYPE_CONCAT(TYPE, EXTRACTOR) \ 766 #define DO_SINGLE_TYPE_CONCAT(TYPE, EXTRACTOR) \
765 do \ 767 do \
766 { \ 768 { \
767 TYPE result (dv); \ 769 TYPE result (dv); \
768 \ 770 \
769 SINGLE_TYPE_CONCAT(TYPE, EXTRACTOR); \ 771 SINGLE_TYPE_CONCAT (TYPE, EXTRACTOR); \
770 \ 772 \
771 retval = result; \ 773 retval = result; \
774 } \
775 while (0)
776
777 #define DO_SINGLE_TYPE_CONCAT_NO_MUTATE(TYPE, EXTRACTOR, OV_TYPE) \
778 do \
779 { \
780 TYPE result (dv); \
781 \
782 SINGLE_TYPE_CONCAT (TYPE, EXTRACTOR); \
783 \
784 retval = octave_value (new OV_TYPE (result)); \
772 } \ 785 } \
773 while (0) 786 while (0)
774 787
775 octave_value 788 octave_value
776 tree_matrix::rvalue1 (int) 789 tree_matrix::rvalue1 (int)
872 if (any_sparse_p) 885 if (any_sparse_p)
873 { 886 {
874 if (all_real_p) 887 if (all_real_p)
875 DO_SINGLE_TYPE_CONCAT (SparseMatrix, sparse_matrix_value); 888 DO_SINGLE_TYPE_CONCAT (SparseMatrix, sparse_matrix_value);
876 else 889 else
877 DO_SINGLE_TYPE_CONCAT (SparseComplexMatrix, sparse_complex_matrix_value); 890 DO_SINGLE_TYPE_CONCAT_NO_MUTATE (SparseComplexMatrix,
891 sparse_complex_matrix_value,
892 octave_sparse_complex_matrix);
878 } 893 }
879 else 894 else
880 { 895 {
881 if (all_real_p) 896 if (all_real_p)
882 DO_SINGLE_TYPE_CONCAT (NDArray, array_value); 897 DO_SINGLE_TYPE_CONCAT (NDArray, array_value);
883 else 898 else
884 DO_SINGLE_TYPE_CONCAT (ComplexNDArray, complex_array_value); 899 DO_SINGLE_TYPE_CONCAT_NO_MUTATE (ComplexNDArray,
900 complex_array_value,
901 octave_complex_matrix);
885 } 902 }
886 } 903 }
887 else if (result_type == "single") 904 else if (result_type == "single")
888 { 905 {
889 if (all_real_p) 906 if (all_real_p)
890 DO_SINGLE_TYPE_CONCAT (FloatNDArray, float_array_value); 907 DO_SINGLE_TYPE_CONCAT (FloatNDArray, float_array_value);
891 else 908 else
892 DO_SINGLE_TYPE_CONCAT (FloatComplexNDArray, 909 DO_SINGLE_TYPE_CONCAT_NO_MUTATE (FloatComplexNDArray,
893 float_complex_array_value); 910 float_complex_array_value,
911 octave_float_complex_matrix);
894 } 912 }
895 else if (result_type == "char") 913 else if (result_type == "char")
896 { 914 {
897 char type = all_dq_strings_p ? '"' : '\''; 915 char type = all_dq_strings_p ? '"' : '\'';
898 916