torch / tds

Torch C data structures
Other
80 stars 25 forks source link

vec: clear #15

Closed deltheil closed 8 years ago

deltheil commented 8 years ago

Any reason to prevent removing all elements from the vector via vec:resize(0)? (see this assert). Of course, as a workaround, one can do: vec:resize(1); vec:remove(1).

Let me know what you think and I can send a PR (if there is any interest). Other possibilty: introduce a clear API:

diff --git a/vec.lua b/vec.lua
index b4aad33..a002028 100644
--- a/vec.lua
+++ b/vec.lua
@@ -45,6 +45,11 @@ function mt:resize(size)
    C.tds_vec_resize(self, size)
 end

+function mt:clear()
+   assert(self)
+   C.tds_vec_resize(self, 0)
+end
+
 if pcall(require, 'torch') then
    function mt:concatstorage(sep, i, j)
       i = i or 1
soumith commented 8 years ago

i dont see any reason to prevent this really!

deltheil commented 8 years ago

Allright! Will send a PR just in case.

deltheil commented 8 years ago

Oops it was a little bit too fast. I changed by mistake the assert message: must be a strictly positive number that should remain must be a positive number. Can you revert or force push? Sorry about that.

deltheil commented 8 years ago

Fixed by #19.