Bug #2122

Python 3 division error

Added by Knödlseder Jürgen almost 7 years ago. Updated over 6 years ago.

Status:ClosedStart date:06/09/2017
Priority:NormalDue date:
Assigned To:Knödlseder Jürgen% Done:

100%

Category:-
Target version:1.5.0
Duration:

Description

The following code in csresmap

logmap  = self._resmap/modelmap

leads to an exception on Python 3.

Probably the GSkyMap Python interface needs the following methods added:

GSkyMap __div__(const GSkyMap& map)
GSkyMap __truediv__(const GSkyMap& map)


Recurrence

No recurrence.

History

#1 Updated by Knödlseder Jürgen over 6 years ago

  • Target version changed from 1.4.0 to 1.5.0

#2 Updated by Knödlseder Jürgen over 6 years ago

Following https://stackoverflow.com/questions/21692065/python-class-div-issue, __truediv__ is Python 3.x while __div__ is Python 2.x. Hence we need both to support Python 2.x and 3.x.

Here is what is implemented in GMatrix.i:

    // Python 2.x
    GMatrix __div__(const double &scalar) {
        return ((*self) / scalar);
    }
    // Python 3.x
    GMatrix __truediv__(const double& scalar) const {
        return ((*self) / scalar);
    }
    // Python 2.x operator/=
    GMatrix __idiv__(const double& scalar) {
        self->operator/=(scalar);
        return (*self);
    }
    // Python 3.x operator/=
    GMatrix __itruediv__(const double& scalar) {
        self->operator/=(scalar);
        return (*self);
    }

For the moment, GSkyMap.i has

    // Python 2.x operator/=
    GSkyMap __idiv__(const GSkyMap& map) {
        self->operator/=(map);
        return (*self);
    }
    // Python 3.x operator/=
    GSkyMap __itruediv__(const GSkyMap& map) {
        self->operator/=(map);
        return (*self);
    }
    // Python 2.x operator/=
    GSkyMap __idiv__(const double& factor) {
        self->operator/=(factor);
        return (*self);
    }
    // Python 3.x operator/=
    GSkyMap __itruediv__(const double& factor) {
        self->operator/=(factor);
        return (*self);
    }

hence we need to add
    // Python 2.x operator/=
    GSkyMap __div__(const GSkyMap& map) {
        return ((*self) / map);
    }
    // Python 3.x operator/=
    GSkyMap __truediv__(const GSkyMap& map) {
        return ((*self) / map);
    }
and remove
GSkyMap       operator/(const GSkyMap& map) const;

#3 Updated by Knödlseder Jürgen over 6 years ago

  • Status changed from New to Closed
  • Assigned To set to Knödlseder Jürgen
  • % Done changed from 0 to 100

Operaters were added and code was merged into devel.

Also available in: Atom PDF