GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
ov-re-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 <limits>
32#include <ostream>
33#include <vector>
34
35#include "lo-specfun.h"
36#include "lo-mappers.h"
37#include "oct-locbuf.h"
38
39#include "mxarray.h"
40#include "errwarn.h"
41
42#include "oct-hdf5.h"
43#include "ls-hdf5.h"
44
45#include "ov-re-sparse.h"
46
47#include "ov-base-sparse.h"
48#include "ov-base-sparse.cc"
49
50#include "ov-bool-sparse.h"
51
53 "double");
54
55octave::idx_vector
56octave_sparse_matrix::index_vector (bool /* require_integers */) const
57{
58 if (matrix.numel () == matrix.nnz ())
59 return octave::idx_vector (array_value ());
60 else
61 {
62 std::string nm = '<' + type_name () + '>';
63 octave::err_invalid_index (nm.c_str ());
64 }
65}
66
67double
69{
70 if (isempty ())
71 err_invalid_conversion ("real sparse matrix", "real scalar");
72
73 if (numel () > 1)
74 warn_implicit_conversion ("Octave:array-to-scalar",
75 "real sparse matrix", "real scalar");
76
77 return matrix(0, 0);
78}
79
82{
83 // FIXME: maybe this should be a function, valid_as_scalar()
84 if (rows () == 0 || columns () == 0)
85 err_invalid_conversion ("real sparse matrix", "complex scalar");
86
87 if (numel () > 1)
88 warn_implicit_conversion ("Octave:array-to-scalar",
89 "real sparse matrix", "complex scalar");
90
91 return Complex (matrix(0, 0), 0);
92}
93
96{
97 return matrix.matrix_value ();
98}
99
102{
104
105 if (m.any_element_is_nan ())
106 octave::err_nan_to_logical_conversion ();
107 if (warn && m.any_element_not_one_or_zero ())
109
110 return boolNDArray (m);
111}
112
115{
116 charNDArray retval (dims (), 0);
119
120 for (octave_idx_type j = 0; j < nc; j++)
121 for (octave_idx_type i = matrix.cidx (j); i < matrix.cidx (j+1); i++)
122 retval(matrix.ridx (i) + nr * j) = static_cast<char> (matrix.data (i));
123
124 return retval;
125}
126
132
138
141{
142 return NDArray (matrix.matrix_value ());
143}
144
147{
149 octave::err_nan_to_logical_conversion ();
150 if (warn && matrix.any_element_not_one_or_zero ())
152
153 return mx_el_ne (matrix, 0.0);
154}
155
158{
159 octave_value retval;
160 const dim_vector& dv = dims ();
161 octave_idx_type nel = dv.numel ();
162
163 if (nel == 0)
164 {
165 char s = '\0';
166 retval = octave_value (&s, type);
167 }
168 else
169 {
172 charNDArray chm (dv, static_cast<char> (0));
173
174 bool warned = false;
175
176 for (octave_idx_type j = 0; j < nc; j++)
177 for (octave_idx_type i = matrix.cidx (j);
178 i < matrix.cidx (j+1); i++)
179 {
180 octave_quit ();
181
182 double d = matrix.data (i);
183
184 if (octave::math::isnan (d))
185 octave::err_nan_to_character_conversion ();
186
187 int ival = octave::math::nint (d);
188
189 if (ival < 0 || ival > std::numeric_limits<unsigned char>::max ())
190 {
191 // FIXME: is there something better we could do?
192
193 ival = 0;
194
195 if (! warned)
196 {
197 ::warning ("range error for conversion to character value");
198 warned = true;
199 }
200 }
201
202 chm(matrix.ridx (i) + j * nr) = static_cast<char> (ival);
203 }
204
205 retval = octave_value (chm, type);
206 }
207
208 return retval;
209}
210
213{
214 return this->matrix;
215}
216
217bool
218octave_sparse_matrix::save_binary (std::ostream& os, bool save_as_floats)
219{
220 const dim_vector& dv = this->dims ();
221 if (dv.ndims () < 1)
222 return false;
223
224 // Ensure that additional memory is deallocated
226
227 int nr = dv(0);
228 int nc = dv(1);
229 int nz = nnz ();
230
231 int32_t itmp;
232 // Use negative value for ndims to be consistent with other formats
233 itmp = -2;
234 os.write (reinterpret_cast<char *> (&itmp), 4);
235
236 itmp = nr;
237 os.write (reinterpret_cast<char *> (&itmp), 4);
238
239 itmp = nc;
240 os.write (reinterpret_cast<char *> (&itmp), 4);
241
242 itmp = nz;
243 os.write (reinterpret_cast<char *> (&itmp), 4);
244
245 save_type st = LS_DOUBLE;
246 if (save_as_floats)
247 {
249 {
250 warning ("save: some values too large to save as floats --");
251 warning ("save: saving as doubles instead");
252 }
253 else
254 st = LS_FLOAT;
255 }
256 else if (matrix.nnz () > 8192) // FIXME: make this configurable.
257 {
258 double max_val, min_val;
259 if (matrix.all_integers (max_val, min_val))
260 st = octave::get_save_type (max_val, min_val);
261 }
262
263 // add one to the printed indices to go from
264 // zero-based to one-based arrays
265 for (int i = 0; i < nc+1; i++)
266 {
267 octave_quit ();
268 itmp = matrix.cidx (i);
269 os.write (reinterpret_cast<char *> (&itmp), 4);
270 }
271
272 for (int i = 0; i < nz; i++)
273 {
274 octave_quit ();
275 itmp = matrix.ridx (i);
276 os.write (reinterpret_cast<char *> (&itmp), 4);
277 }
278
279 write_doubles (os, matrix.data (), st, nz);
280
281 return true;
282}
283
284bool
285octave_sparse_matrix::load_binary (std::istream& is, bool swap,
286 octave::mach_info::float_format fmt)
287{
288 int32_t nz, nc, nr, tmp;
289 char ctmp;
290
291 if (! is.read (reinterpret_cast<char *> (&tmp), 4))
292 return false;
293
294 if (swap)
295 swap_bytes<4> (&tmp);
296
297 if (tmp != -2)
298 error ("load: only 2-D sparse matrices are supported");
299
300 if (! is.read (reinterpret_cast<char *> (&nr), 4))
301 return false;
302 if (! is.read (reinterpret_cast<char *> (&nc), 4))
303 return false;
304 if (! is.read (reinterpret_cast<char *> (&nz), 4))
305 return false;
306
307 if (swap)
308 {
309 swap_bytes<4> (&nr);
310 swap_bytes<4> (&nc);
311 swap_bytes<4> (&nz);
312 }
313
314 SparseMatrix m (static_cast<octave_idx_type> (nr),
315 static_cast<octave_idx_type> (nc),
316 static_cast<octave_idx_type> (nz));
317
318 for (int i = 0; i < nc+1; i++)
319 {
320 octave_quit ();
321 if (! is.read (reinterpret_cast<char *> (&tmp), 4))
322 return false;
323 if (swap)
324 swap_bytes<4> (&tmp);
325 m.xcidx (i) = tmp;
326 }
327
328 for (int i = 0; i < nz; i++)
329 {
330 octave_quit ();
331 if (! is.read (reinterpret_cast<char *> (&tmp), 4))
332 return false;
333 if (swap)
334 swap_bytes<4> (&tmp);
335 m.xridx (i) = tmp;
336 }
337
338 if (! is.read (reinterpret_cast<char *> (&ctmp), 1))
339 return false;
340
341 read_doubles (is, m.xdata (), static_cast<save_type> (ctmp), nz, swap, fmt);
342
343 if (! is)
344 return false;
345
346 if (! m.indices_ok ())
347 return false;
348
349 matrix = m;
350
351 return true;
352}
353
354bool
356 bool save_as_floats)
357{
358 bool retval = false;
359
360#if defined (HAVE_HDF5)
361
362 const dim_vector& dv = dims ();
363 int empty = save_hdf5_empty (loc_id, name, dv);
364 if (empty)
365 return (empty > 0);
366
367 // Ensure that additional memory is deallocated
369
370#if defined (HAVE_HDF5_18)
371 hid_t group_hid = H5Gcreate (loc_id, name, octave_H5P_DEFAULT,
373#else
374 hid_t group_hid = H5Gcreate (loc_id, name, 0);
375#endif
376 if (group_hid < 0)
377 return false;
378
379 hid_t space_hid, data_hid;
380 space_hid = data_hid = -1;
382 octave_idx_type tmp;
383 hsize_t hdims[2];
384
385 space_hid = H5Screate_simple (0, hdims, nullptr);
386 if (space_hid < 0)
387 {
388 H5Gclose (group_hid);
389 return false;
390 }
391#if defined (HAVE_HDF5_18)
392 data_hid = H5Dcreate (group_hid, "nr", H5T_NATIVE_IDX, space_hid,
395#else
396 data_hid = H5Dcreate (group_hid, "nr", H5T_NATIVE_IDX, space_hid,
398#endif
399 if (data_hid < 0)
400 {
401 H5Sclose (space_hid);
402 H5Gclose (group_hid);
403 return false;
404 }
405
406 tmp = m.rows ();
407 retval = H5Dwrite (data_hid, H5T_NATIVE_IDX, octave_H5S_ALL, octave_H5S_ALL,
408 octave_H5P_DEFAULT, &tmp) >= 0;
409 H5Dclose (data_hid);
410 if (! retval)
411 {
412 H5Sclose (space_hid);
413 H5Gclose (group_hid);
414 return false;
415 }
416#if defined (HAVE_HDF5_18)
417 data_hid = H5Dcreate (group_hid, "nc", H5T_NATIVE_IDX, space_hid,
420#else
421 data_hid = H5Dcreate (group_hid, "nc", H5T_NATIVE_IDX, space_hid,
423#endif
424 if (data_hid < 0)
425 {
426 H5Sclose (space_hid);
427 H5Gclose (group_hid);
428 return false;
429 }
430
431 tmp = m.cols ();
432 retval = H5Dwrite (data_hid, H5T_NATIVE_IDX, octave_H5S_ALL, octave_H5S_ALL,
433 octave_H5P_DEFAULT, &tmp) >= 0;
434 H5Dclose (data_hid);
435 if (! retval)
436 {
437 H5Sclose (space_hid);
438 H5Gclose (group_hid);
439 return false;
440 }
441
442#if defined (HAVE_HDF5_18)
443 data_hid = H5Dcreate (group_hid, "nz", H5T_NATIVE_IDX, space_hid,
446#else
447 data_hid = H5Dcreate (group_hid, "nz", H5T_NATIVE_IDX, space_hid,
449#endif
450 if (data_hid < 0)
451 {
452 H5Sclose (space_hid);
453 H5Gclose (group_hid);
454 return false;
455 }
456
457 tmp = m.nnz ();
458 retval = H5Dwrite (data_hid, H5T_NATIVE_IDX, octave_H5S_ALL, octave_H5S_ALL,
459 octave_H5P_DEFAULT, &tmp) >= 0;
460 H5Dclose (data_hid);
461 if (! retval)
462 {
463 H5Sclose (space_hid);
464 H5Gclose (group_hid);
465 return false;
466 }
467
468 H5Sclose (space_hid);
469
470 hdims[0] = m.cols () + 1;
471 hdims[1] = 1;
472
473 space_hid = H5Screate_simple (2, hdims, nullptr);
474
475 if (space_hid < 0)
476 {
477 H5Gclose (group_hid);
478 return false;
479 }
480
481#if defined (HAVE_HDF5_18)
482 data_hid = H5Dcreate (group_hid, "cidx", H5T_NATIVE_IDX, space_hid,
485#else
486 data_hid = H5Dcreate (group_hid, "cidx", H5T_NATIVE_IDX, space_hid,
488#endif
489 if (data_hid < 0)
490 {
491 H5Sclose (space_hid);
492 H5Gclose (group_hid);
493 return false;
494 }
495
496 octave_idx_type *itmp = m.xcidx ();
497 retval = H5Dwrite (data_hid, H5T_NATIVE_IDX, octave_H5S_ALL, octave_H5S_ALL,
498 octave_H5P_DEFAULT, itmp) >= 0;
499 H5Dclose (data_hid);
500 if (! retval)
501 {
502 H5Sclose (space_hid);
503 H5Gclose (group_hid);
504 return false;
505 }
506
507 H5Sclose (space_hid);
508
509 hdims[0] = m.nnz ();
510 hdims[1] = 1;
511
512 space_hid = H5Screate_simple (2, hdims, nullptr);
513
514 if (space_hid < 0)
515 {
516 H5Gclose (group_hid);
517 return false;
518 }
519#if defined (HAVE_HDF5_18)
520 data_hid = H5Dcreate (group_hid, "ridx", H5T_NATIVE_IDX, space_hid,
523#else
524 data_hid = H5Dcreate (group_hid, "ridx", H5T_NATIVE_IDX, space_hid,
526#endif
527 if (data_hid < 0)
528 {
529 H5Sclose (space_hid);
530 H5Gclose (group_hid);
531 return false;
532 }
533
534 itmp = m.xridx ();
535 retval = H5Dwrite (data_hid, H5T_NATIVE_IDX, octave_H5S_ALL, octave_H5S_ALL,
536 octave_H5P_DEFAULT, itmp) >= 0;
537 H5Dclose (data_hid);
538 if (! retval)
539 {
540 H5Sclose (space_hid);
541 H5Gclose (group_hid);
542 return false;
543 }
544
545 hid_t save_type_hid = H5T_NATIVE_DOUBLE;
546
547 if (save_as_floats)
548 {
549 if (m.too_large_for_float ())
550 {
551 warning ("save: some values too large to save as floats --");
552 warning ("save: saving as doubles instead");
553 }
554 else
555 save_type_hid = H5T_NATIVE_FLOAT;
556 }
557#if defined (HAVE_HDF5_INT2FLOAT_CONVERSIONS)
558 // hdf5 currently doesn't support float/integer conversions
559 else
560 {
561 double max_val, min_val;
562
563 if (m.all_integers (max_val, min_val))
564 save_type_hid
565 = save_type_to_hdf5 (octave::get_save_type (max_val, min_val));
566 }
567#endif
568
569#if defined (HAVE_HDF5_18)
570 data_hid = H5Dcreate (group_hid, "data", save_type_hid, space_hid,
573#else
574 data_hid = H5Dcreate (group_hid, "data", save_type_hid, space_hid,
576#endif
577 if (data_hid < 0)
578 {
579 H5Sclose (space_hid);
580 H5Gclose (group_hid);
581 return false;
582 }
583
584 double *dtmp = m.xdata ();
585 retval = H5Dwrite (data_hid, H5T_NATIVE_DOUBLE, octave_H5S_ALL,
587 H5Dclose (data_hid);
588 H5Sclose (space_hid);
589 H5Gclose (group_hid);
590
591#else
592 octave_unused_parameter (loc_id);
593 octave_unused_parameter (name);
594 octave_unused_parameter (save_as_floats);
595
596 warn_save ("hdf5");
597#endif
598
599 return retval;
600}
601
602bool
604{
605 bool retval = false;
606
607#if defined (HAVE_HDF5)
608
609 octave_idx_type nr, nc, nz;
610 hid_t group_hid, data_hid, space_hid;
611 hsize_t rank;
612
613 dim_vector dv;
614 int empty = load_hdf5_empty (loc_id, name, dv);
615 if (empty > 0)
616 matrix.resize (dv);
617 if (empty)
618 return (empty > 0);
619
620#if defined (HAVE_HDF5_18)
621 group_hid = H5Gopen (loc_id, name, octave_H5P_DEFAULT);
622#else
623 group_hid = H5Gopen (loc_id, name);
624#endif
625 if (group_hid < 0) return false;
626
627#if defined (HAVE_HDF5_18)
628 data_hid = H5Dopen (group_hid, "nr", octave_H5P_DEFAULT);
629#else
630 data_hid = H5Dopen (group_hid, "nr");
631#endif
632 space_hid = H5Dget_space (data_hid);
633 rank = H5Sget_simple_extent_ndims (space_hid);
634
635 if (rank != 0)
636 {
637 H5Dclose (data_hid);
638 H5Gclose (group_hid);
639 return false;
640 }
641
642 if (H5Dread (data_hid, H5T_NATIVE_IDX, octave_H5S_ALL, octave_H5S_ALL,
643 octave_H5P_DEFAULT, &nr) < 0)
644 {
645 H5Dclose (data_hid);
646 H5Gclose (group_hid);
647 return false;
648 }
649
650 H5Dclose (data_hid);
651
652#if defined (HAVE_HDF5_18)
653 data_hid = H5Dopen (group_hid, "nc", octave_H5P_DEFAULT);
654#else
655 data_hid = H5Dopen (group_hid, "nc");
656#endif
657 space_hid = H5Dget_space (data_hid);
658 rank = H5Sget_simple_extent_ndims (space_hid);
659
660 if (rank != 0)
661 {
662 H5Dclose (data_hid);
663 H5Gclose (group_hid);
664 return false;
665 }
666
667 if (H5Dread (data_hid, H5T_NATIVE_IDX, octave_H5S_ALL, octave_H5S_ALL,
668 octave_H5P_DEFAULT, &nc) < 0)
669 {
670 H5Dclose (data_hid);
671 H5Gclose (group_hid);
672 return false;
673 }
674
675 H5Dclose (data_hid);
676
677#if defined (HAVE_HDF5_18)
678 data_hid = H5Dopen (group_hid, "nz", octave_H5P_DEFAULT);
679#else
680 data_hid = H5Dopen (group_hid, "nz");
681#endif
682 space_hid = H5Dget_space (data_hid);
683 rank = H5Sget_simple_extent_ndims (space_hid);
684
685 if (rank != 0)
686 {
687 H5Dclose (data_hid);
688 H5Gclose (group_hid);
689 return false;
690 }
691
692 if (H5Dread (data_hid, H5T_NATIVE_IDX, octave_H5S_ALL, octave_H5S_ALL,
693 octave_H5P_DEFAULT, &nz) < 0)
694 {
695 H5Dclose (data_hid);
696 H5Gclose (group_hid);
697 return false;
698 }
699
700 H5Dclose (data_hid);
701
702 SparseMatrix m (static_cast<octave_idx_type> (nr),
703 static_cast<octave_idx_type> (nc),
704 static_cast<octave_idx_type> (nz));
705
706#if defined (HAVE_HDF5_18)
707 data_hid = H5Dopen (group_hid, "cidx", octave_H5P_DEFAULT);
708#else
709 data_hid = H5Dopen (group_hid, "cidx");
710#endif
711 space_hid = H5Dget_space (data_hid);
712 rank = H5Sget_simple_extent_ndims (space_hid);
713
714 if (rank != 2)
715 {
716 H5Sclose (space_hid);
717 H5Dclose (data_hid);
718 H5Gclose (group_hid);
719 return false;
720 }
721
722 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank);
723 OCTAVE_LOCAL_BUFFER (hsize_t, maxdims, rank);
724
725 H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
726
727 if (static_cast<int> (hdims[0]) != nc + 1
728 || static_cast<int> (hdims[1]) != 1)
729 {
730 H5Sclose (space_hid);
731 H5Dclose (data_hid);
732 H5Gclose (group_hid);
733 return false;
734 }
735
736 octave_idx_type *itmp = m.xcidx ();
737 if (H5Dread (data_hid, H5T_NATIVE_IDX, octave_H5S_ALL, octave_H5S_ALL,
738 octave_H5P_DEFAULT, itmp) < 0)
739 {
740 H5Sclose (space_hid);
741 H5Dclose (data_hid);
742 H5Gclose (group_hid);
743 return false;
744 }
745
746 H5Sclose (space_hid);
747 H5Dclose (data_hid);
748
749#if defined (HAVE_HDF5_18)
750 data_hid = H5Dopen (group_hid, "ridx", octave_H5P_DEFAULT);
751#else
752 data_hid = H5Dopen (group_hid, "ridx");
753#endif
754 space_hid = H5Dget_space (data_hid);
755 rank = H5Sget_simple_extent_ndims (space_hid);
756
757 if (rank != 2)
758 {
759 H5Sclose (space_hid);
760 H5Dclose (data_hid);
761 H5Gclose (group_hid);
762 return false;
763 }
764
765 H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
766
767 if (static_cast<int> (hdims[0]) != nz || static_cast<int> (hdims[1]) != 1)
768 {
769 H5Sclose (space_hid);
770 H5Dclose (data_hid);
771 H5Gclose (group_hid);
772 return false;
773 }
774
775 itmp = m.xridx ();
776 if (H5Dread (data_hid, H5T_NATIVE_IDX, octave_H5S_ALL, octave_H5S_ALL,
777 octave_H5P_DEFAULT, itmp) < 0)
778 {
779 H5Sclose (space_hid);
780 H5Dclose (data_hid);
781 H5Gclose (group_hid);
782 return false;
783 }
784
785 H5Sclose (space_hid);
786 H5Dclose (data_hid);
787
788#if defined (HAVE_HDF5_18)
789 data_hid = H5Dopen (group_hid, "data", octave_H5P_DEFAULT);
790#else
791 data_hid = H5Dopen (group_hid, "data");
792#endif
793 space_hid = H5Dget_space (data_hid);
794 rank = H5Sget_simple_extent_ndims (space_hid);
795
796 if (rank != 2)
797 {
798 H5Sclose (space_hid);
799 H5Dclose (data_hid);
800 H5Gclose (group_hid);
801 return false;
802 }
803
804 H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
805
806 if (static_cast<int> (hdims[0]) != nz || static_cast<int> (hdims[1]) != 1)
807 {
808 H5Sclose (space_hid);
809 H5Dclose (data_hid);
810 H5Gclose (group_hid);
811 return false;
812 }
813
814 double *dtmp = m.xdata ();
815
816 if (H5Dread (data_hid, H5T_NATIVE_DOUBLE, octave_H5S_ALL, octave_H5S_ALL,
817 octave_H5P_DEFAULT, dtmp) >= 0
818 && m.indices_ok ())
819 {
820 retval = true;
821 matrix = m;
822 }
823
824 H5Sclose (space_hid);
825 H5Dclose (data_hid);
826 H5Gclose (group_hid);
827
828#else
829 octave_unused_parameter (loc_id);
830 octave_unused_parameter (name);
831
832 warn_load ("hdf5");
833#endif
834
835 return retval;
836}
837
838mxArray *
839octave_sparse_matrix::as_mxArray (bool interleaved) const
840{
841 mwSize nz = nzmax ();
842 mwSize nr = rows ();
843 mwSize nc = columns ();
844
845 mxArray *retval = new mxArray (interleaved, mxDOUBLE_CLASS, nr, nc, nz,
846 mxREAL);
847
848 mxDouble *pd = static_cast<mxDouble *> (retval->get_data ());
849 mwIndex *ir = retval->get_ir ();
850
851 const double *pdata = matrix.data ();
852 const octave_idx_type *pridx = matrix.ridx ();
853
854 for (mwIndex i = 0; i < nz; i++)
855 {
856 pd[i] = pdata[i];
857
858 ir[i] = pridx[i];
859 }
860
861 mwIndex *jc = retval->get_jc ();
862
863 const octave_idx_type *pcidx = matrix.cidx ();
864
865 for (mwIndex i = 0; i < nc + 1; i++)
866 jc[i] = pcidx[i];
867
868 return retval;
869}
870
873{
874 switch (umap)
875 {
876 case umap_imag:
877 return SparseMatrix (matrix.rows (), matrix.cols (), 0.0);
878
879 case umap_real:
880 case umap_conj:
881 return matrix;
882
883 // Mappers handled specially.
884#define ARRAY_METHOD_MAPPER(UMAP, FCN) \
885 case umap_ ## UMAP: \
886 return octave_value (matrix.FCN ())
887
889
890#define ARRAY_MAPPER(UMAP, TYPE, FCN) \
891 case umap_ ## UMAP: \
892 return octave_value (matrix.map<TYPE> (FCN))
893
894 ARRAY_MAPPER (acos, Complex, octave::math::rc_acos);
895 ARRAY_MAPPER (acosh, Complex, octave::math::rc_acosh);
896 ARRAY_MAPPER (angle, double, std::arg);
897 ARRAY_MAPPER (arg, double, std::arg);
898 ARRAY_MAPPER (asin, Complex, octave::math::rc_asin);
899 ARRAY_MAPPER (asinh, double, octave::math::asinh);
900 ARRAY_MAPPER (atan, double, ::atan);
901 ARRAY_MAPPER (atanh, Complex, octave::math::rc_atanh);
902 ARRAY_MAPPER (erf, double, octave::math::erf);
903 ARRAY_MAPPER (erfinv, double, octave::math::erfinv);
904 ARRAY_MAPPER (erfcinv, double, octave::math::erfcinv);
905 ARRAY_MAPPER (erfc, double, octave::math::erfc);
906 ARRAY_MAPPER (erfcx, double, octave::math::erfcx);
907 ARRAY_MAPPER (erfi, double, octave::math::erfi);
908 ARRAY_MAPPER (dawson, double, octave::math::dawson);
909 ARRAY_MAPPER (gamma, double, octave::math::gamma);
910 ARRAY_MAPPER (lgamma, Complex, octave::math::rc_lgamma);
911 ARRAY_MAPPER (cbrt, double, octave::math::cbrt);
912 ARRAY_MAPPER (ceil, double, ::ceil);
913 ARRAY_MAPPER (cos, double, ::cos);
914 ARRAY_MAPPER (cosh, double, ::cosh);
915 ARRAY_MAPPER (exp, double, ::exp);
916 ARRAY_MAPPER (expm1, double, octave::math::expm1);
917 ARRAY_MAPPER (fix, double, octave::math::fix);
918 ARRAY_MAPPER (floor, double, ::floor);
919 ARRAY_MAPPER (log, Complex, octave::math::rc_log);
920 ARRAY_MAPPER (log2, Complex, octave::math::rc_log2);
921 ARRAY_MAPPER (log10, Complex, octave::math::rc_log10);
922 ARRAY_MAPPER (log1p, Complex, octave::math::rc_log1p);
923 ARRAY_MAPPER (round, double, octave::math::round);
924 ARRAY_MAPPER (roundb, double, octave::math::roundb);
925 ARRAY_MAPPER (signum, double, octave::math::signum);
926 ARRAY_MAPPER (sin, double, ::sin);
927 ARRAY_MAPPER (sinh, double, ::sinh);
928 ARRAY_MAPPER (sqrt, Complex, octave::math::rc_sqrt);
929 ARRAY_MAPPER (tan, double, ::tan);
930 ARRAY_MAPPER (tanh, double, ::tanh);
931 ARRAY_MAPPER (isnan, bool, octave::math::isnan);
932 ARRAY_MAPPER (isna, bool, octave::math::isna);
933 ARRAY_MAPPER (isinf, bool, octave::math::isinf);
934 ARRAY_MAPPER (isfinite, bool, octave::math::isfinite);
935
936 default: // Attempt to go via dense matrix.
938 }
939}
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 any_element_not_one_or_zero() const
Definition dNDArray.cc:330
bool any_element_is_nan() const
Definition dNDArray.cc:318
bool any_element_not_one_or_zero() const
Definition dSparse.cc:7202
bool all_integers(double &max_val, double &min_val) const
Definition dSparse.cc:7249
bool any_element_is_nan() const
Definition dSparse.cc:7172
bool too_large_for_float() const
Definition dSparse.cc:7277
Matrix matrix_value() const
Definition dSparse.cc:7398
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
octave_idx_type numel() const
Definition Sparse.h:340
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 numel(int n=0) const
Number of elements that a matrix with this dimensions would have.
Definition dim-vector.h:331
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
octave_idx_type nzmax() const
octave_value map(octave_base_value::unary_mapper_t umap) const
octave_idx_type numel() 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
friend class octave_value
Definition ov-base.h:278
void warn_save(const char *type) const
Definition ov-base.cc:1161
NDArray array_value(bool=false) const
mxArray * as_mxArray(bool interleaved) const
std::string type_name() const
ComplexNDArray complex_array_value(bool=false) const
ComplexMatrix complex_matrix_value(bool=false) const
bool save_binary(std::ostream &os, bool save_as_floats)
bool save_hdf5(octave_hdf5_id loc_id, const char *name, bool save_as_floats)
Complex complex_value(bool=false) const
octave::idx_vector index_vector(bool require_integers=false) const
SparseMatrix sparse_matrix_value(bool=false) const
octave_value map(unary_mapper_t umap) const
octave_value convert_to_str_internal(bool pad, bool force, char type) const
double double_value(bool=false) const
charNDArray char_array_value(bool=false) const
SparseBoolMatrix sparse_bool_matrix_value(bool warn=false) const
Matrix matrix_value(bool=false) const
bool load_hdf5(octave_hdf5_id loc_id, const char *name)
boolNDArray bool_array_value(bool warn=false) const
octave_value as_double() const
bool load_binary(std::istream &is, bool swap, octave::mach_info::float_format fmt)
const octave_hdf5_id octave_H5P_DEFAULT
const octave_hdf5_id octave_H5S_ALL
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
function gamma(x)
Definition gamma.f:3
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
F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
double erfinv(double x)
double erfi(double x)
double dawson(double x)
Complex erf(const Complex &x)
double erfcinv(double x)
double erfcx(double x)
Complex expm1(const Complex &x)
Complex log1p(const Complex &x)
Complex erfc(const Complex &x)
double cbrt(double x)
Definition lo-specfun.h:289
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
double lgamma(double x)
Definition lo-specfun.h:336
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
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)