-
-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(vectors): add more strided vec ops, refactor templates
- Loading branch information
1 parent
65b29f4
commit ca91fa9
Showing
31 changed files
with
463 additions
and
18 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 |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import { MultiVecOpVVN, VecOpVVN } from "./api"; | ||
import { ARGS_VVN, defOp } from "./internal/codegen"; | ||
import { ADDM_N } from "./internal/templates"; | ||
import { MATH2_N } from "./internal/templates"; | ||
|
||
/** | ||
* Returns `out = (a + b) * n`. | ||
*/ | ||
export const [addmN, addmN2, addmN3, addmN4] = defOp<MultiVecOpVVN, VecOpVVN>( | ||
ADDM_N, | ||
MATH2_N("+", "*"), | ||
ARGS_VVN | ||
); |
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,9 @@ | ||
import { VecOpSVVV } from "./api"; | ||
import { ARGS_VVV, defOpS, SARGS_VVV } from "./internal/codegen"; | ||
import { MATH2 } from "./internal/templates"; | ||
|
||
export const [addmS2, addmS3, addmS4] = defOpS<VecOpSVVV>( | ||
MATH2("+", "*"), | ||
`${ARGS_VVV},${SARGS_VVV}`, | ||
ARGS_VVV | ||
); |
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,8 @@ | ||
import { VecOpSVNV } from "./api"; | ||
import { ARGS_VVN, defOpS, SARGS_VV } from "./internal/codegen"; | ||
import { MATH2_N } from "./internal/templates"; | ||
|
||
export const [addmSN2, addmSN3, addmSN4] = defOpS<VecOpSVNV>( | ||
MATH2_N("+", "*"), | ||
`${ARGS_VVN},${SARGS_VV}` | ||
); |
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,14 @@ | ||
import { VecOpSVN } from "./api"; | ||
import { | ||
ARGS_V, | ||
ARGS_VN, | ||
defOpS, | ||
SARGS_V | ||
} from "./internal/codegen"; | ||
import { MATH_N } from "./internal/templates"; | ||
|
||
export const [addSN2, addSN3, addSN4] = defOpS<VecOpSVN>( | ||
MATH_N("+"), | ||
`${ARGS_VN},${SARGS_V}`, | ||
ARGS_V | ||
); |
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,31 @@ | ||
import { ReadonlyVec, Vec } from "./api"; | ||
import { setSC3 } from "./setsc"; | ||
|
||
export const crossS2 = ( | ||
a: ReadonlyVec, | ||
b: ReadonlyVec, | ||
ia = 0, | ||
ib = 0, | ||
sa = 1, | ||
sb = 1 | ||
) => a[ia] * b[ib + sb] - a[ia + sa] * b[ib]; | ||
|
||
export const crossS3 = ( | ||
out: Vec | null, | ||
a: ReadonlyVec, | ||
b: ReadonlyVec, | ||
io = 0, | ||
ia = 0, | ||
ib = 0, | ||
so = 1, | ||
sa = 1, | ||
sb = 1 | ||
) => | ||
setSC3( | ||
out || a, | ||
a[ia + sa] * b[ib + 2 * sb] - a[ia + 2 * sa] * b[ib + sb], | ||
a[ia + 2 * sa] * b[ib] - a[ia] * b[ib + 2 * sb], | ||
a[ia] * b[ib + sb] - a[ia + sa] * b[ib], | ||
io, | ||
so | ||
); |
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,14 @@ | ||
import { VecOpSVN } from "./api"; | ||
import { | ||
ARGS_V, | ||
ARGS_VN, | ||
defOpS, | ||
SARGS_V | ||
} from "./internal/codegen"; | ||
import { MATH_N } from "./internal/templates"; | ||
|
||
export const [divSN2, divSN3, divSN4] = defOpS<VecOpSVN>( | ||
MATH_N("/"), | ||
`${ARGS_VN},${SARGS_V}`, | ||
ARGS_V | ||
); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { VecOpSVVV } from "./api"; | ||
import { ARGS_VVV, defOpS, SARGS_VVV } from "./internal/codegen"; | ||
import { MATH2 } from "./internal/templates"; | ||
|
||
export const [maddS2, maddS3, maddS4] = defOpS<VecOpSVVV>( | ||
MATH2("*", "+"), | ||
`${ARGS_VVV},${SARGS_VVV}`, | ||
ARGS_VVV | ||
); |
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,8 @@ | ||
import { VecOpSVNV } from "./api"; | ||
import { ARGS_VNV, defOpS, SARGS_VV } from "./internal/codegen"; | ||
import { MATH2A_N } from "./internal/templates"; | ||
|
||
export const [maddSN2, maddSN3, maddSN4] = defOpS<VecOpSVNV>( | ||
MATH2A_N("*", "+"), | ||
`${ARGS_VNV},${SARGS_VV}` | ||
); |
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,11 @@ | ||
import { VecOpSRoV } from "./api"; | ||
import { dotS2, dotS3, dotS4 } from "./dots"; | ||
|
||
export const magS2: VecOpSRoV<number> = (a, ia, sa) => | ||
Math.sqrt(dotS2(a, a, ia, ia, sa, sa)); | ||
|
||
export const magS3: VecOpSRoV<number> = (a, ia, sa) => | ||
Math.sqrt(dotS3(a, a, ia, ia, sa, sa)); | ||
|
||
export const magS4: VecOpSRoV<number> = (a, ia, sa) => | ||
Math.sqrt(dotS4(a, a, ia, ia, sa, sa)); |
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,11 @@ | ||
import { VecOpSRoV } from "./api"; | ||
import { dotS2, dotS3, dotS4 } from "./dots"; | ||
|
||
export const magSqS2: VecOpSRoV<number> = (a, ia, sa) => | ||
dotS2(a, a, ia, ia, sa, sa); | ||
|
||
export const magSqS3: VecOpSRoV<number> = (a, ia, sa) => | ||
dotS3(a, a, ia, ia, sa, sa); | ||
|
||
export const magSqS4: VecOpSRoV<number> = (a, ia, sa) => | ||
dotS4(a, a, ia, ia, sa, sa); |
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,9 @@ | ||
import { VecOpSVVV } from "./api"; | ||
import { ARGS_VVV, defOpS, SARGS_VVV } from "./internal/codegen"; | ||
import { MIX } from "./internal/templates"; | ||
|
||
export const [mixS2, mixS3, mixS4] = defOpS<VecOpSVVV>( | ||
MIX, | ||
`${ARGS_VVV},${SARGS_VVV}`, | ||
ARGS_VVV | ||
); |
Oops, something went wrong.