Difference between SimTK::Vector and std::vector

Simbody is useful for internal coordinate and coarse grained molecule modeling, large scale mechanical models like skeletons, and anything else that can be modeled as bodies interconnected by joints, acted upon by forces, and restricted by constraints.
POST REPLY
User avatar
Jiang Ping
Posts: 132
Joined: Sun Aug 26, 2012 4:09 am

Difference between SimTK::Vector and std::vector

Post by Jiang Ping » Sun Oct 11, 2015 12:44 pm

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

User avatar
Michael Sherman
Posts: 800
Joined: Fri Apr 01, 2005 6:05 pm

Re: Difference between SimTK::Vector and std::vector

Post by Michael Sherman » Sun Oct 11, 2015 6:47 pm

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

User avatar
Jiang Ping
Posts: 132
Joined: Sun Aug 26, 2012 4:09 am

Re: Difference between SimTK::Vector and std::vector

Post by Jiang Ping » Mon Oct 12, 2015 4:18 am

hi Sherm,

Thank you very much for your reply.
That is very helpful for me to understand SimTK::vector and Array.

best regards,
jiang

User avatar
Michael Sherman
Posts: 800
Joined: Fri Apr 01, 2005 6:05 pm

Re: Difference between SimTK::Vector and std::vector

Post by Michael Sherman » Mon Oct 12, 2015 9:20 am

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.

POST REPLY