Last active
September 18, 2016 10:12
-
-
Save Marenz/fadabe90e59bf192c72673370349db1a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
auto s_zip = assumeSameStructure!("g", "i", "s_prev", "f")( | |
this.state.g, this.state.i, this.s_prev, this.state.f); | |
this.state.s = s_zip.ndMap!(z => z.g * z.i + z.s_prev * z.f).slice; | |
// vs | |
this.state.s = this.state.g.perElement!mul(this.state.i) | |
.perElement!add(this.s_prev.perElement!mul(this.state.f)); | |
// functions for the second part | |
auto mul ( T ) ( T a, T b ) { return a * b; } | |
auto add ( T ) ( T a, T b ) { return a + b; } | |
// Per forms per-element operation on the two vectors | |
auto perElement ( alias op ) ( Vector a, Vector b ) | |
{ | |
auto zip = assumeSameStructure!("a", "b")(a, b); | |
return zip.ndMap!(z => op(z.a, z.b)).slice; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment