[go: up one dir, main page]

LinSpaced not backwards compatible w.r.t. num_steps=0

Submitted by Alec Jacobson

Assigned to Nobody

Link to original bugzilla bug (#1383)
Version: 3.3 (current stable)

Description

I'm not sure if LinSpaced has well documented behavior for size=0, but in version 3.2.9 this

Eigen::VectorXi::LinSpaced(0,0,-1);  

would produce an empty vector. (This comes up rather regularly for dynamic code where you have Eigen::VectorXi::LinSpaced(n,0,n-1);)

In version 3.3.1 and 3.3.90, the code above causes a divide by zero:

Process 48952 stopped

  • thread #1 (closed): tid = 0x25fd2c, 0x0000000100000f64 .mainEigen::internal::linspaced_op_impl<int, long long vector[2], true>::linspaced_op_impl(this=0x00007fff5fbfecc8, low=0x00007fff5fbfed2c, high=0x00007fff5fbfed28, num_steps=0) + 196 at NullaryFunctors.h:96, queue = 'com.apple.main-thread', stop reason = EXC_ARITHMETIC (code=EXC_I386_DIV, subcode=0x0) frame #0: 0x0000000100000f64 .mainEigen::internal::linspaced_op_impl<int, long long vector[2], true>::linspaced_op_impl(this=0x00007fff5fbfecc8, low=0x00007fff5fbfed2c, high=0x00007fff5fbfed28, num_steps=0) + 196 at NullaryFunctors.h:96
    93 linspaced_op_impl(const Scalar& low, const Scalar& high, Index num_steps) :
    94 m_low(low),
    95 m_multiplier((high-low)/convert_index<Scalar>(num_steps<=1 ? 1 : num_steps-1)),
    -> 96 m_divisor(convert_index<Scalar>(num_steps+high-low)/(high-low+1)),
    97 m_use_divisor((high+1)<(low+num_steps))
    98 {}
    99
Edited by Eigen Bugzilla