jblas-project / jblas

Linear Algebra for Java
http://jblas.org
BSD 3-Clause "New" or "Revised" License
590 stars 149 forks source link

get(Range rs, Range cs) #12

Closed cheshirekow closed 11 years ago

cheshirekow commented 12 years ago

First, thanks for sharing this code. Second, a bug report:

I think this is essentially the same as issue #10. There appears to be a bug in FloatMatrix.get(Range rs, Range cs) (FloatMatrix.class:642) which currently looks like this:

    public FloatMatrix get(Range rs, Range cs) {
        rs.init(0, rows);
        cs.init(0, columns);
        FloatMatrix result = new FloatMatrix(rs.length(), cs.length());

        for (; rs.hasMore(); rs.next()) {
            for (; cs.hasMore(); cs.next()) {
                result.put(rs.index(), cs.index(), get(rs.value(), cs.value()));
            }
        }
        return result;
    }

The problem is that only first row is actually "got". I think this is because cs needs to be reset for each row. For instance:

    public FloatMatrix get(Range rs, Range cs) {
        rs.init(0, rows);
        cs.init(0, columns);
        FloatMatrix result = new FloatMatrix(rs.length(), cs.length());

        for (; rs.hasMore(); rs.next()) {
            for (; cs.hasMore(); cs.next()) {
                cs.init(0,columns) //<--------------- NOTE CHANGE -----
                result.put(rs.index(), cs.index(), get(rs.value(), cs.value()));
            }
        }

        return result;
    }

I didn't bother to check if the same is present in DoubleMatrix

Quantisan commented 11 years ago

this seems to have been resolved

mikiobraun commented 11 years ago

Yes, looks like ;)