Mercurial > hg > octave-nkf
annotate src/ov-flt-re-diag.cc @ 13281:834f904a3dcb
Add support for full asynchronous graphics toolkit running in a separate
thread. Add uicontrol and uipanel implementation.
* oct-mutex.h (octave_base_mutex::try_lock): New method.
(octave_mutex::try_lock): Likewise.
(octave_auto_lock::octave_auto_lock): New argument for
blocking/non-blocking locks.
(octave_auto_lock::ok): New method to test locking state.
(octave_auto_lock::operator bool): Likewise.
(octave_thread): New utility class.
* oct-mutex.cc (octave_base_mutex::try_lock): New method.
(octave_w32_mutex::try_lock): Implement it for Win32.
(octave_pthread_mutex::try_lock): Implement it for pthread.
(octave_thread): Implement new utility class.
* octave.cc (octave_main): Initialize octave_thread.
* genprops.awk (emit_get_string_array): New function.
(emit_declarations): Use it for string_array_property.
* graphics.h.in (base_property::set): New argument to control toolkit
notifying.
(property::set): Likewise.
(string_array_property::string_vector_value): New method.
(radio_property::do_set): Add warning about abbreviated radio values.
(base_graphics_toolkit::initialize): Returns bool.
(graphics_toolkit::initialize): Likewise.
(base_graphics_object::toolkit_flag): New member.
(base_graphics_object::base_graphics_object): Initialize it.
(base_graphics_object::valid_toolkit_object): New method.
(base_graphics_object::initialize, base_graphics_object::finalize,
base_graphics_object::update): Likewise.
(graphics_object::initialize, graphics_object::finalize,
graphics_object::update): Likewise.
(figure::properties::set_toolkit): Move implementation to source file.
(base_properties::get_boundingbox): Add parent size argument for optimization.
(figure::properties::get_boundingbox): Likewise.
(axes::properties::get_boundingbox): Likewise.
(figure::properties::map_from_boundingbox): New utility method.
(figure::properties::map_to_boundingbox): Likewise.
(axes::properties::get_fontsize_points): New utility method.
(text::properties::get_fontsize_points): Likewise.
(axes::properties::xlabel, axes::properties::ylabel, axes::properties::zlabel,
axes::properties::title): Don't notify toolkit on initialization.
(axes::initialize): New method override.
(uicontrol): New class.
(uipanel): Likewise.
(graphics_event::create_callback_event): New static method overload.
(graphics_event::create_set_event): New argument to prevent circular
behavior when property change is triggered from the toolkit.
(gh_manager::post_set): Likewise.
(gh_manager::do_post_set): Likewise.
(gh_manager::make_graphics_handle): New argument controlling toolkit notify.
(gh_manager::make_figure_handle): Likewise.
(gh_manager::do_make_graphics_handle): Likewise.
(gh_manager::do_make_figure_handle): Likewise.
(gh_manager::try_lock): New static method.
(gh_manager::execute_listener): Likewise.
(gh_manager::enable_event_processing): Likewise.
(gh_manager::do_try_lock): New method.
(gh_manager::do_execute_listener): Likewise.
(gh_manager::do_enable_event_processing): Likewise.
(gh_manager::event_processing): New member.
(gh_manager::execute_callback): Protect graphics_object access.
(gh_manager::auto_lock): Inherits from octave_autolock. Renamed from autolock.
(gh_manager::auto_lock::auto_lock): New blocking/non-blocking argument.
* graphics.cc (default_control_position, default_control_sliderstep,
default_panel_position): New utility functions.
(convert_font_size): New utility function.
(convert_position): Support 2D-only positions.
(lookup_object_name): Support uicontrol and uipanel.
(make_graphics_object_from_type): Likewise.
(root_figure::init_factory_properties): Likewise.
(property_list::set, property_list::lookup): Likewise.
(base_property::set): New argument controlling toolkit notifying.
(base_property::run_listeners): Call gh_manager::execute_listener, allowing
to set a property from another thread and run listeners synchronously with
octave.
(color_property::do_set): Add warning about abbreviated radio value.
(double_radio_property::do_set): Likewise.
(finalize_r, initialize_r, xinitialize): New utility functions.
(gh_manager::do_free): Calls graphics_object::finalize.
(base_graphics_toolkit::initialize): Returns bool.
(gnuplot_toolkit::initialize): Likewise.
(figure::properties::set_toolkit): Move implementation from header.
(figure::properties::get_boundingbox): New argument for parent size.
(axes::properties::get_boundingbox): Likewise.
(figure::properties::map_from_boundingbox): New utility method.
(figure::properties::map_to_boundingbox): Likewise.
(axes::properties::update_fontunits): Use convert_font_size.
(axes::properties::get_fontsize_points): New utility method.
(text::properties::get_fontsize_points): Likewise.
(axes::initialize): New method override to trigger initialization of
labels and title.
(uicontrol): New class.
(uipanel): Likewise.
(gh_manager::gh_manager): Initialize new event_processing member.
(gh_manager::do_make_graphics_handle): New argument controlling toolkit
notifying.
(gh_manager::do_make_figure_handle): Likewise.
(callback_event::callback): New member.
(callback_event::callback_event): Initialize it.
(callback_event::execute): Use it.
(set_event::notify_toolkit): New member.
(set_event::set_event): Initialize it.
(set_event::execute): Use it. Also allow to set read-only properties.
(graphics_event::create_callback_event): New static method overload.
(graphics_event::create_set_event): New argument controlling toolkit notifying.
(gh_manager::do_restore_gcbo): Rename autolock to auto_lock.
(gh_manager::do_post_callback, gh_manager::do_post_function): Likewise.
(Fishandle, Fset, Fget, F__get__): Likewise.
(F__go_figure__, F__calc_dimensions__, GO_BODY): Likewise.
(F__go_delete__, F__go_axes_init__, F__go_handles__, F__go_figure_handles__,
Favailable_graphics_toolkits, Faddlistener, Fdellistener, Faddproperty):
Likewise.
(get_property_from_handle, set_property_in_handle): Likewise.
(gh_manager::do_post_set): Likewise. New argument controlling toolkit
notifying.
(gh_manager::do_execute_listener): New method.
(gh_manager::do_enable_event_processing): Likewise.
(gh_manager::do_execute_callback): Check callback argument validity.
Rename autolock to auto_lock.
(gh_manager::do_process_events): Execute drawnow at the end of event
processing loop, avoiding recursivity. Maintain the input event hook
if gh_manager::event_processing is non zero.
(make_graphics_object): Postpone object's toolkit initialization at
the end of the object creation.
(F__go_figure__): Likewise.
(F__go_uicontrol__, F__go_uipanel__): New functions.
* __init_fltk__.cc (fltk_graphics_toolkit::initialise): New method.
* gl-render.h (opengl_renderer::draw): New argument to identify top-level
calls.
(opengl_renderer::draw_uipanel): New method.
(opengl_renderer::init_gl_context): Likewise.
* gl-render.cc (opengl_renderer::draw): New argument to identify top-level
calls. Skip uicontrol objects. Handle uipanel objects when top-level.
(opengl_renderer::init_gl_context): New method.
(opengl_renderer::draw_figure): Use it.
(opengl_renderer::draw_uipanel): New method.
author | Michael Goffioul <michael.goffioul@gmail.com> |
---|---|
date | Thu, 06 Oct 2011 16:44:18 +0100 |
parents | 12df7854fa7c |
children | 72c96de7a403 |
rev | line source |
---|---|
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
1 /* |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
2 |
11523 | 3 Copyright (C) 2008-2011 Jaroslav Hajek |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
4 |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
5 This file is part of Octave. |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
6 |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
7 Octave is free software; you can redistribute it and/or modify it |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
8 under the terms of the GNU General Public License as published by the |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
9 Free Software Foundation; either version 3 of the License, or (at your |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
10 option) any later version. |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
11 |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
15 for more details. |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
16 |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
17 You should have received a copy of the GNU General Public License |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
18 along with Octave; see the file COPYING. If not, see |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
19 <http://www.gnu.org/licenses/>. |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
20 |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
21 */ |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
22 |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
23 #ifdef HAVE_CONFIG_H |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
24 #include <config.h> |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
25 #endif |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
26 |
8381
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
27 #include "byte-swap.h" |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
28 |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
29 #include "ov-flt-re-diag.h" |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
30 #include "ov-base-diag.cc" |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
31 #include "ov-float.h" |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
32 #include "ov-flt-re-mat.h" |
8381
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
33 #include "ls-utils.h" |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
34 |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
35 template class octave_base_diag<FloatDiagMatrix, FloatMatrix>; |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
36 |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
37 DEFINE_OCTAVE_ALLOCATOR (octave_float_diag_matrix); |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
38 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
39 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_float_diag_matrix, |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
40 "float diagonal matrix", "single"); |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
41 |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
42 static octave_base_value * |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
43 default_numeric_conversion_function (const octave_base_value& a) |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
44 { |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
45 CAST_CONV_ARG (const octave_float_diag_matrix&); |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
46 |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
47 return new octave_float_matrix (v.float_matrix_value ()); |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
48 } |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
49 |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
50 octave_base_value::type_conv_info |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
51 octave_float_diag_matrix::numeric_conversion_function (void) const |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
52 { |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
53 return octave_base_value::type_conv_info (default_numeric_conversion_function, |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
54 octave_float_matrix::static_type_id ()); |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
55 } |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
56 |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
57 octave_base_value * |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
58 octave_float_diag_matrix::try_narrowing_conversion (void) |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
59 { |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
60 octave_base_value *retval = 0; |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
61 |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
62 if (matrix.nelem () == 1) |
10815
0eb323b71957
simplify narrowing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
63 retval = new octave_float_scalar (matrix (0, 0)); |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
64 |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
65 return retval; |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
66 } |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
67 |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
68 DiagMatrix |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
69 octave_float_diag_matrix::diag_matrix_value (bool) const |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
70 { |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
71 return DiagMatrix (matrix); |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
72 } |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
73 |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
74 FloatDiagMatrix |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
75 octave_float_diag_matrix::float_diag_matrix_value (bool) const |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
76 { |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
77 return matrix; |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
78 } |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
79 |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
80 ComplexDiagMatrix |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
81 octave_float_diag_matrix::complex_diag_matrix_value (bool) const |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
82 { |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
83 return ComplexDiagMatrix (matrix); |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
84 } |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
85 |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
86 FloatComplexDiagMatrix |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
87 octave_float_diag_matrix::float_complex_diag_matrix_value (bool) const |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
88 { |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
89 return FloatComplexDiagMatrix (matrix); |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
90 } |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
91 |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
92 octave_value |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
93 octave_float_diag_matrix::map (unary_mapper_t umap) const |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
94 { |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
95 switch (umap) |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
96 { |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
97 case umap_abs: |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
98 return matrix.abs (); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
99 case umap_real: |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
100 case umap_conj: |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
101 return matrix; |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
102 case umap_imag: |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
103 return DiagMatrix (matrix.rows (), matrix.cols (), 0.0); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
104 case umap_sqrt: |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
105 { |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
106 FloatComplexColumnVector tmp = matrix.diag ().map<FloatComplex> (rc_sqrt); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
107 FloatComplexDiagMatrix retval (tmp); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
108 retval.resize (matrix.rows (), matrix.columns ()); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
109 return retval; |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
110 } |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
111 default: |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
112 return to_dense ().map (umap); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
113 } |
8834
8dd69187c4a2
specialize sqrt for diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8677
diff
changeset
|
114 } |
8dd69187c4a2
specialize sqrt for diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8677
diff
changeset
|
115 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
116 bool |
8677
095ae5e0a831
eliminte some compiler warnings
John W. Eaton <jwe@octave.org>
parents:
8650
diff
changeset
|
117 octave_float_diag_matrix::save_binary (std::ostream& os, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9812
diff
changeset
|
118 bool& /* save_as_floats*/) |
8381
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
119 { |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
120 |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
121 int32_t r = matrix.rows (), c = matrix.cols (); |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
122 os.write (reinterpret_cast<char *> (&r), 4); |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
123 os.write (reinterpret_cast<char *> (&c), 4); |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
124 |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
125 FloatMatrix m = FloatMatrix (matrix.diag ()); |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
126 save_type st = LS_FLOAT; |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
127 if (matrix.length () > 8192) // FIXME -- make this configurable. |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
128 { |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
129 float max_val, min_val; |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
130 if (m.all_integers (max_val, min_val)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9812
diff
changeset
|
131 st = get_save_type (max_val, min_val); |
8381
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
132 } |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
133 |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
134 const float *mtmp = m.data (); |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
135 write_floats (os, mtmp, st, m.numel ()); |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
136 |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
137 return true; |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
138 } |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
139 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
140 bool |
8381
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
141 octave_float_diag_matrix::load_binary (std::istream& is, bool swap, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9812
diff
changeset
|
142 oct_mach_info::float_format fmt) |
8381
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
143 { |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
144 int32_t r, c; |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
145 char tmp; |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
146 if (! (is.read (reinterpret_cast<char *> (&r), 4) |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
147 && is.read (reinterpret_cast<char *> (&c), 4) |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
148 && is.read (reinterpret_cast<char *> (&tmp), 1))) |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
149 return false; |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
150 if (swap) |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
151 { |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
152 swap_bytes<4> (&r); |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
153 swap_bytes<4> (&c); |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
154 } |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
155 |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
156 FloatDiagMatrix m (r, c); |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
157 float *re = m.fortran_vec (); |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
158 octave_idx_type len = m.length (); |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
159 read_floats (is, re, static_cast<save_type> (tmp), len, swap, fmt); |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
160 if (error_state || ! is) |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
161 return false; |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
162 matrix = m; |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
163 |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
164 return true; |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
165 } |
8398
d95282fa0579
allow element assignment to diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8381
diff
changeset
|
166 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
167 bool |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
168 octave_float_diag_matrix::chk_valid_scalar (const octave_value& val, |
8398
d95282fa0579
allow element assignment to diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8381
diff
changeset
|
169 float& x) const |
d95282fa0579
allow element assignment to diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8381
diff
changeset
|
170 { |
d95282fa0579
allow element assignment to diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8381
diff
changeset
|
171 bool retval = val.is_real_scalar (); |
d95282fa0579
allow element assignment to diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8381
diff
changeset
|
172 if (retval) |
d95282fa0579
allow element assignment to diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8381
diff
changeset
|
173 x = val.float_value (); |
d95282fa0579
allow element assignment to diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8381
diff
changeset
|
174 return retval; |
d95282fa0579
allow element assignment to diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8381
diff
changeset
|
175 } |