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