GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
ov-cx-sparse.cc
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 1998-2025 The Octave Project Developers
4//
5// See the file COPYRIGHT.md in the top-level directory of this
6// distribution or <https://octave.org/copyright/>.
7//
8// This file is part of Octave.
9//
10// Octave is free software: you can redistribute it and/or modify it
11// under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// Octave is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with Octave; see the file COPYING. If not, see
22// <https://www.gnu.org/licenses/>.
23//
24////////////////////////////////////////////////////////////////////////
25
26#if defined (HAVE_CONFIG_H)
27# include "config.h"
28#endif
29
30#include <istream>
31#include <ostream>
32#include <vector>
33
34#include "lo-specfun.h"
35#include "lo-mappers.h"
36#include "oct-locbuf.h"
37
38#include "mxarray.h"
39#include "errwarn.h"
40
41#include "oct-hdf5.h"
42
43#include "ov-re-sparse.h"
44#include "ov-cx-sparse.h"
45
46#include "ov-base-sparse.h"
47#include "ov-base-sparse.cc"
48
49#include "ov-bool-sparse.h"
50
52 "sparse complex matrix", "double");
53
60
61double
62octave_sparse_complex_matrix::double_value (bool force_conversion) const
63{
64 if (! force_conversion)
65 warn_implicit_conversion ("Octave:imag-to-real",
66 "complex sparse matrix", "real scalar");
67
68 // FIXME: maybe this should be a function, valid_as_scalar()
69 if (isempty ())
70 err_invalid_conversion ("complex sparse matrix", "real scalar");
71
72 if (numel () > 1)
73 warn_implicit_conversion ("Octave:array-to-scalar",
74 "complex sparse matrix", "real scalar");
75
76 return std::real (matrix(0, 0));
77}
78
80octave_sparse_complex_matrix::matrix_value (bool force_conversion) const
81{
82 Matrix retval;
83
84 if (! force_conversion)
85 warn_implicit_conversion ("Octave:imag-to-real",
86 "complex sparse matrix", "real matrix");
87
88 retval = ::real (matrix.matrix_value ());
89
90 return retval;
91}
92
95{
96 // FIXME: maybe this should be a function, valid_as_scalar()
97 if (isempty ())
98 err_invalid_conversion ("complex sparse matrix", "real scalar");
99
100 if (numel () > 1)
101 warn_implicit_conversion ("Octave:array-to-scalar",
102 "complex sparse matrix", "real scalar");
103
104 return matrix(0, 0);
105}
106
112
118
121{
122 charNDArray retval;
123
124 if (! frc_str_conv)
125 warn_implicit_conversion ("Octave:num-to-str",
126 "sparse complex matrix", "string");
127 else
128 {
129 retval = charNDArray (dims (), 0);
132
133 for (octave_idx_type j = 0; j < nc; j++)
134 for (octave_idx_type i = matrix.cidx (j); i < matrix.cidx (j+1); i++)
135 retval(matrix.ridx (i) + nr * j)
136 = static_cast<char> (std::real (matrix.data (i)));
137 }
138
139 return retval;
140}
141
144{
145 SparseMatrix retval;
146
147 if (! force_conversion)
148 warn_implicit_conversion ("Octave:imag-to-real",
149 "complex sparse matrix",
150 "real sparse matrix");
151
152 retval = ::real (matrix);
153
154 return retval;
155}
156
159{
161 octave::err_nan_to_logical_conversion ();
162 if (warn && (! matrix.all_elements_are_real ()
163 || real (matrix).any_element_not_one_or_zero ()))
165
166 return mx_el_ne (matrix, Complex (0.0));
167}
168
171{
172 return this->matrix;
173}
174
175bool
177 bool save_as_floats)
178{
179 const dim_vector& dv = this->dims ();
180 if (dv.ndims () < 1)
181 return false;
182
183 // Ensure that additional memory is deallocated
185
186 int nr = dv(0);
187 int nc = dv(1);
188 int nz = nnz ();
189
190 int32_t itmp;
191 // Use negative value for ndims to be consistent with other formats
192 itmp = -2;
193 os.write (reinterpret_cast<char *> (&itmp), 4);
194
195 itmp = nr;
196 os.write (reinterpret_cast<char *> (&itmp), 4);
197
198 itmp = nc;
199 os.write (reinterpret_cast<char *> (&itmp), 4);
200
201 itmp = nz;
202 os.write (reinterpret_cast<char *> (&itmp), 4);
203
204 save_type st = LS_DOUBLE;
205 if (save_as_floats)
206 {
208 {
209 warning ("save: some values too large to save as floats --");
210 warning ("save: saving as doubles instead");
211 }
212 else
213 st = LS_FLOAT;
214 }
215 else if (matrix.nnz () > 8192) // FIXME: make this configurable.
216 {
217 double max_val, min_val;
218 if (matrix.all_integers (max_val, min_val))
219 st = octave::get_save_type (max_val, min_val);
220 }
221
222 // add one to the printed indices to go from
223 // zero-based to one-based arrays
224 for (int i = 0; i < nc+1; i++)
225 {
226 octave_quit ();
227 itmp = matrix.cidx (i);
228 os.write (reinterpret_cast<char *> (&itmp), 4);
229 }
230
231 for (int i = 0; i < nz; i++)
232 {
233 octave_quit ();
234 itmp = matrix.ridx (i);
235 os.write (reinterpret_cast<char *> (&itmp), 4);
236 }
237
238 write_doubles (os, reinterpret_cast<const double *> (matrix.data ()), st,
239 2 * nz);
240
241 return true;
242}
243
244bool
245octave_sparse_complex_matrix::load_binary (std::istream& is, bool swap,
246 octave::mach_info::float_format fmt)
247{
248 int32_t nz, nc, nr, tmp;
249 char ctmp;
250
251 if (! is.read (reinterpret_cast<char *> (&tmp), 4))
252 return false;
253
254 if (swap)
255 swap_bytes<4> (&tmp);
256
257 if (tmp != -2)
258 error ("load: only 2-D sparse matrices are supported");
259
260 if (! is.read (reinterpret_cast<char *> (&nr), 4))
261 return false;
262 if (! is.read (reinterpret_cast<char *> (&nc), 4))
263 return false;
264 if (! is.read (reinterpret_cast<char *> (&nz), 4))
265 return false;
266
267 if (swap)
268 {
269 swap_bytes<4> (&nr);
270 swap_bytes<4> (&nc);
271 swap_bytes<4> (&nz);
272 }
273
274 SparseComplexMatrix m (static_cast<octave_idx_type> (nr),
275 static_cast<octave_idx_type> (nc),
276 static_cast<octave_idx_type> (nz));
277
278 for (int i = 0; i < nc+1; i++)
279 {
280 octave_quit ();
281 if (! is.read (reinterpret_cast<char *> (&tmp), 4))
282 return false;
283 if (swap)
284 swap_bytes<4> (&tmp);
285 m.cidx (i) = tmp;
286 }
287
288 for (int i = 0; i < nz; i++)
289 {
290 octave_quit ();
291 if (! is.read (reinterpret_cast<char *> (&tmp), 4))
292 return false;
293 if (swap)
294 swap_bytes<4> (&tmp);
295 m.ridx (i) = tmp;
296 }
297
298 if (! is.read (reinterpret_cast<char *> (&ctmp), 1))
299 return false;
300
301 read_doubles (is, reinterpret_cast<double *> (m.data ()),
302 static_cast<save_type> (ctmp), 2 * nz, swap, fmt);
303
304 if (! is)
305 return false;
306
307 if (! m.indices_ok ())
308 return false;
309
310 matrix = m;
311
312 return true;
313}
314
315bool
317 const char *name,
318 bool save_as_floats)
319{
320 bool retval = false;
321
322#if defined (HAVE_HDF5)
323
324 const dim_vector& dv = dims ();
325 int empty = save_hdf5_empty (loc_id, name, dv);
326 if (empty)
327 return (empty > 0);
328
329 // Ensure that additional memory is deallocated
331
332#if defined (HAVE_HDF5_18)
333 hid_t group_hid = H5Gcreate (loc_id, name, octave_H5P_DEFAULT,
335#else
336 hid_t group_hid = H5Gcreate (loc_id, name, 0);
337#endif
338 if (group_hid < 0)
339 return false;
340
341 hid_t space_hid, data_hid;
342 space_hid = data_hid = -1;
344 octave_idx_type tmp;
345 hsize_t hdims[2];
346
347 space_hid = H5Screate_simple (0, hdims, nullptr);
348 if (space_hid < 0)
349 {
350 H5Gclose (group_hid);
351 return false;
352 }
353
354#if defined (HAVE_HDF5_18)
355 data_hid = H5Dcreate (group_hid, "nr", H5T_NATIVE_IDX, space_hid,
358#else
359 data_hid = H5Dcreate (group_hid, "nr", H5T_NATIVE_IDX, space_hid,
361#endif
362 if (data_hid < 0)
363 {
364 H5Sclose (space_hid);
365 H5Gclose (group_hid);
366 return false;
367 }
368
369 tmp = m.rows ();
370 retval = H5Dwrite (data_hid, H5T_NATIVE_IDX, octave_H5S_ALL, octave_H5S_ALL,
371 octave_H5P_DEFAULT, &tmp) >= 0;
372 H5Dclose (data_hid);
373 if (! retval)
374 {
375 H5Sclose (space_hid);
376 H5Gclose (group_hid);
377 return false;
378 }
379
380#if defined (HAVE_HDF5_18)
381 data_hid = H5Dcreate (group_hid, "nc", H5T_NATIVE_IDX, space_hid,
384#else
385 data_hid = H5Dcreate (group_hid, "nc", H5T_NATIVE_IDX, space_hid,
387#endif
388 if (data_hid < 0)
389 {
390 H5Sclose (space_hid);
391 H5Gclose (group_hid);
392 return false;
393 }
394
395 tmp = m.cols ();
396 retval = H5Dwrite (data_hid, H5T_NATIVE_IDX, octave_H5S_ALL, octave_H5S_ALL,
397 octave_H5P_DEFAULT, &tmp) >= 0;
398 H5Dclose (data_hid);
399 if (! retval)
400 {
401 H5Sclose (space_hid);
402 H5Gclose (group_hid);
403 return false;
404 }
405
406#if defined (HAVE_HDF5_18)
407 data_hid = H5Dcreate (group_hid, "nz", H5T_NATIVE_IDX, space_hid,
410#else
411 data_hid = H5Dcreate (group_hid, "nz", H5T_NATIVE_IDX, space_hid,
413#endif
414 if (data_hid < 0)
415 {
416 H5Sclose (space_hid);
417 H5Gclose (group_hid);
418 return false;
419 }
420
421 tmp = m.nnz ();
422 retval = H5Dwrite (data_hid, H5T_NATIVE_IDX, octave_H5S_ALL, octave_H5S_ALL,
423 octave_H5P_DEFAULT, &tmp) >= 0;
424 H5Dclose (data_hid);
425 if (! retval)
426 {
427 H5Sclose (space_hid);
428 H5Gclose (group_hid);
429 return false;
430 }
431
432 H5Sclose (space_hid);
433
434 hdims[0] = m.cols () + 1;
435 hdims[1] = 1;
436
437 space_hid = H5Screate_simple (2, hdims, nullptr);
438
439 if (space_hid < 0)
440 {
441 H5Gclose (group_hid);
442 return false;
443 }
444
445#if defined (HAVE_HDF5_18)
446 data_hid = H5Dcreate (group_hid, "cidx", H5T_NATIVE_IDX, space_hid,
449#else
450 data_hid = H5Dcreate (group_hid, "cidx", H5T_NATIVE_IDX, space_hid,
452#endif
453 if (data_hid < 0)
454 {
455 H5Sclose (space_hid);
456 H5Gclose (group_hid);
457 return false;
458 }
459
460 octave_idx_type *itmp = m.xcidx ();
461 retval = H5Dwrite (data_hid, H5T_NATIVE_IDX, octave_H5S_ALL, octave_H5S_ALL,
462 octave_H5P_DEFAULT, itmp) >= 0;
463 H5Dclose (data_hid);
464 if (! retval)
465 {
466 H5Sclose (space_hid);
467 H5Gclose (group_hid);
468 return false;
469 }
470
471 H5Sclose (space_hid);
472
473 hdims[0] = m.nnz ();
474 hdims[1] = 1;
475
476 space_hid = H5Screate_simple (2, hdims, nullptr);
477
478 if (space_hid < 0)
479 {
480 H5Gclose (group_hid);
481 return false;
482 }
483
484#if defined (HAVE_HDF5_18)
485 data_hid = H5Dcreate (group_hid, "ridx", H5T_NATIVE_IDX, space_hid,
488#else
489 data_hid = H5Dcreate (group_hid, "ridx", H5T_NATIVE_IDX, space_hid,
491#endif
492 if (data_hid < 0)
493 {
494 H5Sclose (space_hid);
495 H5Gclose (group_hid);
496 return false;
497 }
498
499 itmp = m.xridx ();
500 retval = H5Dwrite (data_hid, H5T_NATIVE_IDX, octave_H5S_ALL, octave_H5S_ALL,
501 octave_H5P_DEFAULT, itmp) >= 0;
502 H5Dclose (data_hid);
503 if (! retval)
504 {
505 H5Sclose (space_hid);
506 H5Gclose (group_hid);
507 return false;
508 }
509
510 hid_t save_type_hid = H5T_NATIVE_DOUBLE;
511
512 if (save_as_floats)
513 {
514 if (m.too_large_for_float ())
515 {
516 warning ("save: some values too large to save as floats --");
517 warning ("save: saving as doubles instead");
518 }
519 else
520 save_type_hid = H5T_NATIVE_FLOAT;
521 }
522#if defined (HAVE_HDF5_INT2FLOAT_CONVERSIONS)
523 // hdf5 currently doesn't support float/integer conversions
524 else
525 {
526 double max_val, min_val;
527
528 if (m.all_integers (max_val, min_val))
529 save_type_hid
530 = save_type_to_hdf5 (octave::get_save_type (max_val, min_val));
531 }
532#endif
533
534 hid_t type_hid = hdf5_make_complex_type (save_type_hid);
535 if (type_hid < 0)
536 {
537 H5Sclose (space_hid);
538 H5Gclose (group_hid);
539 return false;
540 }
541#if defined (HAVE_HDF5_18)
542 data_hid = H5Dcreate (group_hid, "data", type_hid, space_hid,
545#else
546 data_hid = H5Dcreate (group_hid, "data", type_hid, space_hid,
548#endif
549 if (data_hid < 0)
550 {
551 H5Sclose (space_hid);
552 H5Tclose (type_hid);
553 H5Gclose (group_hid);
554 return false;
555 }
556
557 hid_t complex_type_hid = hdf5_make_complex_type (H5T_NATIVE_DOUBLE);
558 retval = false;
559 if (complex_type_hid >= 0)
560 {
561 Complex *ctmp = m.xdata ();
562
563 retval = H5Dwrite (data_hid, complex_type_hid, octave_H5S_ALL,
565 }
566
567 H5Dclose (data_hid);
568 H5Sclose (space_hid);
569 H5Tclose (type_hid);
570 H5Gclose (group_hid);
571
572#else
573 octave_unused_parameter (loc_id);
574 octave_unused_parameter (name);
575 octave_unused_parameter (save_as_floats);
576
577 warn_save ("hdf5");
578#endif
579
580 return retval;
581}
582
583bool
585 const char *name)
586{
587 bool retval = false;
588
589#if defined (HAVE_HDF5)
590
591 octave_idx_type nr, nc, nz;
592 hid_t group_hid, data_hid, space_hid;
593 hsize_t rank;
594
595 dim_vector dv;
596 int empty = load_hdf5_empty (loc_id, name, dv);
597 if (empty > 0)
598 matrix.resize (dv);
599 if (empty)
600 return (empty > 0);
601
602#if defined (HAVE_HDF5_18)
603 group_hid = H5Gopen (loc_id, name, octave_H5P_DEFAULT);
604#else
605 group_hid = H5Gopen (loc_id, name);
606#endif
607 if (group_hid < 0) return false;
608
609#if defined (HAVE_HDF5_18)
610 data_hid = H5Dopen (group_hid, "nr", octave_H5P_DEFAULT);
611#else
612 data_hid = H5Dopen (group_hid, "nr");
613#endif
614 space_hid = H5Dget_space (data_hid);
615 rank = H5Sget_simple_extent_ndims (space_hid);
616
617 if (rank != 0)
618 {
619 H5Dclose (data_hid);
620 H5Gclose (group_hid);
621 return false;
622 }
623
624 if (H5Dread (data_hid, H5T_NATIVE_IDX, octave_H5S_ALL,
626 {
627 H5Dclose (data_hid);
628 H5Gclose (group_hid);
629 return false;
630 }
631
632 H5Dclose (data_hid);
633
634#if defined (HAVE_HDF5_18)
635 data_hid = H5Dopen (group_hid, "nc", octave_H5P_DEFAULT);
636#else
637 data_hid = H5Dopen (group_hid, "nc");
638#endif
639 space_hid = H5Dget_space (data_hid);
640 rank = H5Sget_simple_extent_ndims (space_hid);
641
642 if (rank != 0)
643 {
644 H5Dclose (data_hid);
645 H5Gclose (group_hid);
646 return false;
647 }
648
649 if (H5Dread (data_hid, H5T_NATIVE_IDX, octave_H5S_ALL,
651 {
652 H5Dclose (data_hid);
653 H5Gclose (group_hid);
654 return false;
655 }
656
657 H5Dclose (data_hid);
658
659#if defined (HAVE_HDF5_18)
660 data_hid = H5Dopen (group_hid, "nz", octave_H5P_DEFAULT);
661#else
662 data_hid = H5Dopen (group_hid, "nz");
663#endif
664 space_hid = H5Dget_space (data_hid);
665 rank = H5Sget_simple_extent_ndims (space_hid);
666
667 if (rank != 0)
668 {
669 H5Dclose (data_hid);
670 H5Gclose (group_hid);
671 return false;
672 }
673
674 if (H5Dread (data_hid, H5T_NATIVE_IDX, octave_H5S_ALL,
676 {
677 H5Dclose (data_hid);
678 H5Gclose (group_hid);
679 return false;
680 }
681
682 H5Dclose (data_hid);
683
684 SparseComplexMatrix m (static_cast<octave_idx_type> (nr),
685 static_cast<octave_idx_type> (nc),
686 static_cast<octave_idx_type> (nz));
687
688#if defined (HAVE_HDF5_18)
689 data_hid = H5Dopen (group_hid, "cidx", octave_H5P_DEFAULT);
690#else
691 data_hid = H5Dopen (group_hid, "cidx");
692#endif
693 space_hid = H5Dget_space (data_hid);
694 rank = H5Sget_simple_extent_ndims (space_hid);
695
696 if (rank != 2)
697 {
698 H5Sclose (space_hid);
699 H5Dclose (data_hid);
700 H5Gclose (group_hid);
701 return false;
702 }
703
704 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank);
705 OCTAVE_LOCAL_BUFFER (hsize_t, maxdims, rank);
706
707 H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
708
709 if (static_cast<int> (hdims[0]) != nc + 1
710 || static_cast<int> (hdims[1]) != 1)
711 {
712 H5Sclose (space_hid);
713 H5Dclose (data_hid);
714 H5Gclose (group_hid);
715 return false;
716 }
717
718 octave_idx_type *itmp = m.xcidx ();
719 if (H5Dread (data_hid, H5T_NATIVE_IDX, octave_H5S_ALL,
721 {
722 H5Sclose (space_hid);
723 H5Dclose (data_hid);
724 H5Gclose (group_hid);
725 return false;
726 }
727
728 H5Sclose (space_hid);
729 H5Dclose (data_hid);
730
731#if defined (HAVE_HDF5_18)
732 data_hid = H5Dopen (group_hid, "ridx", octave_H5P_DEFAULT);
733#else
734 data_hid = H5Dopen (group_hid, "ridx");
735#endif
736 space_hid = H5Dget_space (data_hid);
737 rank = H5Sget_simple_extent_ndims (space_hid);
738
739 if (rank != 2)
740 {
741 H5Sclose (space_hid);
742 H5Dclose (data_hid);
743 H5Gclose (group_hid);
744 return false;
745 }
746
747 H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
748
749 if (static_cast<int> (hdims[0]) != nz
750 || static_cast<int> (hdims[1]) != 1)
751 {
752 H5Sclose (space_hid);
753 H5Dclose (data_hid);
754 H5Gclose (group_hid);
755 return false;
756 }
757
758 itmp = m.xridx ();
759 if (H5Dread (data_hid, H5T_NATIVE_IDX, octave_H5S_ALL,
761 {
762 H5Sclose (space_hid);
763 H5Dclose (data_hid);
764 H5Gclose (group_hid);
765 return false;
766 }
767
768 H5Sclose (space_hid);
769 H5Dclose (data_hid);
770
771#if defined (HAVE_HDF5_18)
772 data_hid = H5Dopen (group_hid, "data", octave_H5P_DEFAULT);
773#else
774 data_hid = H5Dopen (group_hid, "data");
775#endif
776 hid_t type_hid = H5Dget_type (data_hid);
777
778 hid_t complex_type = hdf5_make_complex_type (H5T_NATIVE_DOUBLE);
779
780 if (! hdf5_types_compatible (type_hid, complex_type))
781 {
782 H5Tclose (complex_type);
783 H5Dclose (data_hid);
784 H5Gclose (group_hid);
785 return false;
786 }
787
788 space_hid = H5Dget_space (data_hid);
789 rank = H5Sget_simple_extent_ndims (space_hid);
790
791 if (rank != 2)
792 {
793 H5Sclose (space_hid);
794 H5Dclose (data_hid);
795 H5Gclose (group_hid);
796 return false;
797 }
798
799 H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
800
801 if (static_cast<int> (hdims[0]) != nz
802 || static_cast<int> (hdims[1]) != 1)
803 {
804 H5Sclose (space_hid);
805 H5Dclose (data_hid);
806 H5Gclose (group_hid);
807 return false;
808 }
809
810 Complex *ctmp = m.xdata ();
811
812 if (H5Dread (data_hid, complex_type, octave_H5S_ALL, octave_H5S_ALL,
813 octave_H5P_DEFAULT, ctmp) >= 0
814 && m.indices_ok ())
815 {
816 retval = true;
817 matrix = m;
818 }
819
820 H5Tclose (complex_type);
821 H5Sclose (space_hid);
822 H5Dclose (data_hid);
823 H5Gclose (group_hid);
824
825#else
826 octave_unused_parameter (loc_id);
827 octave_unused_parameter (name);
828
829 warn_load ("hdf5");
830#endif
831
832 return retval;
833}
834
835mxArray *
837{
838 mwSize nz = nzmax ();
839 mwSize nr = rows ();
840 mwSize nc = columns ();
841
842 mxArray *retval = new mxArray (interleaved, mxDOUBLE_CLASS, nr, nc, nz,
843 mxCOMPLEX);
844
845 mwIndex *ir = retval->get_ir ();
846
847 const Complex *pdata = matrix.data ();
848 const octave_idx_type *pridx = matrix.ridx ();
849
850 if (interleaved)
851 {
852 mxComplexDouble *pd
853 = static_cast<mxComplexDouble *> (retval->get_data ());
854
855 for (mwIndex i = 0; i < nz; i++)
856 {
857 pd[i].real = pdata[i].real ();
858 pd[i].imag = pdata[i].imag ();
859
860 ir[i] = pridx[i];
861 }
862 }
863 else
864 {
865 mxDouble *pr = static_cast<mxDouble *> (retval->get_data ());
866 mxDouble *pi = static_cast<mxDouble *> (retval->get_imag_data ());
867
868 for (mwIndex i = 0; i < nz; i++)
869 {
870 pr[i] = pdata[i].real ();
871 pi[i] = pdata[i].imag ();
872
873 ir[i] = pridx[i];
874 }
875 }
876
877 mwIndex *jc = retval->get_jc ();
878
879 const octave_idx_type *pcidx = matrix.cidx ();
880
881 for (mwIndex i = 0; i < nc + 1; i++)
882 jc[i] = pcidx[i];
883
884 return retval;
885}
886
889{
890 switch (umap)
891 {
892 // Mappers handled specially.
893 case umap_real:
894 return ::real (matrix);
895 case umap_imag:
896 return ::imag (matrix);
897
898#define ARRAY_METHOD_MAPPER(UMAP, FCN) \
899 case umap_ ## UMAP: \
900 return octave_value (matrix.FCN ())
901
903
904#define ARRAY_MAPPER(UMAP, TYPE, FCN) \
905 case umap_ ## UMAP: \
906 return octave_value (matrix.map<TYPE> (FCN))
907
908 ARRAY_MAPPER (acos, Complex, octave::math::acos);
909 ARRAY_MAPPER (acosh, Complex, octave::math::acosh);
910 ARRAY_MAPPER (angle, double, std::arg);
911 ARRAY_MAPPER (arg, double, std::arg);
912 ARRAY_MAPPER (asin, Complex, octave::math::asin);
913 ARRAY_MAPPER (asinh, Complex, octave::math::asinh);
914 ARRAY_MAPPER (atan, Complex, octave::math::atan);
915 ARRAY_MAPPER (atanh, Complex, octave::math::atanh);
916 ARRAY_MAPPER (erf, Complex, octave::math::erf);
917 ARRAY_MAPPER (erfc, Complex, octave::math::erfc);
918 ARRAY_MAPPER (erfcx, Complex, octave::math::erfcx);
919 ARRAY_MAPPER (erfi, Complex, octave::math::erfi);
920 ARRAY_MAPPER (dawson, Complex, octave::math::dawson);
921 ARRAY_MAPPER (ceil, Complex, octave::math::ceil);
922 ARRAY_MAPPER (conj, Complex, std::conj<double>);
923 ARRAY_MAPPER (cos, Complex, std::cos);
924 ARRAY_MAPPER (cosh, Complex, std::cosh);
925 ARRAY_MAPPER (exp, Complex, std::exp);
926 ARRAY_MAPPER (expm1, Complex, octave::math::expm1);
927 ARRAY_MAPPER (fix, Complex, octave::math::fix);
928 ARRAY_MAPPER (floor, Complex, octave::math::floor);
929 ARRAY_MAPPER (log, Complex, std::log);
930 ARRAY_MAPPER (log2, Complex, octave::math::log2);
931 ARRAY_MAPPER (log10, Complex, std::log10);
932 ARRAY_MAPPER (log1p, Complex, octave::math::log1p);
933 ARRAY_MAPPER (round, Complex, octave::math::round);
934 ARRAY_MAPPER (roundb, Complex, octave::math::roundb);
935 ARRAY_MAPPER (signum, Complex, octave::math::signum);
936 ARRAY_MAPPER (sin, Complex, std::sin);
937 ARRAY_MAPPER (sinh, Complex, std::sinh);
938 ARRAY_MAPPER (sqrt, Complex, std::sqrt);
939 ARRAY_MAPPER (tan, Complex, std::tan);
940 ARRAY_MAPPER (tanh, Complex, std::tanh);
941 ARRAY_MAPPER (isnan, bool, octave::math::isnan);
942 ARRAY_MAPPER (isna, bool, octave::math::isna);
943 ARRAY_MAPPER (isinf, bool, octave::math::isinf);
944 ARRAY_MAPPER (isfinite, bool, octave::math::isfinite);
945
946 default: // Attempt to go via dense matrix.
948 }
949}
ComplexColumnVector conj(const ComplexColumnVector &a)
boolMatrix mx_el_ne(const boolMatrix &m1, const boolMatrix &m2)
Definition boolMatrix.cc:91
void swap_bytes< 4 >(void *ptr)
Definition byte-swap.h:63
bool too_large_for_float() const
Definition CSparse.cc:7304
ComplexMatrix matrix_value() const
Definition CSparse.cc:598
bool all_elements_are_real() const
Definition CSparse.cc:7256
bool any_element_is_nan() const
Definition CSparse.cc:7224
bool all_integers(double &max_val, double &min_val) const
Definition CSparse.cc:7266
octave_idx_type cols() const
Definition Sparse.h:349
octave_idx_type * cidx()
Definition Sparse.h:593
T * data()
Definition Sparse.h:571
void resize(octave_idx_type r, octave_idx_type c)
Definition Sparse.cc:992
bool indices_ok() const
Definition Sparse.h:746
T * xdata()
Definition Sparse.h:573
octave_idx_type * ridx()
Definition Sparse.h:580
Sparse< T, Alloc > maybe_compress(bool remove_zeros=false)
Definition Sparse.h:528
octave_idx_type nnz() const
Actual number of nonzero terms.
Definition Sparse.h:336
octave_idx_type rows() const
Definition Sparse.h:348
octave_idx_type * xcidx()
Definition Sparse.h:599
octave_idx_type * xridx()
Definition Sparse.h:586
Vector representing the dimensions (size) of an Array.
Definition dim-vector.h:90
octave_idx_type ndims() const
Number of dimensions.
Definition dim-vector.h:253
mwIndex * get_jc() const
Definition mxarray.h:565
mwIndex * get_ir() const
Definition mxarray.h:563
void * get_data() const
Definition mxarray.h:482
void * get_imag_data() const
Definition mxarray.h:520
octave_value map(octave_base_value::unary_mapper_t umap) const
octave_idx_type rows() const
Definition ov-base.h:384
octave_idx_type columns() const
Definition ov-base.h:391
void warn_load(const char *type) const
Definition ov-base.cc:1152
bool isempty() const
Definition ov-base.h:429
void warn_save(const char *type) const
Definition ov-base.cc:1161
SparseComplexMatrix sparse_complex_matrix_value(bool=false) const
octave_value map(unary_mapper_t umap) const
Complex complex_value(bool=false) const
SparseBoolMatrix sparse_bool_matrix_value(bool warn=false) const
octave_base_value * try_narrowing_conversion()
bool load_hdf5(octave_hdf5_id loc_id, const char *name)
ComplexNDArray complex_array_value(bool=false) const
octave_value as_double() const
Matrix matrix_value(bool=false) const
double double_value(bool=false) const
bool save_hdf5(octave_hdf5_id loc_id, const char *name, bool save_as_floats)
ComplexMatrix complex_matrix_value(bool=false) const
mxArray * as_mxArray(bool interleaved) const
SparseMatrix sparse_matrix_value(bool=false) const
charNDArray char_array_value(bool frc_str_conv=false) const
bool load_binary(std::istream &is, bool swap, octave::mach_info::float_format fmt)
bool save_binary(std::ostream &os, bool save_as_floats)
const octave_hdf5_id octave_H5P_DEFAULT
const octave_hdf5_id octave_H5S_ALL
ColumnVector real(const ComplexColumnVector &a)
void read_doubles(std::istream &is, double *data, save_type type, octave_idx_type len, bool swap, octave::mach_info::float_format fmt)
Definition data-conv.cc:802
void write_doubles(std::ostream &os, const double *data, save_type type, octave_idx_type len)
Definition data-conv.cc:918
save_type
Definition data-conv.h:85
@ LS_DOUBLE
Definition data-conv.h:93
@ LS_FLOAT
Definition data-conv.h:92
void warning(const char *fmt,...)
Definition error.cc:1078
void error(const char *fmt,...)
Definition error.cc:1003
void err_invalid_conversion(const std::string &from, const std::string &to)
Definition errwarn.cc:71
void warn_logical_conversion()
Definition errwarn.cc:365
void warn_implicit_conversion(const char *id, const char *from, const char *to)
Definition errwarn.cc:344
Complex log2(const Complex &x)
Complex asin(const Complex &x)
bool isna(double x)
Definition lo-mappers.cc:47
Complex acos(const Complex &x)
Definition lo-mappers.cc:85
std::complex< T > ceil(const std::complex< T > &x)
Definition lo-mappers.h:103
Complex atan(const Complex &x)
Definition lo-mappers.h:71
double roundb(double x)
Definition lo-mappers.h:147
std::complex< T > floor(const std::complex< T > &x)
Definition lo-mappers.h:130
bool isfinite(double x)
Definition lo-mappers.h:192
bool isinf(double x)
Definition lo-mappers.h:203
double signum(double x)
Definition lo-mappers.h:229
double round(double x)
Definition lo-mappers.h:136
bool isnan(bool)
Definition lo-mappers.h:178
double fix(double x)
Definition lo-mappers.h:118
double erfi(double x)
double dawson(double x)
Complex erf(const Complex &x)
double erfcx(double x)
Complex expm1(const Complex &x)
Complex log1p(const Complex &x)
Complex erfc(const Complex &x)
double asinh(double x)
Definition lo-specfun.h:58
double atanh(double x)
Definition lo-specfun.h:63
double acosh(double x)
Definition lo-specfun.h:40
int save_hdf5_empty(octave_hdf5_id loc_id, const char *name, const dim_vector &d)
Definition ls-hdf5.cc:1254
int load_hdf5_empty(octave_hdf5_id loc_id, const char *name, dim_vector &d)
Definition ls-hdf5.cc:1311
octave_hdf5_id save_type_to_hdf5(save_type st)
Definition ls-hdf5.cc:1355
octave_hdf5_id hdf5_make_complex_type(octave_hdf5_id num_type)
Definition ls-hdf5.cc:410
bool hdf5_types_compatible(octave_hdf5_id t1, octave_hdf5_id t2)
Definition ls-hdf5.cc:274
std::complex< double > Complex
Definition oct-cmplx.h:33
int64_t octave_hdf5_id
#define H5T_NATIVE_IDX
Definition oct-hdf5.h:42
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
Definition oct-locbuf.h:44
#define DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(t, n, c)
Definition ov-base.h:246
#define ARRAY_MAPPER(UMAP, TYPE, FCN)
#define ARRAY_METHOD_MAPPER(UMAP, FCN)
template int8_t abs(int8_t)