Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

getmatrix() rejects a list of lists; revisit the base.X matrix/vector converters

未关闭
#255 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
活跃
技术栈
numpy, python
领域
tooling

调研方向

Start with getmatrix and getvector in the spatialmath base package, plus isvector and ismatrix, and run the three examples in the issue to reproduce the TypeError and the flat-list reshape. Check spatialmath/base/types.py for Points2 and Points3. The issue leaves open whether the flat-list reshape is intended and whether the type aliases should widen, so settle those with a maintainer before changing code. Done means nested lists and tuples are converted and shape-checked, with tests for the existing converters.

由索引模型根据 Issue 内容生成。

描述

getmatrix() (and getvector()) reject the most natural way to write a set of points: a list of lists. Found while adding type hints to RTB, where a 2xN path of waypoints is passed to a function.

from spatialmath.base import getmatrix
getmatrix([[0, 1, 2], [0, 1, 0]], (2, None))   # TypeError: argument must be scalar or ndarray
getmatrix([[0, 0], [1, 1], [2, 0]], (2, None))  # TypeError
getmatrix(np.zeros((2, 5)), (2, None))          # OK, (2, 5)

Two related problems:

  1. Nested lists and tuples are rejected. The function accepts a scalar, a 1D array-like or an ndarray, but not a list of rows. I would expect it to convert these with np.asarray and then check the shape against shape, raising ValueError on mismatch.
  2. A flat list is silently reshaped. getmatrix([0, 1, 2, 3], (2, None)) returns a (2, 2) array. That is convenient for (2,2) but can hide a mistake when the caller meant a path of 2 points or a different layout.

Also, Points2 and Points3 in spatialmath.base.types are plain NDArray, so the type hint says "ndarray only" while the docstrings in callers say "array_like".

Suggested direction:

  • Make getmatrix (and the other base.X... converters) accept array-likes of any nesting and validate the shape, so callers can replace hand-written np.asarray(...) plus ndim/shape checks with one call.
  • Decide whether the flat-list reshape is intended, and document it if so.
  • Consider whether Points2/Points3 should widen to accept sequences.

I'll revisit the base.getvector/getmatrix/isvector/ismatrix family together, since the same question applies to all of them.

主要语言
Python
星标
648
派生
108
平均合并
10 天 20 小时
30 天内合并 PR
21

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

rai-opensource/spatialmath-python 的其他 Issue

查看 rai-opensource/spatialmath-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。