Skip to content

Commit

Permalink
chore: add README.md and LICENSE file
Browse files Browse the repository at this point in the history
Signed-off-by: psinghal20 <psinghal20@gmail.com>
  • Loading branch information
psinghal20 committed May 12, 2020
1 parent 3257f07 commit a946276
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ name = "auto_vec"
version = "0.1.0"
authors = ["psinghal20 <psinghal20@gmail.com>"]
edition = "2018"
description = "Auto-vec is simple proc macro to vectorize your scalar functions"
readme = "README.md"
repository = "https://github.com/psinghal20/Auto-Vec"
license = "MIT"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Pratyush Singhal

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Auto-Vec
Auto-vec is simple proc macro to vectorize your scalar functions.

## Example
```rust
#[auto_vec]
pub fn foo(arg1: i64, arg2: i32) -> i64 {
return (arg1 + arg2 as i64);
}
```
Allowing you to do something like this:
```rust
fn main() {
let results = foo_vec(vec![1,2,3,4], vec![1,2,3,4]);
// returned vector is of form [foo(arg1[0], arg2[0]), ...]
assert_eq!(results, vec![2, 4, 6, 8]);
}
```

It keeps the original function and allows computation of the specified function over a vector of inputs. The generated function inherits the visibility and generics from the original function definition. The generated function takes the vectors as mutable so as to take ownership of the inner elements.

The vectorized function expects to get input vectors of the equal length, and panics if that is not the case.
```rust
// Panics due to unequal length of input vectors
foo_vec(vec![1,2,3], vec![1,2]);
```

Auto vec also requires the function to have one or more input types(other than self) and a return type, and fails to compile otherwise.

```rust
#[auto_vec]
pub fn bar() -> String; // Compile time error

#[auto_vec]
pub fn ha(a:i64); // Compile time error
```

It allows vectorization of methods too, accepting vectors for every argument except the first self argument.
```rust
struct T;
impl T {
#[auto_vec]
fn foo(&self, arg1: usize, arg2: usize) -> usize {
return arg1 + arg2;
}
}
fn main() {
let a = T{};
assert_eq!(a.foo_vec(vec![1, 2, 3], vec![1, 2, 3]), vec![2, 4, 6])
}
```

**Warning**: Methods accepting self receviers with a specific type, such as `self: Box<Self>` are not parsed correctly currently and lead to wrong code generation. Auto Vec currently works only for untyped `self` receviers.

## License
Auto-Vec is under the MIT license. See the [LICENSE](LICENSE) file for details.

0 comments on commit a946276

Please sign in to comment.