Mercurial > octave
annotate liboctave/array/Array-fC.cc @ 21573:f3f8e1d3e399 stable
avoid mulitple definitions of static function-scope vars (bug #47372)
Some systems (Windows, others?) may generate multiple definitions of
function-scope static variables if those functions appear in header
files. This can cause trouble in various ways. Attempt to avoid the
problem by moving functions that contain file-scope varaibles from
header files to source files, or by using class-scope static variables
instead. Also attempt to avoid similar problems caused by implicit
instantiations of templates that have functions with static variables.
* Cell.h, Cell.cc (Cell::resize_fill_value):
Move definition from header to source file.
* oct-map.h, oct-map.cc (octave_fields::nil_rep): Likewise.
* ov-base-scalar.h, ov-base-scalar.cc (octave_base_scalar<ST>::dims):
Likewise.
* ov-fcn-handle.h, ov-fcn-handle.cc (octave_fcn_handle::dims): Likewise.
* ov.h, ov.cc (octave_value::nil_rep): Likewise.
* Array.h, Array.cc (Array<T>::nil_rep): Likewise.
* DiagArray2.h, DiagArray2.cc (DiagArray2<T>::elem,
DiagArray2<T>::checkelem): Likewise.
* Sparse.h, Sparse.cc (Sparse<T>::nil_rep): Likewise.
* dim-vector.h, dim-vector.cc (dim_vector::nil_rep): Likewise.
* idx-vector.h, idx-vector.cc (idx_vector::nil_rep,
idx_vector::err_rep): Likewise.
* oct-inttypes.h, oct-inttypes.cc (octave_int_base<T>::convert_real):
Likewise.
* symtab.h, symtab.cc (octave_value symbol_table::dummy_octave_value,
symbol_table::symbol_record symbol_table::dummy_symbol_record): New
class-scope static variables. Use them to eliminate function-scope
static variables.
* ov-int8.cc, ov-int16.cc, ov-int32.cc, ov-int64.cc, ov-uint8.cc,
ov-uint16.cc, ov-uint32.cc, ov-uint64.cc, ov-scalar.cc,
ov-flt-complex.cc, ov-complex.cc, ov-classdef.cc, ov-bool.cc,
Array-jit.cc, Array-os.cc, Array-tc.cc, Array-C.cc, Array-b.cc,
Array-ch.cc, Array-d.cc, Array-f.cc, Array-fC.cc, Array-i.cc,
Array-idx-vec.cc, Array-s.cc, Array-str.cc, Array-voidp.cc:
Prevent impliticit template instantiation.
* Array-tc.cc: Also instantiate Array<cdef_object>.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 01 Apr 2016 12:04:04 -0400 |
parents | 40b2c4323c16 |
children | ae4d7dfea337 |
rev | line source |
---|---|
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1 /* |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2 |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19635
diff
changeset
|
3 Copyright (C) 1994-2015 John W. Eaton |
10521
4d1fc073fbb7
add some missing copyright stmts
Jaroslav Hajek <highegg@gmail.com>
parents:
10374
diff
changeset
|
4 Copyright (C) 2009 VZLU Prague |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
5 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
6 This file is part of Octave. |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
7 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
8 Octave is free software; you can redistribute it and/or modify it |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
9 under the terms of the GNU General Public License as published by the |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
10 Free Software Foundation; either version 3 of the License, or (at your |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
11 option) any later version. |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
12 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
16 for more details. |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
17 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
18 You should have received a copy of the GNU General Public License |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
19 along with Octave; see the file COPYING. If not, see |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
20 <http://www.gnu.org/licenses/>. |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
21 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
22 */ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
23 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
24 #ifdef HAVE_CONFIG_H |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
25 #include <config.h> |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
26 #endif |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
27 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
28 // Instantiate Arrays of FloatComplex values. |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
29 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
30 #include "oct-cmplx.h" |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
31 #include "lo-mappers.h" |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
32 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
33 #include "Array.h" |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
34 #include "Array.cc" |
8700 | 35 #include "oct-sort.cc" |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
36 |
21573
f3f8e1d3e399
avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents:
19966
diff
changeset
|
37 // Prevent implicit instantiations on some systems (Windows, others?) |
f3f8e1d3e399
avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents:
19966
diff
changeset
|
38 // that can lead to duplicate definitions of static data members. |
f3f8e1d3e399
avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents:
19966
diff
changeset
|
39 |
f3f8e1d3e399
avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents:
19966
diff
changeset
|
40 extern template class OCTAVE_API Array<idx_vector>; |
f3f8e1d3e399
avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents:
19966
diff
changeset
|
41 extern template class OCTAVE_API Array<octave_idx_type>; |
f3f8e1d3e399
avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents:
19966
diff
changeset
|
42 |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
43 template <> |
8725 | 44 inline bool |
45 sort_isnan<FloatComplex> (const FloatComplex& x) | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
46 { |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
47 return xisnan (x); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
48 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
49 |
19635
bdf90710dddf
Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
19634
diff
changeset
|
50 // Sort Criteria: 1) isnan, 2) magnitude of z, 3) phase of z in range (-pi, pi] |
bdf90710dddf
Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
19634
diff
changeset
|
51 |
8725 | 52 static bool |
53 nan_ascending_compare (const FloatComplex& x, const FloatComplex& y) | |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
54 { |
19966
40b2c4323c16
avoid some code duplication in complex comparison functions (bug #44206)
John W. Eaton <jwe@octave.org>
parents:
19923
diff
changeset
|
55 return xisnan (y) ? ! xisnan (x) : x < y; |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
56 } |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
57 |
8725 | 58 static bool |
59 nan_descending_compare (const FloatComplex& x, const FloatComplex& y) | |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
60 { |
19966
40b2c4323c16
avoid some code duplication in complex comparison functions (bug #44206)
John W. Eaton <jwe@octave.org>
parents:
19923
diff
changeset
|
61 return xisnan (x) ? ! xisnan (y) : x > y; |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
62 } |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
63 |
8725 | 64 Array<FloatComplex>::compare_fcn_type |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
65 safe_comparator (sortmode mode, const Array<FloatComplex>& a, bool allow_chk) |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
66 { |
8725 | 67 Array<FloatComplex>::compare_fcn_type result = 0; |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
68 |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
69 if (allow_chk) |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
70 { |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
71 octave_idx_type k = 0; |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
72 for (; k < a.numel () && ! xisnan (a(k)); k++) ; |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
73 if (k == a.numel ()) |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
74 { |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
75 if (mode == ASCENDING) |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
76 result = octave_sort<FloatComplex>::ascending_compare; |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
77 else if (mode == DESCENDING) |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
78 result = octave_sort<FloatComplex>::descending_compare; |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
79 } |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
80 } |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
81 |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
82 if (! result) |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
83 { |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
84 if (mode == ASCENDING) |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
85 result = nan_ascending_compare; |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
86 else if (mode == DESCENDING) |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
87 result = nan_descending_compare; |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
88 } |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
89 |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
90 return result; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
91 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
92 |
19395
fb09907f4e49
Remove single line makro INSTANTIATE_ARRAY_SORT.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17769
diff
changeset
|
93 template class OCTAVE_API octave_sort<FloatComplex>; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
94 |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
95 INSTANTIATE_ARRAY (FloatComplex, OCTAVE_API); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
96 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
97 template OCTAVE_API std::ostream& operator << (std::ostream&, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
98 const Array<FloatComplex>&); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
99 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
100 #include "DiagArray2.h" |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
101 #include "DiagArray2.cc" |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
102 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
103 template class OCTAVE_API DiagArray2<FloatComplex>; |