forked from M-Labs/nac3
Compare commits
2 Commits
c74b7992f6
...
188208b959
Author | SHA1 | Date |
---|---|---|
David Nadlinger | 188208b959 | |
David Nadlinger | 164edd266e |
|
@ -1181,21 +1181,38 @@ impl<'a> Inferencer<'a> {
|
||||||
slice.location,
|
slice.location,
|
||||||
),
|
),
|
||||||
TypeEnum::TNDArray { ty: elem_ty, num_dims } => {
|
TypeEnum::TNDArray { ty: elem_ty, num_dims } => {
|
||||||
let num_idxs = if let TypeEnum::TTuple { ty: idx_tys } =
|
let num_idxs = match &*self.unifier.get_ty(slice.custom.unwrap()) {
|
||||||
&*self.unifier.get_ty(slice.custom.unwrap())
|
TypeEnum::TTuple { ty: idx_tys } => {
|
||||||
{
|
for idx_ty in idx_tys.iter() {
|
||||||
for idx_ty in idx_tys.iter() {
|
// xxx: NumPy supports a tuple of tuples for "advanced indexing"
|
||||||
self.constrain(*idx_ty, self.primitives.int32, &slice.location)?;
|
// of multidimensional arrays (sequence index -> subset). We
|
||||||
|
// don't support this, but could give a better error message.
|
||||||
|
self.constrain(
|
||||||
|
*idx_ty,
|
||||||
|
self.primitives.int32,
|
||||||
|
&slice.location,
|
||||||
|
)?;
|
||||||
|
}
|
||||||
|
idx_tys.len()
|
||||||
|
}
|
||||||
|
TypeEnum::TList { .. } | TypeEnum::TNDArray { .. } => {
|
||||||
|
return report_error(
|
||||||
|
concat!(
|
||||||
|
"ndarray index is list/array, but NumPy advanced (subset)",
|
||||||
|
"indexing is not supported yet"
|
||||||
|
),
|
||||||
|
slice.location,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
// xxx: Could lead to suboptimal error message, as higher-dimensional indexing is not mentioned?!
|
||||||
|
self.constrain(
|
||||||
|
slice.custom.unwrap(),
|
||||||
|
self.primitives.int32,
|
||||||
|
&slice.location,
|
||||||
|
)?;
|
||||||
|
1
|
||||||
}
|
}
|
||||||
idx_tys.len()
|
|
||||||
} else {
|
|
||||||
// xxx: Could lead to suboptimal error message, as higher-dimensional indexing is not mentioned?!
|
|
||||||
self.constrain(
|
|
||||||
slice.custom.unwrap(),
|
|
||||||
self.primitives.int32,
|
|
||||||
&slice.location,
|
|
||||||
)?;
|
|
||||||
1
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if *num_dims < num_idxs {
|
if *num_dims < num_idxs {
|
||||||
|
|
|
@ -518,12 +518,13 @@ impl TestEnvironment {
|
||||||
a = array([1, 2])
|
a = array([1, 2])
|
||||||
a0 = a[0]
|
a0 = a[0]
|
||||||
b = array([[1, 2], [3, 4]])
|
b = array([[1, 2], [3, 4]])
|
||||||
# b0 = b[0]
|
b0 = b[0]
|
||||||
b00 = b[0, 0]
|
b00 = b[0, 0]
|
||||||
c = 1
|
c = 1
|
||||||
ac = a[c]
|
ac = a[c]
|
||||||
"},
|
"},
|
||||||
[("a", "ndarray[int32, 1]"), ("b", "ndarray[int32, 2]"), ("a0", "int32"), ("b00", "int32"), ("ac", "int32")].iter().cloned().collect(),
|
[("a", "ndarray[int32, 1]"), ("a0", "int32"), ("b", "ndarray[int32, 2]"),
|
||||||
|
("b0", "ndarray[int32, 1]"), ("b00", "int32"), ("ac", "int32")].iter().cloned().collect(),
|
||||||
&[]
|
&[]
|
||||||
; "array test")]
|
; "array test")]
|
||||||
#[test_case(indoc! {"
|
#[test_case(indoc! {"
|
||||||
|
|
|
@ -662,13 +662,17 @@ impl Unifier {
|
||||||
for (k, v) in fields.iter() {
|
for (k, v) in fields.iter() {
|
||||||
match *k {
|
match *k {
|
||||||
RecordKey::Int(_) => {
|
RecordKey::Int(_) => {
|
||||||
if *num_dims > 1 {
|
// .<n> is generated during generic scalar indexing lowering.
|
||||||
unreachable!("xxx implement unification for scalar indexing of multidimensional array");
|
let indexed_ty = if *num_dims == 1 {
|
||||||
}
|
*ty
|
||||||
self.unify_impl(v.ty, *ty, false).map_err(|e| e.at(v.loc))?
|
} else {
|
||||||
|
self.add_ty(TNDArray { ty: *ty, num_dims: *num_dims - 1 })
|
||||||
|
};
|
||||||
|
self.unify_impl(v.ty, indexed_ty, false).map_err(|e| e.at(v.loc))?
|
||||||
}
|
}
|
||||||
RecordKey::Str(_) => {
|
RecordKey::Str(_) => {
|
||||||
return Err(TypeError::new(TypeErrorKind::NoSuchField(*k, b), v.loc))
|
// xxx: Implement .shape here?
|
||||||
|
return Err(TypeError::new(TypeErrorKind::NoSuchField(*k, b), v.loc));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue