Row-major flat index `((c0 - lo0) * extent1 * extent2 ...) + ...`.
(
schema: &ArraySchema,
coord: &[crate::types::coord::value::CoordValue],
)
| 78 | |
| 79 | /// Row-major flat index `((c0 - lo0) * extent1 * extent2 ...) + ...`. |
| 80 | fn flat_index_for_coord( |
| 81 | schema: &ArraySchema, |
| 82 | coord: &[crate::types::coord::value::CoordValue], |
| 83 | ) -> ArrayResult<usize> { |
| 84 | use crate::schema::dim_spec::DimType; |
| 85 | use crate::types::coord::value::CoordValue; |
| 86 | use crate::types::domain::DomainBound; |
| 87 | let mut flat: usize = 0; |
| 88 | for (i, dim) in schema.dims.iter().enumerate() { |
| 89 | let extent = schema.tile_extents[i] as usize; |
| 90 | let lo = match (&dim.dtype, &dim.domain.lo) { |
| 91 | (DimType::Int64, DomainBound::Int64(v)) |
| 92 | | (DimType::TimestampMs, DomainBound::TimestampMs(v)) => *v, |
| 93 | _ => 0, |
| 94 | }; |
| 95 | let off = match coord.get(i) { |
| 96 | Some(CoordValue::Int64(v)) | Some(CoordValue::TimestampMs(v)) => { |
| 97 | ((*v - lo) as usize) % extent |
| 98 | } |
| 99 | _ => { |
| 100 | return Err(ArrayError::CoordOutOfDomain { |
| 101 | array: schema.name.clone(), |
| 102 | dim: dim.name.clone(), |
| 103 | detail: "non-integer coord in dense promotion".to_string(), |
| 104 | }); |
| 105 | } |
| 106 | }; |
| 107 | flat = flat * extent + off; |
| 108 | } |
| 109 | Ok(flat) |
| 110 | } |
| 111 | |
| 112 | #[cfg(test)] |
| 113 | mod tests { |
no test coverage detected