-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. get output layer removed, use loss instead 2. assign regularization to tensors 3. add timing module 4. Add backend for future promotion
- Loading branch information
Showing
15 changed files
with
295 additions
and
198 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
|
||
/** | ||
* ov = m * v | ||
*/ | ||
function TensorVectorProduct(ov, m, v) { | ||
let ncol = m.axis(-1) | 0; | ||
let nrow = m.axis(-2) | 0; | ||
let new_shape = m.shape.slice(); new_shape.pop(); | ||
let bs = ncol * nrow | 0; | ||
let N = (m.size / bs) | 0; | ||
|
||
let mw = m.w, vw = v.w, ow = ov.w; | ||
ow.fill(0.); | ||
for (let z = 0; z < N; z++) { | ||
for (let i = 0; i < nrow; i++) { | ||
for (let j = 0; j < ncol; j++) { | ||
ow[z * nrow + i] += mw[z * bs + i * ncol + j] * vw[j]; | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* ov += m' * v | ||
*/ | ||
function TransposedTensorVectorProductAdd(ov, m, v) { | ||
let ncol = m.axis(-1) | 0; | ||
let nrow = m.axis(-2) | 0; | ||
let new_shape = m.shape.slice(); | ||
|
||
// reverse order | ||
let a = new_shape.pop(); | ||
new_shape.pop(); | ||
new_shape.push(a); | ||
|
||
let bs = ncol * nrow | 0; | ||
let N = (m.size / bs) | 0; | ||
|
||
let mw = m.w, vw = v.w, ow = ov.w; | ||
// ow.fill(0.); | ||
for (let z = 0; z < N; z++) { | ||
for (let i = 0; i < nrow; i++) { | ||
for (let j = 0; j < ncol; j++) { | ||
// transposed order | ||
ow[z * ncol + j] += mw[z * bs + i * ncol + j] * vw[i]; | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
/** | ||
* HadmardProduct apply to self | ||
*/ | ||
function HadmardProduct_s(o, x) { | ||
let N = o.size, ow = o.w, xw = x.w; | ||
for (let i = 0; i < N; i++) { | ||
ow[i] *= xw; | ||
} | ||
} | ||
|
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
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
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
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
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
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
Oops, something went wrong.