hi,
I have created a SimTK::Vector and a std::vector. I found that the resize() method was different.
if we have two empty vector SimTK::Vector a and std::vector b now,
a.resize(10) will return a vector with ten elements but without any default value (the value is random).
b.resize(10) will return a 10 dimensional zero vector.
Are there are any other differences between usage of SimTK::Vector and std::vector like this?
best regards,
jiang
Difference between SimTK::Vector and std::vector
- Jiang Ping
- Posts: 132
- Joined: Sun Aug 26, 2012 4:09 am
- Michael Sherman
- Posts: 806
- Joined: Fri Apr 01, 2005 6:05 pm
Re: Difference between SimTK::Vector and std::vector
Hi, Jiang. Yes, there are many differences between SimTK::Vector (a 1-dimensional numeric object) and std::vector (a container class). Other than the similarity in the names they are basically unrelated classes. Simbody has Vector and Matrix classes for dealing with 1- and 2-d numerical objects. Here a Vector is the type of a column of a Matrix (there is an obscure RowVector class that is the type of a row of a Matrix).
Regarding resize(), std::vector::resize() changes size while preserving the existing content. SimTK::Vector::resize() changes size without preserving existing content; the method SimTK::Vector::resizeKeep() is available to provide the more expensive option in which the existing content is preserved. Also, Vector and Matrix objects are intentionally uninitialized in Release builds to avoid unnecessary touching of large amounts of memory. In Debug builds their elements are initialized to NaN.
You might want to scan through the Doxygen documentation for Vector here (be sure to look at the inheritance diagram since most methods are inherited from VectorBase or MatrixBase). There is also a design document about Simbody's arithmetic classes here.
Regards,
Sherm
Regarding resize(), std::vector::resize() changes size while preserving the existing content. SimTK::Vector::resize() changes size without preserving existing content; the method SimTK::Vector::resizeKeep() is available to provide the more expensive option in which the existing content is preserved. Also, Vector and Matrix objects are intentionally uninitialized in Release builds to avoid unnecessary touching of large amounts of memory. In Debug builds their elements are initialized to NaN.
You might want to scan through the Doxygen documentation for Vector here (be sure to look at the inheritance diagram since most methods are inherited from VectorBase or MatrixBase). There is also a design document about Simbody's arithmetic classes here.
Regards,
Sherm
- Jiang Ping
- Posts: 132
- Joined: Sun Aug 26, 2012 4:09 am
Re: Difference between SimTK::Vector and std::vector
hi Sherm,
Thank you very much for your reply.
That is very helpful for me to understand SimTK::vector and Array.
best regards,
jiang
Thank you very much for your reply.
That is very helpful for me to understand SimTK::vector and Array.
best regards,
jiang
- Michael Sherman
- Posts: 806
- Joined: Fri Apr 01, 2005 6:05 pm
Re: Difference between SimTK::Vector and std::vector
I should also mention that Simbody's SimTK::Array_<T> class is intended to be a container class like std::vector<T>; in that case the APIs are intended to be the same -- the classes are almost interchangeable.