octave: map unary functions to __...___ Python-style unary members
- Only available in Octave 3.8.0 and higher
This commit is contained in:
parent
000ab753df
commit
125329466d
3 changed files with 42 additions and 0 deletions
|
|
@ -31,4 +31,20 @@
|
|||
return (double) $self->re();
|
||||
}
|
||||
|
||||
double __real__() {
|
||||
return $self->re();
|
||||
}
|
||||
double __imag__() {
|
||||
return $self->im();
|
||||
}
|
||||
double __abs__() {
|
||||
return sqrt($self->re()*$self->re() + $self->im()*$self->im());
|
||||
}
|
||||
ComplexVal __conj__() {
|
||||
return ComplexVal($self->re(), -$self->im());
|
||||
}
|
||||
ComplexVal __exp__() {
|
||||
return exp($self->re()) * ComplexVal(cos($self->im()), sin($self->im()));
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
|||
|
|
@ -28,3 +28,12 @@ printf("2*a = %s\n",disp(2*a));
|
|||
# conversions
|
||||
printf("single(a) = %g\n", single(a));
|
||||
printf("double(a) = %g\n", double(a));
|
||||
|
||||
# unary functions
|
||||
if swig_octave_prereq(3,8,0)
|
||||
printf("real(a) = %g\n", real(a));
|
||||
printf("imag(a) = %g\n", imag(a));
|
||||
printf("abs(a) = %g\n", abs(a));
|
||||
printf("conj(a) = %s\n", disp(conj(a)));
|
||||
printf("exp(a) = %s\n", disp(exp(a)));
|
||||
endif
|
||||
|
|
|
|||
|
|
@ -824,6 +824,18 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own);
|
|||
return ret.scalar_value();
|
||||
}
|
||||
|
||||
#if SWIG_OCTAVE_PREREQ(3,8,0)
|
||||
virtual octave_value map(octave_base_value::unary_mapper_t umap) const {
|
||||
const std::string opname = std::string("__") + octave_base_value::get_umap_name(umap) + std::string("__");
|
||||
octave_value ret;
|
||||
if (!dispatch_unary_op(opname, ret)) {
|
||||
error((opname + std::string(" method not found")).c_str());
|
||||
return octave_value();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if SWIG_OCTAVE_PREREQ(3,3,52)
|
||||
virtual octave_map map_value() const {
|
||||
return octave_map();
|
||||
|
|
@ -1080,6 +1092,11 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own);
|
|||
virtual double scalar_value(bool frc_str_conv = false) const
|
||||
{ return ptr->scalar_value(frc_str_conv); }
|
||||
|
||||
#if SWIG_OCTAVE_PREREQ(3,8,0)
|
||||
virtual octave_value map(octave_base_value::unary_mapper_t umap) const
|
||||
{ return ptr->map(umap); }
|
||||
#endif
|
||||
|
||||
#if SWIG_OCTAVE_PREREQ(3,3,52)
|
||||
virtual octave_map map_value() const
|
||||
{ return ptr->map_value(); }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue