annotate libinterp/corefcn/oct-handle.h @ 31225:3eab70385569

sparse-xpow.cc: Use faster multiplication technique, this time for complex
author Arun Giridhar <arungiridhar@gmail.com>
date Sun, 11 Sep 2022 13:53:38 -0400
parents 796f54d4ddbf
children 597f3ee61a48
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ////////////////////////////////////////////////////////////////////////
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 //
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 30175
diff changeset
3 // Copyright (C) 2007-2022 The Octave Project Developers
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
4 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 // See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 // distribution or <https://octave.org/copyright/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
7 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
8 // This file is part of Octave.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
9 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
10 // Octave is free software: you can redistribute it and/or modify it
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
11 // under the terms of the GNU General Public License as published by
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
12 // the Free Software Foundation, either version 3 of the License, or
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
13 // (at your option) any later version.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
14 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
15 // Octave is distributed in the hope that it will be useful, but
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
18 // GNU General Public License for more details.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
19 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
20 // You should have received a copy of the GNU General Public License
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
21 // along with Octave; see the file COPYING. If not, see
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
22 // <https://www.gnu.org/licenses/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ////////////////////////////////////////////////////////////////////////
17544
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
25
20791
f7084eae3318 maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents: 20785
diff changeset
26 #if ! defined (octave_oct_handle_h)
17822
ebb3ef964372 maint: Use common #define syntax "octave_filename_h" in h_files.
Rik <rik@octave.org>
parents: 17744
diff changeset
27 #define octave_oct_handle_h 1
17544
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
28
21244
1473547f50f5 include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
29 #include "octave-config.h"
1473547f50f5 include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
30
17544
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
31 #include "dMatrix.h"
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
32 #include "lo-ieee.h"
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
33
27130
396d17dcfb9f don't include error.h in ov-base.h
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
34 #include "error.h"
17544
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
35 #include "ov.h"
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
36
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
37 // ---------------------------------------------------------------------
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
38
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
39 class octave_handle
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
40 {
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
41 public:
30175
b063bc05be18 maint: use "m_" prefix for member variables in class octave_handle.
Rik <rik@octave.org>
parents: 29359
diff changeset
42 octave_handle (void) : m_dval (octave::numeric_limits<double>::NaN ()) { }
17544
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
43
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
44 octave_handle (const octave_value& a)
30175
b063bc05be18 maint: use "m_" prefix for member variables in class octave_handle.
Rik <rik@octave.org>
parents: 29359
diff changeset
45 : m_dval (octave::numeric_limits<double>::NaN ())
17544
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
46 {
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23220
diff changeset
47 if (a.isempty ())
20946
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
48 ; // do nothing
17544
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
49 else
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
50 {
20545
c547458dc10e eliminate error_state from most header files
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
51 try
c547458dc10e eliminate error_state from most header files
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
52 {
30175
b063bc05be18 maint: use "m_" prefix for member variables in class octave_handle.
Rik <rik@octave.org>
parents: 29359
diff changeset
53 m_dval = a.double_value ();
20545
c547458dc10e eliminate error_state from most header files
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
54 }
29163
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 27923
diff changeset
55 catch (octave::execution_exception& ee)
20545
c547458dc10e eliminate error_state from most header files
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
56 {
29163
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 27923
diff changeset
57 error (ee, "invalid handle");
20545
c547458dc10e eliminate error_state from most header files
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
58 }
17544
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
59 }
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
60 }
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
61
30175
b063bc05be18 maint: use "m_" prefix for member variables in class octave_handle.
Rik <rik@octave.org>
parents: 29359
diff changeset
62 octave_handle (int a) : m_dval (a) { }
17544
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
63
30175
b063bc05be18 maint: use "m_" prefix for member variables in class octave_handle.
Rik <rik@octave.org>
parents: 29359
diff changeset
64 octave_handle (double a) : m_dval (a) { }
17544
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
65
30175
b063bc05be18 maint: use "m_" prefix for member variables in class octave_handle.
Rik <rik@octave.org>
parents: 29359
diff changeset
66 octave_handle (const octave_handle& a) : m_dval (a.m_dval) { }
17544
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
67
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
68 octave_handle& operator = (const octave_handle& a)
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
69 {
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
70 if (&a != this)
30175
b063bc05be18 maint: use "m_" prefix for member variables in class octave_handle.
Rik <rik@octave.org>
parents: 29359
diff changeset
71 m_dval = a.m_dval;
17544
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
72
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
73 return *this;
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
74 }
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
75
22868
87e3163f6c87 use c++11 "= default" syntax for declaration of trivial destructors
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
76 ~octave_handle (void) = default;
17544
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
77
30175
b063bc05be18 maint: use "m_" prefix for member variables in class octave_handle.
Rik <rik@octave.org>
parents: 29359
diff changeset
78 double value (void) const { return m_dval; }
17544
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
79
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
80 octave_value as_octave_value (void) const
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
81 {
30175
b063bc05be18 maint: use "m_" prefix for member variables in class octave_handle.
Rik <rik@octave.org>
parents: 29359
diff changeset
82 return ok () ? octave_value (m_dval) : octave_value (Matrix ());
17544
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
83 }
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
84
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
85 // Prefix increment/decrement operators.
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
86 octave_handle& operator ++ (void)
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
87 {
30175
b063bc05be18 maint: use "m_" prefix for member variables in class octave_handle.
Rik <rik@octave.org>
parents: 29359
diff changeset
88 ++m_dval;
17544
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
89 return *this;
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
90 }
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
91
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
92 octave_handle& operator -- (void)
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
93 {
30175
b063bc05be18 maint: use "m_" prefix for member variables in class octave_handle.
Rik <rik@octave.org>
parents: 29359
diff changeset
94 --m_dval;
17544
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
95 return *this;
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
96 }
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
97
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
98 // Postfix increment/decrement operators.
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
99 const octave_handle operator ++ (int)
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
100 {
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
101 octave_handle old_value = *this;
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
102 ++(*this);
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
103 return old_value;
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
104 }
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
105
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
106 const octave_handle operator -- (int)
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
107 {
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
108 octave_handle old_value = *this;
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
109 --(*this);
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
110 return old_value;
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
111 }
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
112
30175
b063bc05be18 maint: use "m_" prefix for member variables in class octave_handle.
Rik <rik@octave.org>
parents: 29359
diff changeset
113 bool ok (void) const { return ! octave::math::isnan (m_dval); }
17544
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
114
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
115 private:
30175
b063bc05be18 maint: use "m_" prefix for member variables in class octave_handle.
Rik <rik@octave.org>
parents: 29359
diff changeset
116 double m_dval;
17544
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
117 };
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
118
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
119 inline bool
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
120 operator == (const octave_handle& a, const octave_handle& b)
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
121 {
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
122 return a.value () == b.value ();
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
123 }
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
124
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
125 inline bool
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
126 operator != (const octave_handle& a, const octave_handle& b)
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
127 {
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
128 return a.value () != b.value ();
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
129 }
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
130
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
131 inline bool
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
132 operator < (const octave_handle& a, const octave_handle& b)
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
133 {
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
134 return a.value () < b.value ();
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
135 }
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
136
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
137 inline bool
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
138 operator <= (const octave_handle& a, const octave_handle& b)
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
139 {
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
140 return a.value () <= b.value ();
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
141 }
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
142
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
143 inline bool
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
144 operator >= (const octave_handle& a, const octave_handle& b)
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
145 {
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
146 return a.value () >= b.value ();
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
147 }
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
148
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
149 inline bool
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
150 operator > (const octave_handle& a, const octave_handle& b)
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
151 {
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
152 return a.value () > b.value ();
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
153 }
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
154
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
155 #endif