public int offset(Section intersect) throws InvalidRangeException { if (!compatibleRank(intersect)) throw new InvalidRangeException("Invalid Section rank"); int result = 0; int stride = 1; for (int j = list.size() - 1; j >= 0; j--) { Range base = list.get(j); Range r = intersect.getRange(j); int offset = base.index(r.first()); result += offset * stride; stride *= base.length(); } return result; }
public int offset(Section intersect) throws InvalidRangeException { if (intersect.getRank() != getRank()) throw new InvalidRangeException("Invalid Section rank"); int result = 0; int stride = 1; for (int j = list.size() - 1; j >= 0; j--) { Range base = list.get(j); Range r = intersect.getRange(j); int offset = base.index(r.first()); result += offset * stride; stride *= base.length(); } return result; }
/** * Compute the element offset of an intersecting subrange of this. * @param intersect the subrange * @return element offset * @throws InvalidRangeException */ public int offset(Section intersect) throws InvalidRangeException { if (!compatibleRank(intersect)) throw new InvalidRangeException("Incompatible Section rank"); int result = 0; int stride = 1; for (int j = list.size() - 1; j >= 0; j--) { Range base = list.get(j); Range r = intersect.getRange(j); int offset = base.index(r.first()); result += offset * stride; stride *= base.length(); } return result; }