GNU Octave 11.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
ov-re-mat.cc
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 1996-2026 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 <clocale>
31#include <istream>
32#include <limits>
33#include <ostream>
34#include <vector>
35
36#include "dNDArray.h"
37#include "fNDArray.h"
38#include "int16NDArray.h"
39#include "int32NDArray.h"
40#include "int64NDArray.h"
41#include "int8NDArray.h"
42#include "uint16NDArray.h"
43#include "uint32NDArray.h"
44#include "uint64NDArray.h"
45#include "uint8NDArray.h"
46
47#include "data-conv.h"
48#include "lo-ieee.h"
49#include "lo-utils.h"
50#include "mach-info.h"
51#include "mappers.h"
52#include "mx-base.h"
53#include "oct-locbuf.h"
54#include "oct-specfun.h"
55#include "quit.h"
56
57#include "defun.h"
58#include "errwarn.h"
59#include "mxarray.h"
60#include "ovl.h"
61#include "oct-lvalue.h"
62#include "oct-hdf5.h"
63#include "oct-stream.h"
64#include "ops.h"
65#include "ov-base.h"
66#include "ov-scalar.h"
67#include "ov-re-mat.h"
68#include "ov-flt-re-mat.h"
69#include "ov-complex.h"
70#include "ov-cx-mat.h"
71#include "ov-re-sparse.h"
72#include "ov-re-diag.h"
73#include "ov-cx-diag.h"
74#include "ov-lazy-idx.h"
75#include "ov-perm.h"
76#include "pr-flt-fmt.h"
77#include "pr-output.h"
78#include "variables.h"
79
80#include "byte-swap.h"
81#include "ls-oct-text.h"
82#include "ls-utils.h"
83#include "ls-hdf5.h"
84
85
87
88static octave_base_value *
89default_numeric_demotion_function (const octave_base_value& a)
90{
91 const octave_matrix& v = dynamic_cast<const octave_matrix&> (a);
92
93 return new octave_float_matrix (v.float_array_value ());
94}
95
98{
100 (default_numeric_demotion_function,
102}
103
106{
107 octave_base_value *retval = nullptr;
108
109 if (m_matrix.numel () == 1)
110 retval = new octave_scalar (m_matrix (0));
111
112 return retval;
113}
114
115double
117{
118 if (isempty ())
119 err_invalid_conversion ("real matrix", "real scalar");
120
121 warn_implicit_conversion ("Octave:array-to-scalar",
122 "real matrix", "real scalar");
123
124 return m_matrix(0, 0);
125}
126
127float
129{
130 if (isempty ())
131 err_invalid_conversion ("real matrix", "real scalar");
132
133 warn_implicit_conversion ("Octave:array-to-scalar",
134 "real matrix", "real scalar");
135
136 return m_matrix(0, 0);
137}
138
139// FIXME
140
141Matrix
143{
144 return Matrix (m_matrix);
145}
146
149{
150 return FloatMatrix (Matrix (m_matrix));
151}
152
155{
156 if (rows () == 0 || columns () == 0)
157 err_invalid_conversion ("real matrix", "complex scalar");
158
159 warn_implicit_conversion ("Octave:array-to-scalar",
160 "real matrix", "complex scalar");
161
162 return Complex (m_matrix(0, 0), 0);
163}
164
167{
168 float tmp = lo_ieee_float_nan_value ();
169
170 FloatComplex retval (tmp, tmp);
171
172 if (rows () == 0 || columns () == 0)
173 err_invalid_conversion ("real matrix", "complex scalar");
174
175 warn_implicit_conversion ("Octave:array-to-scalar",
176 "real matrix", "complex scalar");
177
178 retval = m_matrix(0, 0);
179
180 return retval;
181}
182
183// FIXME
184
190
196
199{
200 return ComplexNDArray (m_matrix);
201}
202
208
211{
213 octave::err_nan_to_logical_conversion ();
216
217 return boolNDArray (m_matrix);
218}
219
222{
223 charNDArray retval (dims ());
224
225 octave_idx_type nel = numel ();
226
227 for (octave_idx_type i = 0; i < nel; i++)
228 if (octave::math::isnan (m_matrix.elem (i)))
229 retval.elem (i) = 0;
230 else
231 retval.elem (i) = static_cast<char> (m_matrix.elem (i));
232
233 return retval;
234}
235
238{
239 return SparseMatrix (Matrix (m_matrix));
240}
241
244{
245 // FIXME: Need a SparseComplexMatrix (Matrix) constructor to make
246 // this function more efficient. Then this should become
247 // return SparseComplexMatrix (matrix.matrix_value ());
249}
250
253{
254 return NDArray (m_matrix);
255}
256
259{
260 return FloatNDArray (m_matrix);
261}
262
265{
266 return int8NDArray (m_matrix);
267}
268
271{
272 return int16NDArray (m_matrix);
273}
274
277{
278 return int32NDArray (m_matrix);
279}
280
283{
284 return int64NDArray (m_matrix);
285}
286
289{
290 return uint8NDArray (m_matrix);
291}
292
295{
296 return uint16NDArray (m_matrix);
297}
298
301{
302 return uint32NDArray (m_matrix);
303}
304
307{
308 return uint64NDArray (m_matrix);
309}
310
313{
314 octave_value retval;
315 if (k == 0 && m_matrix.ndims () == 2
316 && (m_matrix.rows () == 1 || m_matrix.columns () == 1))
318 else
320
321 return retval;
322}
323
326{
327 if (m_matrix.ndims () != 2
328 || (m_matrix.rows () != 1 && m_matrix.columns () != 1))
329 error ("diag: expecting vector argument");
330
331 Matrix mat (m_matrix);
332
333 return mat.diag (m, n);
334}
335
336// We override these two functions to allow reshaping both
337// the matrix and the index cache.
339octave_matrix::reshape (const dim_vector& new_dims) const
340{
341 if (m_idx_cache)
342 {
343 return new octave_matrix (m_matrix.reshape (new_dims),
344 octave::idx_vector (m_idx_cache->as_array ().reshape (new_dims),
345 m_idx_cache->extent (0)));
346 }
347 else
348 return octave_base_matrix<NDArray>::reshape (new_dims);
349}
350
353{
354 if (m_idx_cache)
355 {
356 return new octave_matrix (m_matrix.squeeze (),
357 octave::idx_vector (m_idx_cache->as_array ().squeeze (),
358 m_idx_cache->extent (0)));
359 }
360 else
362}
363
366{
367 if (m_idx_cache)
368 {
369 // This is a valid index matrix, so sort via integers because it's
370 // generally more efficient.
371 return octave_lazy_index (*m_idx_cache).sort (dim, mode);
372 }
373 else
374 return octave_base_matrix<NDArray>::sort (dim, mode);
375}
376
379 sortmode mode) const
380{
381 if (m_idx_cache)
382 {
383 // This is a valid index matrix, so sort via integers because it's
384 // generally more efficient.
385 return octave_lazy_index (*m_idx_cache).sort (sidx, dim, mode);
386 }
387 else
388 return octave_base_matrix<NDArray>::sort (sidx, dim, mode);
389}
390
393{
394 if (m_idx_cache)
395 {
396 // This is a valid index matrix, so check via integers because it's
397 // generally more efficient.
398 return m_idx_cache->as_array ().issorted (mode);
399 }
400 else
402}
405{
406 if (m_idx_cache)
407 {
408 // This is a valid index matrix, so sort via integers because it's
409 // generally more efficient.
410 return octave_lazy_index (*m_idx_cache).sort_rows_idx (mode);
411 }
412 else
414}
415
418{
419 if (m_idx_cache)
420 {
421 // This is a valid index matrix, so check via integers because it's
422 // generally more efficient.
423 return m_idx_cache->as_array ().is_sorted_rows (mode);
424 }
425 else
427}
428
430octave_matrix::convert_to_str_internal (bool, bool, char type) const
431{
432 octave_value retval;
433 const dim_vector& dv = dims ();
434 octave_idx_type nel = dv.numel ();
435
436 charNDArray chm (dv);
437
438 bool warned = false;
439
440 for (octave_idx_type i = 0; i < nel; i++)
441 {
442 octave_quit ();
443
444 double d = m_matrix(i);
445
446 if (octave::math::isnan (d))
447 octave::err_nan_to_character_conversion ();
448
449 int ival = octave::math::nint (d);
450
451 if (ival < 0 || ival > std::numeric_limits<unsigned char>::max ())
452 {
453 // FIXME: is there something better we could do?
454
455 ival = 0;
456
457 if (! warned)
458 {
459 ::warning ("range error for conversion to character value");
460 warned = true;
461 }
462 }
463
464 chm(i) = static_cast<char> (ival);
465 }
466
467 retval = octave_value (chm, type);
468
469 return retval;
470}
471
472bool
474{
475 const dim_vector& dv = dims ();
476
477 if (dv.ndims () > 2)
478 {
479 NDArray tmp = array_value ();
480
481 os << "# ndims: " << dv.ndims () << "\n";
482
483 for (int i=0; i < dv.ndims (); i++)
484 os << ' ' << dv(i);
485
486 os << "\n" << tmp;
487 }
488 else
489 {
490 // Keep this case, rather than use generic code above for backward
491 // compatibility. Makes load_ascii much more complex!!
492 os << "# rows: " << rows () << "\n"
493 << "# columns: " << columns () << "\n";
494
495 os << matrix_value ();
496 }
497
498 return true;
499}
500
501bool
503{
504 string_vector keywords(2);
505
506 keywords[0] = "ndims";
507 keywords[1] = "rows";
508
509 std::string kw;
510 octave_idx_type val = 0;
511
512 if (! extract_keyword (is, keywords, kw, val, true))
513 error ("load: failed to extract number of rows and columns");
514
515 // Set "C" locale for the duration of this function to avoid the performance
516 // panelty of frequently switching the locale when reading floating point
517 // values from the stream.
518 char *prev_locale = std::setlocale (LC_ALL, nullptr);
519 std::string old_locale (prev_locale ? prev_locale : "");
520 std::setlocale (LC_ALL, "C");
521 octave::unwind_action act
522 ([&old_locale] () { std::setlocale (LC_ALL, old_locale.c_str ()); });
523
524 if (kw == "ndims")
525 {
526 int mdims = static_cast<int> (val);
527
528 if (mdims < 0)
529 error ("load: failed to extract number of dimensions");
530
531 dim_vector dv;
532 dv.resize (mdims);
533
534 for (int i = 0; i < mdims; i++)
535 is >> dv(i);
536
537 if (! is)
538 error ("load: failed to read dimensions");
539
540 NDArray tmp(dv);
541
542 is >> tmp;
543
544 if (! is)
545 error ("load: failed to load matrix constant");
546
547 m_matrix = tmp;
548 }
549 else if (kw == "rows")
550 {
551 octave_idx_type nr = val;
552 octave_idx_type nc = 0;
553
554 if (nr < 0 || ! extract_keyword (is, "columns", nc) || nc < 0)
555 error ("load: failed to extract number of rows and columns");
556
557 if (nr > 0 && nc > 0)
558 {
559 Matrix tmp (nr, nc);
560 is >> tmp;
561 if (! is)
562 error ("load: failed to load matrix constant");
563
564 m_matrix = tmp;
565 }
566 else if (nr == 0 || nc == 0)
567 m_matrix = Matrix (nr, nc);
568 else
569 error ("unexpected dimensions in octave_matrix::load_ascii - please report this bug");
570 }
571 else
572 error ("unexpected dimensions keyword (= '%s') octave_matrix::load_ascii - please report this bug", kw.c_str ());
573
574 return true;
575}
576
577bool
578octave_matrix::save_binary (std::ostream& os, bool save_as_floats)
579{
580
581 const dim_vector& dv = dims ();
582 if (dv.ndims () < 1)
583 return false;
584
585 // Use negative value for ndims to differentiate with old format!!
586 int32_t tmp = - dv.ndims ();
587 os.write (reinterpret_cast<char *> (&tmp), 4);
588 for (int i = 0; i < dv.ndims (); i++)
589 {
590 tmp = dv(i);
591 os.write (reinterpret_cast<char *> (&tmp), 4);
592 }
593
594 NDArray m = array_value ();
595 save_type st = LS_DOUBLE;
596 if (save_as_floats)
597 {
598 if (m.too_large_for_float ())
599 {
600 warning ("save: some values too large to save as floats --");
601 warning ("save: saving as doubles instead");
602 }
603 else
604 st = LS_FLOAT;
605 }
606 else if (dv.numel () > 8192) // FIXME: make this configurable.
607 {
608 double max_val, min_val;
609 if (m.all_integers (max_val, min_val))
610 st = octave::get_save_type (max_val, min_val);
611 }
612
613 const double *mtmp = m.data ();
614 write_doubles (os, mtmp, st, dv.numel ());
615
616 return true;
617}
618
619bool
620octave_matrix::load_binary (std::istream& is, bool swap,
621 octave::mach_info::float_format fmt)
622{
623 char tmp;
624 int32_t mdims;
625 if (! is.read (reinterpret_cast<char *> (&mdims), 4))
626 return false;
627 if (swap)
628 swap_bytes<4> (&mdims);
629 if (mdims < 0)
630 {
631 mdims = - mdims;
632 int32_t di;
633 dim_vector dv;
634 dv.resize (mdims);
635
636 for (int i = 0; i < mdims; i++)
637 {
638 if (! is.read (reinterpret_cast<char *> (&di), 4))
639 return false;
640 if (swap)
641 swap_bytes<4> (&di);
642 dv(i) = di;
643 }
644
645 // Convert an array with a single dimension to be a row vector.
646 // Octave should never write files like this, other software
647 // might.
648
649 if (mdims == 1)
650 {
651 mdims = 2;
652 dv.resize (mdims);
653 dv(1) = dv(0);
654 dv(0) = 1;
655 }
656
657 if (! is.read (reinterpret_cast<char *> (&tmp), 1))
658 return false;
659
660 NDArray m(dv);
661 double *re = m.rwdata ();
662 read_doubles (is, re, static_cast<save_type> (tmp), dv.numel (),
663 swap, fmt);
664
665 if (! is)
666 return false;
667
668 m_matrix = m;
669 }
670 else
671 {
672 int32_t nr, nc;
673 nr = mdims;
674 if (! is.read (reinterpret_cast<char *> (&nc), 4))
675 return false;
676 if (swap)
677 swap_bytes<4> (&nc);
678 if (! is.read (reinterpret_cast<char *> (&tmp), 1))
679 return false;
680 Matrix m (nr, nc);
681 double *re = m.rwdata ();
682 octave_idx_type len = static_cast<octave_idx_type> (nr) * nc;
683 read_doubles (is, re, static_cast<save_type> (tmp), len, swap, fmt);
684
685 if (! is)
686 return false;
687
688 m_matrix = m;
689 }
690 return true;
691}
692
693bool
694octave_matrix::save_hdf5 (octave_hdf5_id loc_id, const char *name,
695 bool save_as_floats)
696{
697 bool retval = false;
698
699#if defined (HAVE_HDF5)
700
701 const dim_vector& dv = dims ();
702 int empty = save_hdf5_empty (loc_id, name, dv);
703 if (empty)
704 return (empty > 0);
705
706 int rank = dv.ndims ();
707 hid_t space_hid, data_hid;
708 space_hid = data_hid = -1;
709 NDArray m = array_value ();
710
711 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank);
712
713 // Octave uses column-major, while HDF5 uses row-major ordering
714 for (int i = 0; i < rank; i++)
715 hdims[i] = dv(rank-i-1);
716
717 space_hid = H5Screate_simple (rank, hdims, nullptr);
718
719 if (space_hid < 0) return false;
720
721 hid_t save_type_hid = H5T_NATIVE_DOUBLE;
722
723 if (save_as_floats)
724 {
725 if (m.too_large_for_float ())
726 {
727 warning ("save: some values too large to save as floats --");
728 warning ("save: saving as doubles instead");
729 }
730 else
731 save_type_hid = H5T_NATIVE_FLOAT;
732 }
733#if defined (HAVE_HDF5_INT2FLOAT_CONVERSIONS)
734 // hdf5 currently doesn't support float/integer conversions
735 else
736 {
737 double max_val, min_val;
738
739 if (m.all_integers (max_val, min_val))
740 save_type_hid
741 = save_type_to_hdf5 (octave::get_save_type (max_val, min_val));
742 }
743#endif
744
745#if defined (HAVE_HDF5_18)
746 data_hid = H5Dcreate (loc_id, name, save_type_hid, space_hid,
749#else
750 data_hid = H5Dcreate (loc_id, name, save_type_hid, space_hid,
752#endif
753 if (data_hid < 0)
754 {
755 H5Sclose (space_hid);
756 return false;
757 }
758
759 const double *mtmp = m.data ();
760 retval = H5Dwrite (data_hid, H5T_NATIVE_DOUBLE, octave_H5S_ALL,
762
763 H5Dclose (data_hid);
764 H5Sclose (space_hid);
765
766#else
767 octave_unused_parameter (loc_id);
768 octave_unused_parameter (name);
769 octave_unused_parameter (save_as_floats);
770
771 warn_save ("hdf5");
772#endif
773
774 return retval;
775}
776
777bool
778octave_matrix::load_hdf5 (octave_hdf5_id loc_id, const char *name)
779{
780 bool retval = false;
781
782#if defined (HAVE_HDF5)
783
784 dim_vector dv;
785 int empty = load_hdf5_empty (loc_id, name, dv);
786 if (empty > 0)
787 m_matrix.resize (dv);
788 if (empty)
789 return (empty > 0);
790
791#if defined (HAVE_HDF5_18)
792 hid_t data_hid = H5Dopen (loc_id, name, octave_H5P_DEFAULT);
793#else
794 hid_t data_hid = H5Dopen (loc_id, name);
795#endif
796 hid_t space_id = H5Dget_space (data_hid);
797
798 hsize_t rank = H5Sget_simple_extent_ndims (space_id);
799
800 if (rank < 1)
801 {
802 H5Sclose (space_id);
803 H5Dclose (data_hid);
804 return false;
805 }
806
807 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank);
808 OCTAVE_LOCAL_BUFFER (hsize_t, maxdims, rank);
809
810 H5Sget_simple_extent_dims (space_id, hdims, maxdims);
811
812 // Octave uses column-major, while HDF5 uses row-major ordering
813 if (rank == 1)
814 {
815 dv.resize (2);
816 dv(0) = 1;
817 dv(1) = hdims[0];
818 }
819 else
820 {
821 dv.resize (rank);
822 for (hsize_t i = 0, j = rank - 1; i < rank; i++, j--)
823 dv(j) = hdims[i];
824 }
825
826 NDArray m (dv);
827 double *re = m.rwdata ();
828 if (H5Dread (data_hid, H5T_NATIVE_DOUBLE, octave_H5S_ALL, octave_H5S_ALL,
829 octave_H5P_DEFAULT, re) >= 0)
830 {
831 retval = true;
832 m_matrix = m;
833 }
834
835 H5Sclose (space_id);
836 H5Dclose (data_hid);
837
838#else
839 octave_unused_parameter (loc_id);
840 octave_unused_parameter (name);
841
842 warn_load ("hdf5");
843#endif
844
845 return retval;
846}
847
848void
849octave_matrix::print_raw (std::ostream& os,
850 bool pr_as_read_syntax) const
851{
852 octave_print_internal (os, m_matrix, pr_as_read_syntax,
854}
855
856mxArray *
857octave_matrix::as_mxArray (bool interleaved) const
858{
859 mxArray *retval = new mxArray (interleaved, mxDOUBLE_CLASS, dims (), mxREAL);
860
861 mxDouble *pd = static_cast<mxDouble *> (retval->get_data ());
862
863 mwSize nel = numel ();
864
865 const double *pdata = m_matrix.data ();
866
867 for (mwIndex i = 0; i < nel; i++)
868 pd[i] = pdata[i];
869
870 return retval;
871}
872
873// This uses a smarter strategy for doing the complex->real mappers. We
874// allocate an array for a real result and keep filling it until a complex
875// result is produced.
876static octave_value
877do_rc_map (const NDArray& a, Complex (&fcn) (double))
878{
879 octave_idx_type n = a.numel ();
880 NDArray rr (a.dims ());
881
882 for (octave_idx_type i = 0; i < n; i++)
883 {
884 octave_quit ();
885
886 Complex tmp = fcn (a(i));
887 if (tmp.imag () == 0.0)
888 rr.xelem (i) = tmp.real ();
889 else
890 {
891 ComplexNDArray rc (a.dims ());
892
893 for (octave_idx_type j = 0; j < i; j++)
894 rc.xelem (j) = rr.xelem (j);
895
896 rc.xelem (i) = tmp;
897
898 for (octave_idx_type j = i+1; j < n; j++)
899 {
900 octave_quit ();
901
902 rc.xelem (j) = fcn (a(j));
903 }
904
905 return new octave_complex_matrix (rc);
906 }
907 }
908
909 return rr;
910}
911
914{
915 switch (umap)
916 {
917 case umap_imag:
918 return NDArray (m_matrix.dims (), 0.0);
919
920 case umap_real:
921 case umap_conj:
922 return m_matrix;
923
924 // Mappers handled specially.
925#define ARRAY_METHOD_MAPPER(UMAP, FCN) \
926 case umap_ ## UMAP: \
927 return octave_value (m_matrix.FCN ())
928
933
934#define ARRAY_MAPPER(UMAP, TYPE, FCN) \
935 case umap_ ## UMAP: \
936 return octave_value (m_matrix.map<TYPE> (FCN))
937
938#define RC_ARRAY_MAPPER(UMAP, TYPE, FCN) \
939 case umap_ ## UMAP: \
940 return do_rc_map (m_matrix, FCN)
941
942 RC_ARRAY_MAPPER (acos, Complex, octave::math::rc_acos);
943 RC_ARRAY_MAPPER (acosh, Complex, octave::math::rc_acosh);
944 ARRAY_MAPPER (angle, double, std::arg);
945 ARRAY_MAPPER (arg, double, std::arg);
946 RC_ARRAY_MAPPER (asin, Complex, octave::math::rc_asin);
947 ARRAY_MAPPER (asinh, double, octave::math::asinh);
948 ARRAY_MAPPER (atan, double, ::atan);
949 RC_ARRAY_MAPPER (atanh, Complex, octave::math::rc_atanh);
950 ARRAY_MAPPER (erf, double, octave::math::erf);
951 ARRAY_MAPPER (erfinv, double, octave::math::erfinv);
952 ARRAY_MAPPER (erfcinv, double, octave::math::erfcinv);
953 ARRAY_MAPPER (erfc, double, octave::math::erfc);
954 ARRAY_MAPPER (erfcx, double, octave::math::erfcx);
955 ARRAY_MAPPER (erfi, double, octave::math::erfi);
956 ARRAY_MAPPER (dawson, double, octave::math::dawson);
957 ARRAY_MAPPER (gamma, double, octave::math::gamma);
958 RC_ARRAY_MAPPER (lgamma, Complex, octave::math::rc_lgamma);
959 ARRAY_MAPPER (cbrt, double, octave::math::cbrt);
960 ARRAY_MAPPER (ceil, double, ::ceil);
961 ARRAY_MAPPER (cos, double, ::cos);
962 ARRAY_MAPPER (cosh, double, ::cosh);
963 ARRAY_MAPPER (exp, double, ::exp);
964 ARRAY_MAPPER (expm1, double, octave::math::expm1);
965 ARRAY_MAPPER (fix, double, octave::math::fix);
966 ARRAY_MAPPER (floor, double, ::floor);
967 RC_ARRAY_MAPPER (log, Complex, octave::math::rc_log);
968 RC_ARRAY_MAPPER (log2, Complex, octave::math::rc_log2);
969 RC_ARRAY_MAPPER (log10, Complex, octave::math::rc_log10);
970 RC_ARRAY_MAPPER (log1p, Complex, octave::math::rc_log1p);
971 ARRAY_MAPPER (round, double, octave::math::round);
972 ARRAY_MAPPER (roundb, double, octave::math::roundb);
973 ARRAY_MAPPER (signum, double, octave::math::signum);
974 ARRAY_MAPPER (sin, double, ::sin);
975 ARRAY_MAPPER (sinh, double, ::sinh);
976 RC_ARRAY_MAPPER (sqrt, Complex, octave::math::rc_sqrt);
977 ARRAY_MAPPER (tan, double, ::tan);
978 ARRAY_MAPPER (tanh, double, ::tanh);
979 ARRAY_MAPPER (isna, bool, octave::math::isna);
980 ARRAY_MAPPER (xsignbit, double, octave::math::signbit);
981
982 // Special cases for Matlab compatibility.
983 case umap_xtolower:
984 case umap_xtoupper:
985 return m_matrix;
986
987 case umap_xisalnum:
988 case umap_xisalpha:
989 case umap_xisascii:
990 case umap_xiscntrl:
991 case umap_xisdigit:
992 case umap_xisgraph:
993 case umap_xislower:
994 case umap_xisprint:
995 case umap_xispunct:
996 case umap_xisspace:
997 case umap_xisupper:
998 case umap_xisxdigit:
999 {
1000 octave_value str_conv = convert_to_str (true, true);
1001 return str_conv.map (umap);
1002 }
1003
1004 default:
1005 return octave_base_value::map (umap);
1006 }
1007}
void swap_bytes< 4 >(void *ptr)
Definition byte-swap.h:63
N Dimensional Array with copy-on-write semantics.
Definition Array-base.h:130
const dim_vector & dims() const
Return a const-reference so that dims ()(i) works efficiently.
Definition Array-base.h:529
T & elem(octave_idx_type n)
Size of the specified dimension.
Definition Array-base.h:585
int ndims() const
Size of the specified dimension.
Definition Array-base.h:701
octave_idx_type rows() const
Definition Array-base.h:485
void resize(const dim_vector &dv, const T &rfv)
Size of the specified dimension.
octave_idx_type columns() const
Definition Array-base.h:497
const T * data() const
Size of the specified dimension.
Definition Array-base.h:687
T * rwdata()
Size of the specified dimension.
octave_idx_type numel() const
Number of elements in the array.
Definition Array-base.h:440
MArray< T > reshape(const dim_vector &new_dims) const
Definition MArray.h:91
Matrix diag(octave_idx_type k=0) const
Definition dMatrix.cc:2413
bool any_element_not_one_or_zero() const
Definition dNDArray.cc:330
bool any_element_is_nan() const
Definition dNDArray.cc:318
bool all_integers(double &max_val, double &min_val) const
Definition dNDArray.cc:351
bool too_large_for_float() const
Definition dNDArray.cc:387
NDArray squeeze() const
Definition dNDArray.h:150
Vector representing the dimensions (size) of an Array.
Definition dim-vector.h:92
octave_idx_type numel(int n=0) const
Number of elements that a matrix with this dimensions would have.
Definition dim-vector.h:341
void resize(int n, int fill_value=0)
Definition dim-vector.h:278
octave_idx_type ndims() const
Number of dimensions.
Definition dim-vector.h:263
void * get_data() const
Definition mxarray.h:482
octave::idx_vector * m_idx_cache
octave_value diag(octave_idx_type k=0) const
octave_idx_type numel() const
sortmode issorted(sortmode mode=UNSORTED) const
sortmode is_sorted_rows(sortmode mode=UNSORTED) const
octave_value sort(octave_idx_type dim=0, sortmode mode=ASCENDING) const
octave_value squeeze() const
Definition ov-base-mat.h:82
Array< octave_idx_type > sort_rows_idx(sortmode mode=ASCENDING) const
octave_value reshape(const dim_vector &new_dims) const
octave_idx_type rows() const
Definition ov-base.h:384
octave_idx_type columns() const
Definition ov-base.h:391
int current_print_indent_level() const
Definition ov-base.h:945
virtual octave_value map(unary_mapper_t) const
Definition ov-base.cc:1170
virtual octave_value convert_to_str(bool pad=false, bool force=false, char type='\'') const
Definition ov-base.cc:431
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
static int static_type_id()
octave_value sort(octave_idx_type dim=0, sortmode mode=ASCENDING) const
Array< octave_idx_type > sort_rows_idx(sortmode mode=ASCENDING) const
FloatComplexMatrix float_complex_matrix_value(bool=false) const
Definition ov-re-mat.cc:192
boolNDArray bool_array_value(bool warn=false) const
Definition ov-re-mat.cc:210
Array< octave_idx_type > sort_rows_idx(sortmode mode=ASCENDING) const
Definition ov-re-mat.cc:404
type_conv_info numeric_demotion_function() const
Definition ov-re-mat.cc:97
SparseMatrix sparse_matrix_value(bool=false) const
Definition ov-re-mat.cc:237
octave_value as_uint32() const
Definition ov-re-mat.cc:300
bool load_ascii(std::istream &is)
Definition ov-re-mat.cc:502
octave_value as_int64() const
Definition ov-re-mat.cc:282
FloatComplex float_complex_value(bool=false) const
Definition ov-re-mat.cc:166
float float_value(bool=false) const
Definition ov-re-mat.cc:128
octave_base_value * try_narrowing_conversion()
Definition ov-re-mat.cc:105
octave_value as_int8() const
Definition ov-re-mat.cc:264
charNDArray char_array_value(bool=false) const
Definition ov-re-mat.cc:221
FloatMatrix float_matrix_value(bool=false) const
Definition ov-re-mat.cc:148
bool save_binary(std::ostream &os, bool save_as_floats)
Definition ov-re-mat.cc:578
octave_value squeeze() const
Definition ov-re-mat.cc:352
bool save_ascii(std::ostream &os)
Definition ov-re-mat.cc:473
SparseComplexMatrix sparse_complex_matrix_value(bool=false) const
Definition ov-re-mat.cc:243
octave_value as_uint64() const
Definition ov-re-mat.cc:306
FloatComplexNDArray float_complex_array_value(bool=false) const
Definition ov-re-mat.cc:204
bool load_binary(std::istream &is, bool swap, octave::mach_info::float_format fmt)
Definition ov-re-mat.cc:620
void print_raw(std::ostream &os, bool pr_as_read_syntax=false) const
Definition ov-re-mat.cc:849
octave_value sort(octave_idx_type dim=0, sortmode mode=ASCENDING) const
Definition ov-re-mat.cc:365
bool save_hdf5(octave_hdf5_id loc_id, const char *name, bool save_as_floats)
Definition ov-re-mat.cc:694
octave_value as_single() const
Definition ov-re-mat.cc:258
octave_value as_int16() const
Definition ov-re-mat.cc:270
Complex complex_value(bool=false) const
Definition ov-re-mat.cc:154
ComplexNDArray complex_array_value(bool=false) const
Definition ov-re-mat.cc:198
octave_value reshape(const dim_vector &new_dims) const
Definition ov-re-mat.cc:339
Matrix matrix_value(bool=false) const
Definition ov-re-mat.cc:142
octave_value diag(octave_idx_type k=0) const
Definition ov-re-mat.cc:312
octave_value map(unary_mapper_t umap) const
Definition ov-re-mat.cc:913
mxArray * as_mxArray(bool interleaved) const
Definition ov-re-mat.cc:857
bool load_hdf5(octave_hdf5_id loc_id, const char *name)
Definition ov-re-mat.cc:778
sortmode issorted(sortmode mode=UNSORTED) const
Definition ov-re-mat.cc:392
ComplexMatrix complex_matrix_value(bool=false) const
Definition ov-re-mat.cc:186
octave_value as_int32() const
Definition ov-re-mat.cc:276
FloatNDArray float_array_value(bool=false) const
Definition ov-re-mat.h:177
octave_value as_uint8() const
Definition ov-re-mat.cc:288
octave_value as_double() const
Definition ov-re-mat.cc:252
octave_value convert_to_str_internal(bool pad, bool force, char type) const
Definition ov-re-mat.cc:430
sortmode is_sorted_rows(sortmode mode=UNSORTED) const
Definition ov-re-mat.cc:417
octave_value as_uint16() const
Definition ov-re-mat.cc:294
NDArray array_value(bool=false) const
Definition ov-re-mat.h:175
double double_value(bool=false) const
Definition ov-re-mat.cc:116
octave_value map(octave_base_value::unary_mapper_t umap) const
Definition ov.h:1526
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:820
void write_doubles(std::ostream &os, const double *data, save_type type, octave_idx_type len)
Definition data-conv.cc:960
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:1083
void error(const char *fmt,...)
Definition error.cc:1008
void err_invalid_conversion(const std::string &from, const std::string &to)
Definition errwarn.cc:71
void warn_logical_conversion()
Definition errwarn.cc:366
void warn_implicit_conversion(const char *id, const char *from, const char *to)
Definition errwarn.cc:345
function gamma(x)
Definition gamma.f:3
intNDArray< octave_int16 > int16NDArray
intNDArray< octave_int32 > int32NDArray
intNDArray< octave_int64 > int64NDArray
intNDArray< octave_int8 > int8NDArray
Definition int8NDArray.h:36
Complex log2(const Complex &x)
Definition mappers.cc:140
Complex asin(const Complex &x)
Definition mappers.cc:106
bool isna(double x)
Definition mappers.cc:46
Complex acos(const Complex &x)
Definition mappers.cc:84
float lo_ieee_float_nan_value()
Definition lo-ieee.cc:116
int save_hdf5_empty(octave_hdf5_id loc_id, const char *name, const dim_vector &d)
Definition ls-hdf5.cc:1255
int load_hdf5_empty(octave_hdf5_id loc_id, const char *name, dim_vector &d)
Definition ls-hdf5.cc:1312
octave_hdf5_id save_type_to_hdf5(save_type st)
Definition ls-hdf5.cc:1356
std::string extract_keyword(std::istream &is, const char *keyword, const bool next_only)
std::complex< T > ceil(const std::complex< T > &x)
Definition mappers.h:115
Complex atan(const Complex &x)
Definition mappers.h:83
double roundb(double x)
Definition mappers.h:159
std::complex< T > floor(const std::complex< T > &x)
Definition mappers.h:142
bool isfinite(double x)
Definition mappers.h:229
bool isinf(double x)
Definition mappers.h:212
double signum(double x)
Definition mappers.h:255
double round(double x)
Definition mappers.h:148
bool isnan(bool)
Definition mappers.h:192
double fix(double x)
Definition mappers.h:130
std::complex< double > Complex
Definition oct-cmplx.h:33
std::complex< float > FloatComplex
Definition oct-cmplx.h:34
int64_t octave_hdf5_id
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
Definition oct-locbuf.h:44
sortmode
Definition oct-sort.h:97
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)
double asinh(double x)
Definition oct-specfun.h:57
double atanh(double x)
Definition oct-specfun.h:62
double acosh(double x)
Definition oct-specfun.h:39
double lgamma(double x)
#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)
#define RC_ARRAY_MAPPER(UMAP, TYPE, FCN)
void octave_print_internal(std::ostream &os, const float_display_format &fmt, bool d, bool pr_as_read_syntax)
template int8_t abs(int8_t)
F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
intNDArray< octave_uint16 > uint16NDArray
intNDArray< octave_uint32 > uint32NDArray
intNDArray< octave_uint64 > uint64NDArray
intNDArray< octave_uint8 > uint8NDArray
F77_RET_T len
Definition xerbla.cc:61