Mercurial > octave
comparison libinterp/corefcn/data.cc @ 29961:7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
Files affected: __betainc__.cc, __contourc__.cc, __eigs__.cc,
__expint__.cc, __ftp__.cc, __gammainc__.cc, __ichol__.cc, __ilu__.cc,
__magick_read__.cc, __pchip_deriv__.cc, __qp__.cc, amd.cc, balance.cc,
besselj.cc, bsxfun.cc, call-stack.cc, ccolamd.cc, cellfun.cc, chol.cc,
colamd.cc, colloc.cc, conv2.cc, daspk.cc, dasrt.cc, dassl.cc, data.cc,
defaults.cc, dirfns.cc, display.cc, dlmread.cc, dmperm.cc, dot.cc,
eig.cc, ellipj.cc, environment.cc, error.cc, event-manager.cc, fft.cc,
fft2.cc, fftn.cc, file-io.cc, find.cc, gcd.cc, getgrent.cc,
getpwent.cc, getrusage.cc, gsvd.cc, hash.cc, help.cc, hess.cc,
hex2num.cc, input.cc, inv.cc, jsondecode.cc, jsonencode.cc,
load-path.cc, load-save.cc, lookup.cc, lsode.cc, lu.cc, max.cc,
mgorth.cc, oct-hist.cc, ordqz.cc, ordschur.cc, pager.cc, pr-output.cc,
psi.cc, qr.cc, quad.cc, quadcc.cc, qz.cc, rand.cc, regexp.cc,
schur.cc, settings.cc, sighandlers.cc, sparse.cc, spparms.cc,
sqrtm.cc, stream-euler.cc, strfind.cc, strfns.cc, sub2ind.cc, svd.cc,
symbfact.cc, symtab.cc, syscalls.cc, sysdep.cc, time.cc, toplev.cc,
tril.cc, typecast.cc, urlwrite.cc, utils.cc, variables.cc,
__delaunayn__.cc, __fltk_uigetfile__.cc, __glpk__.cc,
__init_gnuplot__.cc, __ode15__.cc, __voronoi__.cc, audiodevinfo.cc,
audioread.cc, convhulln.cc, fftw.cc, gzip.cc, ov-cell.cc, ov-class.cc,
ov-classdef.cc, ov-fcn-handle.cc, ov-struct.cc, ov-typeinfo.cc,
ov-usr-fcn.cc, octave.cc, lex.ll, oct-parse.yy, profiler.cc,
andpt-eval.cc.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 14 Aug 2021 22:48:52 -0400 |
parents | 9e35973fb6c0 |
children | bd02f48ac38f |
comparison
equal
deleted
inserted
replaced
29960:939bef0b66e0 | 29961:7d6709900da7 |
---|---|
451 f = Array<T>(x.dims ()); | 451 f = Array<T>(x.dims ()); |
452 e = Array<ET>(x.dims ()); | 452 e = Array<ET>(x.dims ()); |
453 for (octave_idx_type i = 0; i < x.numel (); i++) | 453 for (octave_idx_type i = 0; i < x.numel (); i++) |
454 { | 454 { |
455 int exp; | 455 int exp; |
456 f.xelem (i) = octave::math::log2 (x(i), exp); | 456 f.xelem (i) = math::log2 (x(i), exp); |
457 e.xelem (i) = exp; | 457 e.xelem (i) = exp; |
458 } | 458 } |
459 } | 459 } |
460 | 460 |
461 DEFUN (log2, args, nargout, | 461 DEFUN (log2, args, nargout, |
662 } | 662 } |
663 } | 663 } |
664 else if (args(0).is_single_type () || args(1).is_single_type ()) | 664 else if (args(0).is_single_type () || args(1).is_single_type ()) |
665 { | 665 { |
666 if (args(0).is_scalar_type () && args(1).is_scalar_type ()) | 666 if (args(0).is_scalar_type () && args(1).is_scalar_type ()) |
667 retval = octave::math::rem (args(0).float_value (), args(1).float_value ()); | 667 retval = math::rem (args(0).float_value (), args(1).float_value ()); |
668 else | 668 else |
669 { | 669 { |
670 FloatNDArray a0 = args(0).float_array_value (); | 670 FloatNDArray a0 = args(0).float_array_value (); |
671 FloatNDArray a1 = args(1).float_array_value (); | 671 FloatNDArray a1 = args(1).float_array_value (); |
672 retval = binmap<float> (a0, a1, octave::math::rem<float>, "rem"); | 672 retval = binmap<float> (a0, a1, math::rem<float>, "rem"); |
673 } | 673 } |
674 } | 674 } |
675 else | 675 else |
676 { | 676 { |
677 if (args(0).is_scalar_type () && args(1).is_scalar_type ()) | 677 if (args(0).is_scalar_type () && args(1).is_scalar_type ()) |
678 retval = octave::math::rem (args(0).scalar_value (), args(1).scalar_value ()); | 678 retval = math::rem (args(0).scalar_value (), args(1).scalar_value ()); |
679 else if (args(0).issparse () || args(1).issparse ()) | 679 else if (args(0).issparse () || args(1).issparse ()) |
680 { | 680 { |
681 SparseMatrix m0 = args(0).sparse_matrix_value (); | 681 SparseMatrix m0 = args(0).sparse_matrix_value (); |
682 SparseMatrix m1 = args(1).sparse_matrix_value (); | 682 SparseMatrix m1 = args(1).sparse_matrix_value (); |
683 retval = binmap<double> (m0, m1, octave::math::rem<double>, "rem"); | 683 retval = binmap<double> (m0, m1, math::rem<double>, "rem"); |
684 } | 684 } |
685 else | 685 else |
686 { | 686 { |
687 NDArray a0 = args(0).array_value (); | 687 NDArray a0 = args(0).array_value (); |
688 NDArray a1 = args(1).array_value (); | 688 NDArray a1 = args(1).array_value (); |
689 retval = binmap<double> (a0, a1, octave::math::rem<double>, "rem"); | 689 retval = binmap<double> (a0, a1, math::rem<double>, "rem"); |
690 } | 690 } |
691 } | 691 } |
692 | 692 |
693 return retval; | 693 return retval; |
694 } | 694 } |
844 } | 844 } |
845 } | 845 } |
846 else if (args(0).is_single_type () || args(1).is_single_type ()) | 846 else if (args(0).is_single_type () || args(1).is_single_type ()) |
847 { | 847 { |
848 if (args(0).is_scalar_type () && args(1).is_scalar_type ()) | 848 if (args(0).is_scalar_type () && args(1).is_scalar_type ()) |
849 retval = octave::math::mod (args(0).float_value (), args(1).float_value ()); | 849 retval = math::mod (args(0).float_value (), args(1).float_value ()); |
850 else | 850 else |
851 { | 851 { |
852 FloatNDArray a0 = args(0).float_array_value (); | 852 FloatNDArray a0 = args(0).float_array_value (); |
853 FloatNDArray a1 = args(1).float_array_value (); | 853 FloatNDArray a1 = args(1).float_array_value (); |
854 retval = binmap<float> (a0, a1, octave::math::mod<float>, "mod"); | 854 retval = binmap<float> (a0, a1, math::mod<float>, "mod"); |
855 } | 855 } |
856 } | 856 } |
857 else | 857 else |
858 { | 858 { |
859 if (args(0).is_scalar_type () && args(1).is_scalar_type ()) | 859 if (args(0).is_scalar_type () && args(1).is_scalar_type ()) |
860 retval = octave::math::mod (args(0).scalar_value (), args(1).scalar_value ()); | 860 retval = math::mod (args(0).scalar_value (), args(1).scalar_value ()); |
861 else if (args(0).issparse () || args(1).issparse ()) | 861 else if (args(0).issparse () || args(1).issparse ()) |
862 { | 862 { |
863 SparseMatrix m0 = args(0).sparse_matrix_value (); | 863 SparseMatrix m0 = args(0).sparse_matrix_value (); |
864 SparseMatrix m1 = args(1).sparse_matrix_value (); | 864 SparseMatrix m1 = args(1).sparse_matrix_value (); |
865 retval = binmap<double> (m0, m1, octave::math::mod<double>, "mod"); | 865 retval = binmap<double> (m0, m1, math::mod<double>, "mod"); |
866 } | 866 } |
867 else | 867 else |
868 { | 868 { |
869 NDArray a0 = args(0).array_value (); | 869 NDArray a0 = args(0).array_value (); |
870 NDArray a1 = args(1).array_value (); | 870 NDArray a1 = args(1).array_value (); |
871 retval = binmap<double> (a0, a1, octave::math::mod<double>, "mod"); | 871 retval = binmap<double> (a0, a1, math::mod<double>, "mod"); |
872 } | 872 } |
873 } | 873 } |
874 | 874 |
875 return retval; | 875 return retval; |
876 } | 876 } |
1649 // the dispatch type dtype. It will have the name of the dispatch | 1649 // the dispatch type dtype. It will have the name of the dispatch |
1650 // type. | 1650 // type. |
1651 | 1651 |
1652 std::string cname = ov.class_name (); | 1652 std::string cname = ov.class_name (); |
1653 | 1653 |
1654 octave::symbol_table& symtab | 1654 symbol_table& symtab = __get_symbol_table__ ("attempt_type_conversion"); |
1655 = octave::__get_symbol_table__ ("attempt_type_conversion"); | |
1656 | 1655 |
1657 octave_value fcn = symtab.find_method (dtype, cname); | 1656 octave_value fcn = symtab.find_method (dtype, cname); |
1658 | 1657 |
1659 if (fcn.is_defined ()) | 1658 if (fcn.is_defined ()) |
1660 { | 1659 { |
1661 octave_value_list result; | 1660 octave_value_list result; |
1662 | 1661 |
1663 try | 1662 try |
1664 { | 1663 { |
1665 result = octave::feval (fcn, ovl (ov), 1); | 1664 result = feval (fcn, ovl (ov), 1); |
1666 } | 1665 } |
1667 catch (octave::execution_exception& ee) | 1666 catch (execution_exception& ee) |
1668 { | 1667 { |
1669 error (ee, "conversion from %s to %s failed", dtype.c_str (), | 1668 error (ee, "conversion from %s to %s failed", dtype.c_str (), |
1670 cname.c_str ()); | 1669 cname.c_str ()); |
1671 } | 1670 } |
1672 | 1671 |
1688 | 1687 |
1689 octave_value_list result; | 1688 octave_value_list result; |
1690 | 1689 |
1691 try | 1690 try |
1692 { | 1691 { |
1693 result = octave::feval (fcn, ovl (ov), 1); | 1692 result = feval (fcn, ovl (ov), 1); |
1694 } | 1693 } |
1695 catch (octave::execution_exception& ee) | 1694 catch (execution_exception& ee) |
1696 { | 1695 { |
1697 error (ee, "%s constructor failed for %s argument", dtype.c_str (), | 1696 error (ee, "%s constructor failed for %s argument", dtype.c_str (), |
1698 cname.c_str ()); | 1697 cname.c_str ()); |
1699 } | 1698 } |
1700 | 1699 |
1714 { | 1713 { |
1715 octave_value retval; | 1714 octave_value retval; |
1716 | 1715 |
1717 // Get dominant type for list | 1716 // Get dominant type for list |
1718 | 1717 |
1719 std::string dtype = octave::get_dispatch_type (ovl); | 1718 std::string dtype = get_dispatch_type (ovl); |
1720 | 1719 |
1721 octave::symbol_table& symtab = octave::__get_symbol_table__ ("do_class_concat"); | 1720 symbol_table& symtab = __get_symbol_table__ ("do_class_concat"); |
1722 | 1721 |
1723 octave_value fcn = symtab.find_method (cattype, dtype); | 1722 octave_value fcn = symtab.find_method (cattype, dtype); |
1724 | 1723 |
1725 if (fcn.is_defined ()) | 1724 if (fcn.is_defined ()) |
1726 { | 1725 { |
1728 | 1727 |
1729 octave_value_list tmp2; | 1728 octave_value_list tmp2; |
1730 | 1729 |
1731 try | 1730 try |
1732 { | 1731 { |
1733 tmp2 = octave::feval (fcn, ovl, 1); | 1732 tmp2 = feval (fcn, ovl, 1); |
1734 } | 1733 } |
1735 catch (octave::execution_exception& ee) | 1734 catch (execution_exception& ee) |
1736 { | 1735 { |
1737 error (ee, "%s/%s method failed", dtype.c_str (), cattype.c_str ()); | 1736 error (ee, "%s/%s method failed", dtype.c_str (), cattype.c_str ()); |
1738 } | 1737 } |
1739 | 1738 |
1740 if (tmp2.empty ()) | 1739 if (tmp2.empty ()) |
1815 result_type = args(i).class_name (); | 1814 result_type = args(i).class_name (); |
1816 | 1815 |
1817 first_elem_is_struct = args(i).isstruct (); | 1816 first_elem_is_struct = args(i).isstruct (); |
1818 } | 1817 } |
1819 else | 1818 else |
1820 result_type = octave::get_concat_class (result_type, args(i).class_name ()); | 1819 result_type = get_concat_class (result_type, args(i).class_name ()); |
1821 | 1820 |
1822 if (all_strings_p && ! args(i).is_string ()) | 1821 if (all_strings_p && ! args(i).is_string ()) |
1823 all_strings_p = false; | 1822 all_strings_p = false; |
1824 if (all_sq_strings_p && ! args(i).is_sq_string ()) | 1823 if (all_sq_strings_p && ! args(i).is_sq_string ()) |
1825 all_sq_strings_p = false; | 1824 all_sq_strings_p = false; |
1857 args.resize (n_args); | 1856 args.resize (n_args); |
1858 } | 1857 } |
1859 | 1858 |
1860 if (any_class_p) | 1859 if (any_class_p) |
1861 { | 1860 { |
1862 retval = octave::do_class_concat (args, fname, dim); | 1861 retval = do_class_concat (args, fname, dim); |
1863 } | 1862 } |
1864 else if (result_type == "double") | 1863 else if (result_type == "double") |
1865 { | 1864 { |
1866 if (any_sparse_p) | 1865 if (any_sparse_p) |
1867 { | 1866 { |
1891 | 1890 |
1892 if (! all_strings_p) | 1891 if (! all_strings_p) |
1893 warn_implicit_conversion ("Octave:num-to-str", | 1892 warn_implicit_conversion ("Octave:num-to-str", |
1894 "numeric", result_type); | 1893 "numeric", result_type); |
1895 else | 1894 else |
1896 octave::maybe_warn_string_concat (all_dq_strings_p, all_sq_strings_p); | 1895 maybe_warn_string_concat (all_dq_strings_p, all_sq_strings_p); |
1897 | 1896 |
1898 charNDArray result = do_single_type_concat<charNDArray> (args, dim); | 1897 charNDArray result = do_single_type_concat<charNDArray> (args, dim); |
1899 | 1898 |
1900 retval = octave_value (result, type); | 1899 retval = octave_value (result, type); |
1901 } | 1900 } |
1954 // slower than the do_cat_op function, so it makes sense to have | 1953 // slower than the do_cat_op function, so it makes sense to have |
1955 // an empty matrix and copy all data. | 1954 // an empty matrix and copy all data. |
1956 // | 1955 // |
1957 // We might also start with a empty octave_value using | 1956 // We might also start with a empty octave_value using |
1958 // | 1957 // |
1959 // tmp = octave::type_info::lookup_type (args(1).type_name()); | 1958 // tmp = type_info::lookup_type (args(1).type_name()); |
1960 // | 1959 // |
1961 // and then directly resize. However, for some types there might | 1960 // and then directly resize. However, for some types there might |
1962 // be some additional setup needed, and so this should be avoided. | 1961 // be some additional setup needed, and so this should be avoided. |
1963 | 1962 |
1964 octave_value tmp = args(0); | 1963 octave_value tmp = args(0); |
1970 for (int j = 0; j < n_args; j++) | 1969 for (int j = 0; j < n_args; j++) |
1971 { | 1970 { |
1972 // Can't fast return here to skip empty matrices as something | 1971 // Can't fast return here to skip empty matrices as something |
1973 // like cat (1,[],single ([])) must return an empty matrix of | 1972 // like cat (1,[],single ([])) must return an empty matrix of |
1974 // the right type. | 1973 // the right type. |
1975 tmp = octave::cat_op (tmp, args(j), ra_idx); | 1974 tmp = cat_op (tmp, args(j), ra_idx); |
1976 | 1975 |
1977 dim_vector dv_tmp = args(j).dims (); | 1976 dim_vector dv_tmp = args(j).dims (); |
1978 | 1977 |
1979 if (dim >= dv_len) | 1978 if (dim >= dv_len) |
1980 { | 1979 { |
2645 retval = args(0).numel (); | 2644 retval = args(0).numel (); |
2646 else if (nargin > 1) | 2645 else if (nargin > 1) |
2647 { | 2646 { |
2648 // Don't use numel (const octave_value_list&) here as that corresponds to | 2647 // Don't use numel (const octave_value_list&) here as that corresponds to |
2649 // an overloaded call, not to builtin! | 2648 // an overloaded call, not to builtin! |
2650 retval = octave::dims_to_numel (args(0).dims (), | 2649 retval = dims_to_numel (args(0).dims (), args.slice (1, nargin-1)); |
2651 args.slice (1, nargin-1)); | |
2652 } | 2650 } |
2653 | 2651 |
2654 return retval; | 2652 return retval; |
2655 } | 2653 } |
2656 | 2654 |
3986 { | 3984 { |
3987 case 0: | 3985 case 0: |
3988 break; | 3986 break; |
3989 | 3987 |
3990 case 1: | 3988 case 1: |
3991 octave::get_dimensions (args(0), fcn, dims); | 3989 get_dimensions (args(0), fcn, dims); |
3992 break; | 3990 break; |
3993 | 3991 |
3994 default: | 3992 default: |
3995 { | 3993 { |
3996 dims.resize (nargin); | 3994 dims.resize (nargin); |
4001 break; | 3999 break; |
4002 } | 4000 } |
4003 | 4001 |
4004 dims.chop_trailing_singletons (); | 4002 dims.chop_trailing_singletons (); |
4005 | 4003 |
4006 octave::check_dimensions (dims, fcn); | 4004 check_dimensions (dims, fcn); |
4007 | 4005 |
4008 // FIXME: Perhaps this should be made extensible by using the class name | 4006 // FIXME: Perhaps this should be made extensible by using the class name |
4009 // to lookup a function to call to create the new value. | 4007 // to lookup a function to call to create the new value. |
4010 | 4008 |
4011 // Note that automatic narrowing will handle conversion from | 4009 // Note that automatic narrowing will handle conversion from |
4086 { | 4084 { |
4087 // FIXME: If this optimization provides a significant | 4085 // FIXME: If this optimization provides a significant |
4088 // benefit, then maybe there should be a special storage | 4086 // benefit, then maybe there should be a special storage |
4089 // type for constant value arrays. | 4087 // type for constant value arrays. |
4090 double dval = static_cast<double> (val); | 4088 double dval = static_cast<double> (val); |
4091 retval = octave::range<double>::make_constant (dval, dims(1)); | 4089 retval = range<double>::make_constant (dval, dims(1)); |
4092 } | 4090 } |
4093 else | 4091 else |
4094 retval = NDArray (dims, val); | 4092 retval = NDArray (dims, val); |
4095 break; | 4093 break; |
4096 | 4094 |
4146 { | 4144 { |
4147 case 0: | 4145 case 0: |
4148 break; | 4146 break; |
4149 | 4147 |
4150 case 1: | 4148 case 1: |
4151 octave::get_dimensions (args(0), fcn, dims); | 4149 get_dimensions (args(0), fcn, dims); |
4152 break; | 4150 break; |
4153 | 4151 |
4154 default: | 4152 default: |
4155 { | 4153 { |
4156 dims.resize (nargin); | 4154 dims.resize (nargin); |
4161 break; | 4159 break; |
4162 } | 4160 } |
4163 | 4161 |
4164 dims.chop_trailing_singletons (); | 4162 dims.chop_trailing_singletons (); |
4165 | 4163 |
4166 octave::check_dimensions (dims, fcn); | 4164 check_dimensions (dims, fcn); |
4167 | 4165 |
4168 // Note that automatic narrowing will handle conversion from | 4166 // Note that automatic narrowing will handle conversion from |
4169 // NDArray to scalar. | 4167 // NDArray to scalar. |
4170 | 4168 |
4171 if (issparse) | 4169 if (issparse) |
4191 break; | 4189 break; |
4192 | 4190 |
4193 case oct_data_conv::dt_double: | 4191 case oct_data_conv::dt_double: |
4194 if (iscomplex) | 4192 if (iscomplex) |
4195 retval = ComplexNDArray (dims, Complex (val, 0)); | 4193 retval = ComplexNDArray (dims, Complex (val, 0)); |
4196 else if (dims.ndims () == 2 && dims(0) == 1 | 4194 else if (dims.ndims () == 2 && dims(0) == 1 && math::isfinite (val)) |
4197 && octave::math::isfinite (val)) | |
4198 // FIXME: If this optimization provides a significant benefit, | 4195 // FIXME: If this optimization provides a significant benefit, |
4199 // then maybe there should be a special storage type for | 4196 // then maybe there should be a special storage type for |
4200 // constant value arrays. | 4197 // constant value arrays. |
4201 retval = octave::range<double>::make_constant (val, dims(1)); | 4198 retval = range<double>::make_constant (val, dims(1)); |
4202 else | 4199 else |
4203 retval = NDArray (dims, val); | 4200 retval = NDArray (dims, val); |
4204 break; | 4201 break; |
4205 | 4202 |
4206 default: | 4203 default: |
4234 { | 4231 { |
4235 case 0: | 4232 case 0: |
4236 break; | 4233 break; |
4237 | 4234 |
4238 case 1: | 4235 case 1: |
4239 octave::get_dimensions (args(0), fcn, dims); | 4236 get_dimensions (args(0), fcn, dims); |
4240 break; | 4237 break; |
4241 | 4238 |
4242 default: | 4239 default: |
4243 { | 4240 { |
4244 dims.resize (nargin); | 4241 dims.resize (nargin); |
4249 break; | 4246 break; |
4250 } | 4247 } |
4251 | 4248 |
4252 dims.chop_trailing_singletons (); | 4249 dims.chop_trailing_singletons (); |
4253 | 4250 |
4254 octave::check_dimensions (dims, fcn); | 4251 check_dimensions (dims, fcn); |
4255 | 4252 |
4256 // Note that automatic narrowing will handle conversion from | 4253 // Note that automatic narrowing will handle conversion from |
4257 // NDArray to scalar. | 4254 // NDArray to scalar. |
4258 | 4255 |
4259 switch (dt) | 4256 switch (dt) |
4261 case oct_data_conv::dt_single: | 4258 case oct_data_conv::dt_single: |
4262 retval = FloatNDArray (dims, static_cast<float> (val)); | 4259 retval = FloatNDArray (dims, static_cast<float> (val)); |
4263 break; | 4260 break; |
4264 | 4261 |
4265 case oct_data_conv::dt_double: | 4262 case oct_data_conv::dt_double: |
4266 if (dims.ndims () == 2 && dims(0) == 1 && octave::math::isfinite (val)) | 4263 if (dims.ndims () == 2 && dims(0) == 1 && math::isfinite (val)) |
4267 // FIXME: If this optimization provides a significant benefit, | 4264 // FIXME: If this optimization provides a significant benefit, |
4268 // then maybe there should be a special storage type for | 4265 // then maybe there should be a special storage type for |
4269 // constant value arrays. | 4266 // constant value arrays. |
4270 retval = octave::range<double>::make_constant (val, dims(1)); | 4267 retval = range<double>::make_constant (val, dims(1)); |
4271 else | 4268 else |
4272 retval = NDArray (dims, val); | 4269 retval = NDArray (dims, val); |
4273 break; | 4270 break; |
4274 | 4271 |
4275 default: | 4272 default: |
4304 { | 4301 { |
4305 case 0: | 4302 case 0: |
4306 break; | 4303 break; |
4307 | 4304 |
4308 case 1: | 4305 case 1: |
4309 octave::get_dimensions (args(0), fcn, dims); | 4306 get_dimensions (args(0), fcn, dims); |
4310 break; | 4307 break; |
4311 | 4308 |
4312 default: | 4309 default: |
4313 { | 4310 { |
4314 dims.resize (nargin); | 4311 dims.resize (nargin); |
4319 break; | 4316 break; |
4320 } | 4317 } |
4321 | 4318 |
4322 dims.chop_trailing_singletons (); | 4319 dims.chop_trailing_singletons (); |
4323 | 4320 |
4324 octave::check_dimensions (dims, fcn); | 4321 check_dimensions (dims, fcn); |
4325 | 4322 |
4326 // Note that automatic narrowing will handle conversion from | 4323 // Note that automatic narrowing will handle conversion from |
4327 // NDArray to scalar. | 4324 // NDArray to scalar. |
4328 | 4325 |
4329 switch (dt) | 4326 switch (dt) |
4382 { | 4379 { |
4383 case 0: | 4380 case 0: |
4384 break; | 4381 break; |
4385 | 4382 |
4386 case 1: | 4383 case 1: |
4387 octave::get_dimensions (args(0), fcn, dims); | 4384 get_dimensions (args(0), fcn, dims); |
4388 break; | 4385 break; |
4389 | 4386 |
4390 default: | 4387 default: |
4391 { | 4388 { |
4392 dims.resize (nargin); | 4389 dims.resize (nargin); |
4397 break; | 4394 break; |
4398 } | 4395 } |
4399 | 4396 |
4400 dims.chop_trailing_singletons (); | 4397 dims.chop_trailing_singletons (); |
4401 | 4398 |
4402 octave::check_dimensions (dims, fcn); | 4399 check_dimensions (dims, fcn); |
4403 | 4400 |
4404 // Note that automatic narrowing will handle conversion from | 4401 // Note that automatic narrowing will handle conversion from |
4405 // NDArray to scalar. | 4402 // NDArray to scalar. |
4406 | 4403 |
4407 if (issparse) | 4404 if (issparse) |
4767 T epsval = x.abs (); | 4764 T epsval = x.abs (); |
4768 typedef typename T::value_type P; | 4765 typedef typename T::value_type P; |
4769 for (octave_idx_type i = 0; i < x.numel (); i++) | 4766 for (octave_idx_type i = 0; i < x.numel (); i++) |
4770 { | 4767 { |
4771 P val = epsval.xelem (i); | 4768 P val = epsval.xelem (i); |
4772 if (octave::math::isnan (val) || octave::math::isinf (val)) | 4769 if (math::isnan (val) || math::isinf (val)) |
4773 epsval(i) = octave::numeric_limits<P>::NaN (); | 4770 epsval(i) = numeric_limits<P>::NaN (); |
4774 else if (val < std::numeric_limits<P>::min ()) | 4771 else if (val < std::numeric_limits<P>::min ()) |
4775 epsval(i) = std::numeric_limits<P>::denorm_min (); | 4772 epsval(i) = std::numeric_limits<P>::denorm_min (); |
4776 else | 4773 else |
4777 { | 4774 { |
4778 int exponent; | 4775 int exponent; |
4779 octave::math::frexp (val, &exponent); | 4776 math::frexp (val, &exponent); |
4780 const P digits = std::numeric_limits<P>::digits; | 4777 const P digits = std::numeric_limits<P>::digits; |
4781 epsval(i) = std::pow (static_cast<P> (2.0), | 4778 epsval(i) = std::pow (static_cast<P> (2.0), |
4782 static_cast<P> (exponent - digits)); | 4779 static_cast<P> (exponent - digits)); |
4783 } | 4780 } |
4784 } | 4781 } |
5328 if (nargin == 0) | 5325 if (nargin == 0) |
5329 retval = identity_matrix (1, 1, dt); | 5326 retval = identity_matrix (1, 1, dt); |
5330 else if (nargin == 1) | 5327 else if (nargin == 1) |
5331 { | 5328 { |
5332 octave_idx_type nr, nc; | 5329 octave_idx_type nr, nc; |
5333 octave::get_dimensions (args(0), "eye", nr, nc); | 5330 get_dimensions (args(0), "eye", nr, nc); |
5334 | 5331 |
5335 retval = identity_matrix (nr, nc, dt); | 5332 retval = identity_matrix (nr, nc, dt); |
5336 } | 5333 } |
5337 else | 5334 else |
5338 { | 5335 { |
5339 octave_idx_type nr, nc; | 5336 octave_idx_type nr, nc; |
5340 octave::get_dimensions (args(0), args(1), "eye", nr, nc); | 5337 get_dimensions (args(0), args(1), "eye", nr, nc); |
5341 | 5338 |
5342 retval = identity_matrix (nr, nc, dt); | 5339 retval = identity_matrix (nr, nc, dt); |
5343 } | 5340 } |
5344 | 5341 |
5345 return retval; | 5342 return retval; |
6011 error ("norm: invalid combination of options"); | 6008 error ("norm: invalid combination of options"); |
6012 | 6009 |
6013 if (str == "fro") | 6010 if (str == "fro") |
6014 p_arg = octave_value (2); | 6011 p_arg = octave_value (2); |
6015 else if (str == "inf") | 6012 else if (str == "inf") |
6016 p_arg = octave::numeric_limits<double>::Inf (); | 6013 p_arg = numeric_limits<double>::Inf (); |
6017 else if (str == "-inf") | 6014 else if (str == "-inf") |
6018 p_arg = -octave::numeric_limits<double>::Inf (); | 6015 p_arg = -numeric_limits<double>::Inf (); |
6019 else | 6016 else |
6020 error ("norm: unrecognized option: %s", str.c_str ()); | 6017 error ("norm: unrecognized option: %s", str.c_str ()); |
6021 } | 6018 } |
6022 else if (! p_arg.is_scalar_type ()) | 6019 else if (! p_arg.is_scalar_type ()) |
6023 err_wrong_type_arg ("norm", p_arg); | 6020 err_wrong_type_arg ("norm", p_arg); |
6041 case sffrob: | 6038 case sffrob: |
6042 retval = xfrobnorm (x_arg); | 6039 retval = xfrobnorm (x_arg); |
6043 break; | 6040 break; |
6044 | 6041 |
6045 case sfinf: | 6042 case sfinf: |
6046 retval = xnorm (x_arg, octave::numeric_limits<double>::Inf ()); | 6043 retval = xnorm (x_arg, numeric_limits<double>::Inf ()); |
6047 break; | 6044 break; |
6048 | 6045 |
6049 case sfneginf: | 6046 case sfneginf: |
6050 retval = xnorm (x_arg, -octave::numeric_limits<double>::Inf ()); | 6047 retval = xnorm (x_arg, -numeric_limits<double>::Inf ()); |
6051 break; | 6048 break; |
6052 } | 6049 } |
6053 | 6050 |
6054 return retval; | 6051 return retval; |
6055 } | 6052 } |
6148 const octave_value_list& args) | 6145 const octave_value_list& args) |
6149 { | 6146 { |
6150 if (args.length () != 1) | 6147 if (args.length () != 1) |
6151 print_usage (); | 6148 print_usage (); |
6152 | 6149 |
6153 return octave::unary_op (op, args(0)); | 6150 return unary_op (op, args(0)); |
6154 } | 6151 } |
6155 | 6152 |
6156 DEFUN (not, args, , | 6153 DEFUN (not, args, , |
6157 doc: /* -*- texinfo -*- | 6154 doc: /* -*- texinfo -*- |
6158 @deftypefn {} {@var{z} =} not (@var{x}) | 6155 @deftypefn {} {@var{z} =} not (@var{x}) |
6254 const octave_value_list& args) | 6251 const octave_value_list& args) |
6255 { | 6252 { |
6256 if (args.length () != 2) | 6253 if (args.length () != 2) |
6257 print_usage (); | 6254 print_usage (); |
6258 | 6255 |
6259 return octave::binary_op (op, args(0), args(1)); | 6256 return binary_op (op, args(0), args(1)); |
6260 } | 6257 } |
6261 | 6258 |
6262 static octave_value | 6259 static octave_value |
6263 binary_assoc_op_defun_body (octave_value::binary_op op, | 6260 binary_assoc_op_defun_body (octave_value::binary_op op, |
6264 octave_value::assign_op aop, | 6261 octave_value::assign_op aop, |
6270 print_usage (); | 6267 print_usage (); |
6271 | 6268 |
6272 octave_value retval; | 6269 octave_value retval; |
6273 | 6270 |
6274 if (nargin == 2) | 6271 if (nargin == 2) |
6275 retval = octave::binary_op (op, args(0), args(1)); | 6272 retval = binary_op (op, args(0), args(1)); |
6276 else | 6273 else |
6277 { | 6274 { |
6278 retval = octave::binary_op (op, args(0), args(1)); | 6275 retval = binary_op (op, args(0), args(1)); |
6279 | 6276 |
6280 for (int i = 2; i < nargin; i++) | 6277 for (int i = 2; i < nargin; i++) |
6281 retval.assign (aop, args(i)); | 6278 retval.assign (aop, args(i)); |
6282 } | 6279 } |
6283 | 6280 |
6575 | 6572 |
6576 if (nargin < 2 || nargin > 3) | 6573 if (nargin < 2 || nargin > 3) |
6577 print_usage (); | 6574 print_usage (); |
6578 | 6575 |
6579 return (nargin == 2 | 6576 return (nargin == 2 |
6580 ? octave::colon_op (args(0), args(1)) | 6577 ? colon_op (args(0), args(1)) |
6581 : octave::colon_op (args(0), args(1), args(2))); | 6578 : colon_op (args(0), args(1), args(2))); |
6582 } | 6579 } |
6583 | 6580 |
6584 static double tic_toc_timestamp = -1.0; | 6581 static double tic_toc_timestamp = -1.0; |
6585 | 6582 |
6586 DEFUN (tic, args, nargout, | 6583 DEFUN (tic, args, nargout, |
6637 { | 6634 { |
6638 if (args.length () != 0) | 6635 if (args.length () != 0) |
6639 warning ("tic: ignoring extra arguments"); | 6636 warning ("tic: ignoring extra arguments"); |
6640 | 6637 |
6641 octave_value retval; | 6638 octave_value retval; |
6642 octave::sys::time now; | 6639 sys::time now; |
6643 double tmp = now.double_value (); | 6640 double tmp = now.double_value (); |
6644 | 6641 |
6645 if (nargout > 0) | 6642 if (nargout > 0) |
6646 { | 6643 { |
6647 double ip = 0.0; | 6644 double ip = 0.0; |
6697 } | 6694 } |
6698 | 6695 |
6699 if (start_time < 0) | 6696 if (start_time < 0) |
6700 error ("toc: function called before timer initialization with tic()"); | 6697 error ("toc: function called before timer initialization with tic()"); |
6701 | 6698 |
6702 octave::sys::time now; | 6699 sys::time now; |
6703 | 6700 |
6704 double etime = now.double_value () - start_time; | 6701 double etime = now.double_value () - start_time; |
6705 | 6702 |
6706 octave_value retval; | 6703 octave_value retval; |
6707 if (nargout > 0) | 6704 if (nargout > 0) |
6739 @end deftypefn */) | 6736 @end deftypefn */) |
6740 { | 6737 { |
6741 if (args.length () != 0) | 6738 if (args.length () != 0) |
6742 print_usage (); | 6739 print_usage (); |
6743 | 6740 |
6744 octave::sys::cpu_time cpu_tm; | 6741 sys::cpu_time cpu_tm; |
6745 | 6742 |
6746 double usr = cpu_tm.user (); | 6743 double usr = cpu_tm.user (); |
6747 double sys = cpu_tm.system (); | 6744 double sys = cpu_tm.system (); |
6748 | 6745 |
6749 return ovl (usr + sys, usr, sys); | 6746 return ovl (usr + sys, usr, sys); |
6879 Array<octave_idx_type> sidx; | 6876 Array<octave_idx_type> sidx; |
6880 | 6877 |
6881 // NOTE: Can not change this to ovl() call because arg.sort changes sidx | 6878 // NOTE: Can not change this to ovl() call because arg.sort changes sidx |
6882 // and objects are declared const in ovl prototype. | 6879 // and objects are declared const in ovl prototype. |
6883 retval(0) = arg.sort (sidx, dim, smode); | 6880 retval(0) = arg.sort (sidx, dim, smode); |
6884 retval(1) = octave::idx_vector (sidx, dv(dim)); // No checking, extent is known. | 6881 retval(1) = idx_vector (sidx, dv(dim)); // No checking, extent is known. |
6885 } | 6882 } |
6886 else | 6883 else |
6887 retval = ovl (arg.sort (dim, smode)); | 6884 retval = ovl (arg.sort (dim, smode)); |
6888 | 6885 |
6889 return retval; | 6886 return retval; |
7305 | 7302 |
7306 octave_value retval; | 7303 octave_value retval; |
7307 | 7304 |
7308 try | 7305 try |
7309 { | 7306 { |
7310 octave::idx_vector n = args(1).index_vector (); | 7307 idx_vector n = args(1).index_vector (); |
7311 | 7308 |
7312 switch (argx.builtin_type ()) | 7309 switch (argx.builtin_type ()) |
7313 { | 7310 { |
7314 case btyp_double: | 7311 case btyp_double: |
7315 retval = argx.array_value ().nth_element (n, dim); | 7312 retval = argx.array_value ().nth_element (n, dim); |
7346 retval = argx.cellstr_value ().nth_element (n, dim); | 7343 retval = argx.cellstr_value ().nth_element (n, dim); |
7347 else | 7344 else |
7348 err_wrong_type_arg ("nth_element", argx); | 7345 err_wrong_type_arg ("nth_element", argx); |
7349 } | 7346 } |
7350 } | 7347 } |
7351 catch (const octave::index_exception& ie) | 7348 catch (const index_exception& ie) |
7352 { | 7349 { |
7353 error ("nth_element: invalid index %s", ie.what ()); | 7350 error ("nth_element: invalid index %s", ie.what ()); |
7354 } | 7351 } |
7355 | 7352 |
7356 return retval; | 7353 return retval; |
7371 %!error nth_element ("abcd", 3) | 7368 %!error nth_element ("abcd", 3) |
7372 */ | 7369 */ |
7373 | 7370 |
7374 template <typename NDT> | 7371 template <typename NDT> |
7375 static NDT | 7372 static NDT |
7376 do_accumarray_sum (const octave::idx_vector& idx, const NDT& vals, | 7373 do_accumarray_sum (const idx_vector& idx, const NDT& vals, |
7377 octave_idx_type n = -1) | 7374 octave_idx_type n = -1) |
7378 { | 7375 { |
7379 typedef typename NDT::element_type T; | 7376 typedef typename NDT::element_type T; |
7380 if (n < 0) | 7377 if (n < 0) |
7381 n = idx.extent (0); | 7378 n = idx.extent (0); |
7410 | 7407 |
7411 octave_value retval; | 7408 octave_value retval; |
7412 | 7409 |
7413 try | 7410 try |
7414 { | 7411 { |
7415 octave::idx_vector idx = args(0).index_vector (); | 7412 idx_vector idx = args(0).index_vector (); |
7416 octave_idx_type n = -1; | 7413 octave_idx_type n = -1; |
7417 if (nargin == 3) | 7414 if (nargin == 3) |
7418 n = args(2).idx_type_value (true); | 7415 n = args(2).idx_type_value (true); |
7419 | 7416 |
7420 octave_value vals = args(1); | 7417 octave_value vals = args(1); |
7421 | 7418 |
7422 if (vals.is_range ()) | 7419 if (vals.is_range ()) |
7423 { | 7420 { |
7424 octave::range<double> r = vals.range_value (); | 7421 range<double> r = vals.range_value (); |
7425 if (r.increment () == 0) | 7422 if (r.increment () == 0) |
7426 vals = r.base (); | 7423 vals = r.base (); |
7427 } | 7424 } |
7428 | 7425 |
7429 if (vals.is_single_type ()) | 7426 if (vals.is_single_type ()) |
7445 retval = do_accumarray_sum (idx, vals.array_value (), n); | 7442 retval = do_accumarray_sum (idx, vals.array_value (), n); |
7446 } | 7443 } |
7447 else | 7444 else |
7448 err_wrong_type_arg ("accumarray", vals); | 7445 err_wrong_type_arg ("accumarray", vals); |
7449 } | 7446 } |
7450 catch (const octave::index_exception& ie) | 7447 catch (const index_exception& ie) |
7451 { | 7448 { |
7452 error ("__accumarray_sum__: invalid index %s", ie.what ()); | 7449 error ("__accumarray_sum__: invalid index %s", ie.what ()); |
7453 } | 7450 } |
7454 | 7451 |
7455 return retval; | 7452 return retval; |
7456 } | 7453 } |
7457 | 7454 |
7458 template <typename NDT> | 7455 template <typename NDT> |
7459 static NDT | 7456 static NDT |
7460 do_accumarray_minmax (const octave::idx_vector& idx, const NDT& vals, | 7457 do_accumarray_minmax (const idx_vector& idx, const NDT& vals, |
7461 octave_idx_type n, bool ismin, | 7458 octave_idx_type n, bool ismin, |
7462 const typename NDT::element_type& zero_val) | 7459 const typename NDT::element_type& zero_val) |
7463 { | 7460 { |
7464 typedef typename NDT::element_type T; | 7461 typedef typename NDT::element_type T; |
7465 if (n < 0) | 7462 if (n < 0) |
7468 error ("accumarray: index out of range"); | 7465 error ("accumarray: index out of range"); |
7469 | 7466 |
7470 NDT retval (dim_vector (n, 1), zero_val); | 7467 NDT retval (dim_vector (n, 1), zero_val); |
7471 | 7468 |
7472 // Pick minimizer or maximizer. | 7469 // Pick minimizer or maximizer. |
7473 void (MArray<T>::*op) (const octave::idx_vector&, const MArray<T>&) | 7470 void (MArray<T>::*op) (const idx_vector&, const MArray<T>&) |
7474 = ismin ? (&MArray<T>::idx_min) : (&MArray<T>::idx_max); | 7471 = ismin ? (&MArray<T>::idx_min) : (&MArray<T>::idx_max); |
7475 | 7472 |
7476 octave_idx_type l = idx.length (n); | 7473 octave_idx_type l = idx.length (n); |
7477 if (vals.numel () == 1) | 7474 if (vals.numel () == 1) |
7478 (retval.*op) (idx, NDT (dim_vector (l, 1), vals(0))); | 7475 (retval.*op) (idx, NDT (dim_vector (l, 1), vals(0))); |
7498 | 7495 |
7499 octave_value retval; | 7496 octave_value retval; |
7500 | 7497 |
7501 try | 7498 try |
7502 { | 7499 { |
7503 octave::idx_vector idx = args(0).index_vector (); | 7500 idx_vector idx = args(0).index_vector (); |
7504 octave_idx_type n = -1; | 7501 octave_idx_type n = -1; |
7505 if (nargin == 4) | 7502 if (nargin == 4) |
7506 n = args(3).idx_type_value (true); | 7503 n = args(3).idx_type_value (true); |
7507 | 7504 |
7508 octave_value vals = args(1); | 7505 octave_value vals = args(1); |
7556 | 7553 |
7557 default: | 7554 default: |
7558 err_wrong_type_arg ("accumarray", vals); | 7555 err_wrong_type_arg ("accumarray", vals); |
7559 } | 7556 } |
7560 } | 7557 } |
7561 catch (const octave::index_exception& ie) | 7558 catch (const index_exception& ie) |
7562 { | 7559 { |
7563 error ("do_accumarray_minmax_fun: invalid index %s", ie.what ()); | 7560 error ("do_accumarray_minmax_fun: invalid index %s", ie.what ()); |
7564 } | 7561 } |
7565 | 7562 |
7566 return retval; | 7563 return retval; |
7584 return do_accumarray_minmax_fun (args, false); | 7581 return do_accumarray_minmax_fun (args, false); |
7585 } | 7582 } |
7586 | 7583 |
7587 template <typename NDT> | 7584 template <typename NDT> |
7588 static NDT | 7585 static NDT |
7589 do_accumdim_sum (const octave::idx_vector& idx, const NDT& vals, | 7586 do_accumdim_sum (const idx_vector& idx, const NDT& vals, |
7590 int dim = -1, octave_idx_type n = -1) | 7587 int dim = -1, octave_idx_type n = -1) |
7591 { | 7588 { |
7592 typedef typename NDT::element_type T; | 7589 typedef typename NDT::element_type T; |
7593 if (n < 0) | 7590 if (n < 0) |
7594 n = idx.extent (0); | 7591 n = idx.extent (0); |
7631 | 7628 |
7632 octave_value retval; | 7629 octave_value retval; |
7633 | 7630 |
7634 try | 7631 try |
7635 { | 7632 { |
7636 octave::idx_vector idx = args(0).index_vector (); | 7633 idx_vector idx = args(0).index_vector (); |
7637 int dim = -1; | 7634 int dim = -1; |
7638 if (nargin >= 3) | 7635 if (nargin >= 3) |
7639 dim = args(2).int_value () - 1; | 7636 dim = args(2).int_value () - 1; |
7640 | 7637 |
7641 octave_idx_type n = -1; | 7638 octave_idx_type n = -1; |
7663 retval = do_accumdim_sum (idx, vals.array_value (), dim, n); | 7660 retval = do_accumdim_sum (idx, vals.array_value (), dim, n); |
7664 } | 7661 } |
7665 else | 7662 else |
7666 err_wrong_type_arg ("accumdim", vals); | 7663 err_wrong_type_arg ("accumdim", vals); |
7667 } | 7664 } |
7668 catch (const octave::index_exception& ie) | 7665 catch (const index_exception& ie) |
7669 { | 7666 { |
7670 error ("__accumdim_sum__: invalid index %s", ie.what ()); | 7667 error ("__accumdim_sum__: invalid index %s", ie.what ()); |
7671 } | 7668 } |
7672 | 7669 |
7673 return retval; | 7670 return retval; |
7853 if (dim == 1) | 7850 if (dim == 1) |
7854 { | 7851 { |
7855 octave_idx_type k = retval.columns (); | 7852 octave_idx_type k = retval.columns (); |
7856 while (order > 0 && k > 0) | 7853 while (order > 0 && k > 0) |
7857 { | 7854 { |
7858 octave::idx_vector col1 (':'), col2 (':'), sl1 (1, k), sl2 (0, k-1); | 7855 idx_vector col1 (':'), col2 (':'), sl1 (1, k), sl2 (0, k-1); |
7859 retval = SparseT (retval.index (col1, sl1)) | 7856 retval = SparseT (retval.index (col1, sl1)) |
7860 - SparseT (retval.index (col2, sl2)); | 7857 - SparseT (retval.index (col2, sl2)); |
7861 assert (retval.columns () == k-1); | 7858 assert (retval.columns () == k-1); |
7862 order--; | 7859 order--; |
7863 k--; | 7860 k--; |
7866 else | 7863 else |
7867 { | 7864 { |
7868 octave_idx_type k = retval.rows (); | 7865 octave_idx_type k = retval.rows (); |
7869 while (order > 0 && k > 0) | 7866 while (order > 0 && k > 0) |
7870 { | 7867 { |
7871 octave::idx_vector col1 (':'), col2 (':'), sl1 (1, k), sl2 (0, k-1); | 7868 idx_vector col1 (':'), col2 (':'), sl1 (1, k), sl2 (0, k-1); |
7872 retval = SparseT (retval.index (sl1, col1)) | 7869 retval = SparseT (retval.index (sl1, col1)) |
7873 - SparseT (retval.index (sl2, col2)); | 7870 - SparseT (retval.index (sl2, col2)); |
7874 assert (retval.rows () == k-1); | 7871 assert (retval.rows () == k-1); |
7875 order--; | 7872 order--; |
7876 k--; | 7873 k--; |
8181 | 8178 |
8182 octave_value_list retval; | 8179 octave_value_list retval; |
8183 | 8180 |
8184 if (args(0).isinteger ()) | 8181 if (args(0).isinteger ()) |
8185 { | 8182 { |
8186 #define MAKE_INT_BRANCH(X) \ | 8183 #define MAKE_INT_BRANCH(X) \ |
8187 if (args(0).is_ ## X ## _type ()) \ | 8184 if (args(0).is_ ## X ## _type ()) \ |
8188 { \ | 8185 { \ |
8189 const X##NDArray in = args(0). X## _array_value (); \ | 8186 const X##NDArray in = args(0). X## _array_value (); \ |
8190 std::size_t inlen = in.numel () * sizeof (X## _t) / sizeof (char); \ | 8187 std::size_t inlen = in.numel () * sizeof (X## _t) / sizeof (char); \ |
8191 const char *inc = reinterpret_cast<const char *> (in.data ()); \ | 8188 const char *inc = reinterpret_cast<const char *> (in.data ()); \ |
8192 char *out; \ | 8189 char *out; \ |
8193 if (octave::base64_encode (inc, inlen, &out)) \ | 8190 if (base64_encode (inc, inlen, &out)) \ |
8194 { \ | 8191 { \ |
8195 retval(0) = octave_value (out); \ | 8192 retval(0) = octave_value (out); \ |
8196 ::free (out); \ | 8193 ::free (out); \ |
8197 } \ | 8194 } \ |
8198 } | 8195 } |
8199 | 8196 |
8200 MAKE_INT_BRANCH(int8) | 8197 MAKE_INT_BRANCH(int8) |
8201 else MAKE_INT_BRANCH(int16) | 8198 else MAKE_INT_BRANCH(int16) |
8202 else MAKE_INT_BRANCH(int32) | 8199 else MAKE_INT_BRANCH(int32) |
8217 std::size_t inlen; | 8214 std::size_t inlen; |
8218 inlen = in.numel () * sizeof (float) / sizeof (char); | 8215 inlen = in.numel () * sizeof (float) / sizeof (char); |
8219 const char* inc; | 8216 const char* inc; |
8220 inc = reinterpret_cast<const char *> (in.data ()); | 8217 inc = reinterpret_cast<const char *> (in.data ()); |
8221 char *out; | 8218 char *out; |
8222 if (octave::base64_encode (inc, inlen, &out)) | 8219 if (base64_encode (inc, inlen, &out)) |
8223 { | 8220 { |
8224 retval(0) = octave_value (out); | 8221 retval(0) = octave_value (out); |
8225 ::free (out); | 8222 ::free (out); |
8226 } | 8223 } |
8227 } | 8224 } |
8231 std::size_t inlen; | 8228 std::size_t inlen; |
8232 inlen = in.numel () * sizeof (double) / sizeof (char); | 8229 inlen = in.numel () * sizeof (double) / sizeof (char); |
8233 const char* inc; | 8230 const char* inc; |
8234 inc = reinterpret_cast<const char *> (in.data ()); | 8231 inc = reinterpret_cast<const char *> (in.data ()); |
8235 char *out; | 8232 char *out; |
8236 if (octave::base64_encode (inc, inlen, &out)) | 8233 if (base64_encode (inc, inlen, &out)) |
8237 { | 8234 { |
8238 retval(0) = octave_value (out); | 8235 retval(0) = octave_value (out); |
8239 ::free (out); | 8236 ::free (out); |
8240 } | 8237 } |
8241 } | 8238 } |
8283 if (nargin < 1 || nargin > 2) | 8280 if (nargin < 1 || nargin > 2) |
8284 print_usage (); | 8281 print_usage (); |
8285 | 8282 |
8286 std::string str = args(0).string_value (); | 8283 std::string str = args(0).string_value (); |
8287 | 8284 |
8288 Array<double> retval = octave::base64_decode (str); | 8285 Array<double> retval = base64_decode (str); |
8289 | 8286 |
8290 if (nargin == 2) | 8287 if (nargin == 2) |
8291 { | 8288 { |
8292 dim_vector dims; | 8289 dim_vector dims; |
8293 | 8290 |
8339 if (nargin < 1 || nargin > 2) | 8336 if (nargin < 1 || nargin > 2) |
8340 print_usage (); | 8337 print_usage (); |
8341 | 8338 |
8342 std::string str = args(0).string_value (); | 8339 std::string str = args(0).string_value (); |
8343 | 8340 |
8344 intNDArray<octave_uint8> retval = octave::base64_decode_bytes (str); | 8341 intNDArray<octave_uint8> retval = base64_decode_bytes (str); |
8345 | 8342 |
8346 if (nargin == 2) | 8343 if (nargin == 2) |
8347 { | 8344 { |
8348 dim_vector dims; | 8345 dim_vector dims; |
8349 | 8346 |