#ifndef vec_scalar_ATYPE_LTYPE_RTYPE_OPNAME
#define vec_scalar_ATYPE_LTYPE_RTYPE_OPNAME
static IA_DiscreteImage<ATYPE>
vec_scalar_bo_OPNAME(const IA_VectorDI<LTYPE> *lhs,RTYPE rhs)
{
    const IA_IntPointSet domain = lhs->domain();
    const unsigned sz = domain.card();
    ATYPE *const vec = new ATYPE[sz];

    {
	ATYPE *ds = vec;
	const LTYPE *ls = lhs->vec;
	for (unsigned i=0; i<sz; i++) {
	    *(ds++) = ( (*(ls++)) SUBOP (rhs) );
	}
    }
    return IA_DiscreteImage<ATYPE>(domain, vec, sz, 1);
}
#endif // vec_scalar_ATYPE_LTYPE_RTYPE_OPNAME

// scalar-scalar operation is trivial

#ifndef iter_scalar_ATYPE_LTYPE_RTYPE_OPNAME
#define iter_scalar_ATYPE_LTYPE_RTYPE_OPNAME
static IA_DiscreteImage<ATYPE>
iter_scalar_bo_OPNAME(IA_DiscreteImage<LTYPE> lhs,RTYPE rhs)
{
    const IA_IntPointSet domain = lhs.domain();
    const unsigned sz = domain.card();
    ATYPE *const vec = new ATYPE[sz];

    {
	ATYPE *ds = vec;
	LTYPE ltmp;
	IA_DIVIter<LTYPE>	liter(lhs);
	for (unsigned i=0; i<sz; i++) {
	    liter(ltmp);
	    *(ds++) = ( (ltmp) SUBOP (rhs) );
	}
    }
    return IA_DiscreteImage<ATYPE>(domain, vec, sz, 1);
}
#endif // iter_scalar_ATYPE_LTYPE_RTYPE_OPNAME

IA_DiscreteImage<ATYPE>
OP ( const IA_DiscreteImage<LTYPE> &lhs, RTYPE rhs)
{
    if (lhs.type() == IA_VectorDI<LTYPE>::s_type()) {
	return vec_scalar_bo_OPNAME((IA_VectorDI<LTYPE> *)lhs.bdip,rhs);
    } else if (lhs.type() == IA_ConstDI<LTYPE>::s_type()) {
	return IA_DiscreteImage<ATYPE> (lhs.domain(), (((IA_ConstDI<LTYPE> *)lhs.bdip)->value) SUBOP (rhs));
    } else {
	return iter_scalar_bo_OPNAME(lhs,rhs);
    }
}
