Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions spatialmath/spatialvector.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ def __init__(self, value):
super().__init__()

if base.isvector(value, 6):
self.data = [np.array(value)]
self.data = [base.getvector(value, 6)]
elif base.isvector(value, 3):
self.data = [np.r_[value, 0, 0, 0]]
self.data = [np.r_[base.getvector(value, 3), 0, 0, 0]]
elif isinstance(value, SpatialVector):
self.data = [value.A]
elif base.ismatrix(value, (6, None)):
Expand Down
36 changes: 36 additions & 0 deletions tests/test_spatialvector_shaped_input.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""Row and column vectors must use the same flat internal representation."""

import numpy as np
import numpy.testing as nt
import pytest
from spatialmath import (
SpatialVelocity,
SpatialAcceleration,
SpatialForce,
SpatialMomentum,
)


@pytest.mark.parametrize(
"cls", [SpatialVelocity, SpatialAcceleration, SpatialForce, SpatialMomentum]
)
@pytest.mark.parametrize("size", [3, 6])
@pytest.mark.parametrize("shape", ["flat", "row", "column"])
def test_shaped_vector_constructor(cls, size, shape):
values = np.arange(1, size + 1, dtype=float)
supplied = (
values
if shape == "flat"
else values.reshape((1, size) if shape == "row" else (size, 1))
)
original = supplied.copy()
vector = cls(supplied)
expected = values if size == 6 else np.r_[values, 0, 0, 0]
assert len(vector) == 1
assert vector.A.shape == (6,)
assert vector.isvalid(vector.A, check=False)
nt.assert_array_equal(vector.A, expected)
nt.assert_array_equal(vector[0].A, expected)
assert str(vector).startswith(cls.__name__ + "[")
nt.assert_array_equal((-vector).A, -expected)
nt.assert_array_equal(supplied, original)