Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/erfanzar/EasyDeL
Browse files Browse the repository at this point in the history
  • Loading branch information
erfanzar committed Oct 30, 2023
2 parents d347f8d + 0640547 commit e828ed6
Show file tree
Hide file tree
Showing 20 changed files with 3,088 additions and 2,229 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ parts/
sdist/
var/
wheels/
nn_module.🔥
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
Expand Down
72 changes: 36 additions & 36 deletions docs/Mojo/Array.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@

```mojo
fn convert_numpy_to_easydel_array[
T: DType
](np_array: PythonObject, array_spec: ArrayShape) raises -> Array[T]:
DT: DType
](np_array: PythonObject, array_spec: ArrayShape) raises -> Array[DT]:
```

Converts a Numpy Array To Mojo Array

### matmul_shape 🌪

`fn matmul_shape[T: DType](A: Array[T], B: Array[T]) -> ArrayShape:`
`fn matmul_shape[DT: DType](A: Array[DT], B: Array[DT]) -> ArrayShape:`

give you the shape of new Array for C in Matmul

### matmul 🪓

`fn matmul[nelts: Int, T: DType](inout C: Array[T], A: Array[T], B: Array[T]) -> None:->`
`fn matmul[nelts: Int, DT: DType](inout C: Array[DT], A: Array[DT], B: Array[DT]) -> None:->`

Apply the Matrix Mul for two Arrays

Expand All @@ -30,12 +30,12 @@ a simple matmul with two arrays
from EasyDel import Array, matmul, matmul_shape
fn run[nelts: Int, T: DType]() raises:
fn run[nelts: Int, DT: DType]() raises:
# You can change this But Remember Cols of A must match Rows of B
let A: Array[T] = Array[T](True, 1, 3, 1024, 512) # True Passed to init Array
let B: Array[T] = Array[T](True, 1, 3, 512, 1024)
var C: Array[T] = Array[T](A, B)
matmul[nelts, T](C, A, B) # You Get the same result As Numpy
let A: Array[DT] = Array[DT](True, 1, 3, 1024, 512) # True Passed to init Array
let B: Array[DT] = Array[DT](True, 1, 3, 512, 1024)
var C: Array[DT] = Array[DT](A, B)
matmul[nelts, DT](C, A, B) # You Get the same result As Numpy
fn main() raises:
Expand All @@ -50,7 +50,7 @@ from python import Python as Py
import EasyDel as ed
fn run[T: DType]() raises:
fn run[DT: DType]() raises:
let np_shape_1 = (2, 20)
let shape_1 = ed.ArrayShape(2, 20)
let np_shape_2 = (20, 18)
Expand All @@ -60,13 +60,13 @@ fn run[T: DType]() raises:
let A1 = np.random.randint(0, 20, np_shape_1)
let A2 = np.random.randint(0, 20, np_shape_2)
let E1: ed.Array[T] = ed.convert_numpy_to_easydel_array[T](A1, shape_1)
let E2: ed.Array[T] = ed.convert_numpy_to_easydel_array[T](A2, shape_2)
let E1: ed.Array[DT] = ed.convert_numpy_to_easydel_array[DT](A1, shape_1)
let E2: ed.Array[DT] = ed.convert_numpy_to_easydel_array[DT](A2, shape_2)
let matmul_np = np.matmul(A1, A2)
var C: ed.Array[T] = ed.Array[T](E1, E2) # Prepare Result Array for Matmul
var C: ed.Array[DT] = ed.Array[DT](E1, E2) # Prepare Result Array for Matmul
C.fill(0.0) # Fill it with zeros
ed.matmul[ed.Array[T].nelts, T](C, E1, E2)
ed.matmul[ed.Array[DT].nelts, DT](C, E1, E2)
print(matmul_np)
C.print_array()
Expand Down Expand Up @@ -156,21 +156,21 @@ Takes DType as dynamic Input like `Array[DType.float32]`

- Description: Init Array from ArrayShape and load data from VariadicList[FloatLiteral](Alloc One).

`fn __init__(inout self: Self, pointer: DTypePointer[T], *dim: Int) -> None:`
`fn __init__(inout self: Self, pointer: DTypePointer[DT], *dim: Int) -> None:`

- Description: Init Array from IntArgs and load data from DTypePointer[T](Alloc One).
- Description: Init Array from IntArgs and load data from DTypePointer[DT](Alloc One).

`fn __init__(inout self: Self, pointer: DTypePointer[T], *dim: Int) -> None:`
`fn __init__(inout self: Self, pointer: DTypePointer[DT], *dim: Int) -> None:`

- Description: Init Array from given data from DTypePointer[T](Alloc Zero).
- Description: Init Array from given data from DTypePointer[DT](Alloc Zero).

### Alloc

`fn alloc(inout self: Self) -> None:`

- Description: Allocate or Init The Array.

`fn alloc(inout self: Self, fill:SIMD[T, 1]) -> None:`
`fn alloc(inout self: Self, fill:SIMD[DT, 1]) -> None:`

- Allocate or Init The Array and fill that with given fill number.

Expand Down Expand Up @@ -215,52 +215,52 @@ Reshape:
```
fn load[
nelts: Int, off: Int
](self, index: InlinedFixedVector[off, Int]) -> SIMD[T, nelts]:
](self, index: InlinedFixedVector[off, Int]) -> SIMD[DT, nelts]:
```

`fn load[nelts: Int, off: Int](self, index: StaticIntTuple[off]) -> SIMD[T, nelts]:`
`fn load[nelts: Int, off: Int](self, index: StaticIntTuple[off]) -> SIMD[DT, nelts]:`

`fn load[nelts: Int](self, index: Int) -> SIMD[T, nelts]:`
`fn load[nelts: Int](self, index: Int) -> SIMD[DT, nelts]:`

### Store Functions

```
fn store[
nelts: Int, off: Int
](self, index: InlinedFixedVector[off, Int], val: SIMD[T, nelts]) -> None:
](self, index: InlinedFixedVector[off, Int], val: SIMD[DT, nelts]) -> None:
```

```
fn store[
nelts: Int, off: Int
](self, index: StaticIntTuple[off], val: SIMD[T, nelts]) -> None:
](self, index: StaticIntTuple[off], val: SIMD[DT, nelts]) -> None:
```

`fn store[nelts: Int](self, index: Int, val: SIMD[T, nelts]) -> None:`
`fn store[nelts: Int](self, index: Int, val: SIMD[DT, nelts]) -> None:`

### `__getitem__` Functions

`fn __getitem__[off: Int](self, index: InlinedFixedVector[off, Int]) -> SIMD[T, 1]:`
`fn __getitem__[off: Int](self, index: InlinedFixedVector[off, Int]) -> SIMD[DT, 1]:`

`fn __getitem__[off: Int](self, index: StaticIntTuple[off]) -> SIMD[T, 1]:`
`fn __getitem__[off: Int](self, index: StaticIntTuple[off]) -> SIMD[DT, 1]:`

`fn __getitem__(self, index: Int) -> SIMD[T, 1]:`
`fn __getitem__(self, index: Int) -> SIMD[DT, 1]:`

`fn __getitem__(self, d1: Int, d2: Int, val:SIMD[T, 1]) raises->None:`
`fn __getitem__(self, d1: Int, d2: Int, val:SIMD[DT, 1]) raises->None:`

`fn __getitem__(self, d1: Int, d2: Int, d3: Int, val:SIMD[T, 1]) raises->None:`
`fn __getitem__(self, d1: Int, d2: Int, d3: Int, val:SIMD[DT, 1]) raises->None:`

### `__setitem__` Functions

`fn __setitem__(self, index: Int, val: SIMD[T, 1]) -> None:`
`fn __setitem__(self, index: Int, val: SIMD[DT, 1]) -> None:`

`fn __setitem__[off: Int](self, index: InlinedFixedVector[off, Int], val: SIMD[T, 1]):`
`fn __setitem__[off: Int](self, index: InlinedFixedVector[off, Int], val: SIMD[DT, 1]):`

`fn __setitem__[off: Int](self, index: StaticIntTuple[off], val: SIMD[T, 1]):`
`fn __setitem__[off: Int](self, index: StaticIntTuple[off], val: SIMD[DT, 1]):`

`fn __setitem__(self, d1: Int, d2: Int, val:SIMD[T, 1]) raises->None:`
`fn __setitem__(self, d1: Int, d2: Int, val:SIMD[DT, 1]) raises->None:`

`fn __setitem__(self, d1: Int, d2: Int, d3: Int, val:SIMD[T, 1]) raises->None:`
`fn __setitem__(self, d1: Int, d2: Int, d3: Int, val:SIMD[DT, 1]) raises->None:`

### Math Functions

Expand Down Expand Up @@ -410,5 +410,5 @@ fn acosh(inout self: Self, rt: Runtime) -> Self:
# Fill the whole array with the val
fn fill(inout self: Self, val: SIMD[T, 1]) -> None:
fn fill(inout self: Self, val: SIMD[DT, 1]) -> None:
```
57 changes: 43 additions & 14 deletions lib/mojo/EasyDel/__init__.🔥
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,54 @@ from .array import (
Array,
ArrayShape,
# Array Module
convert_numpy_to_easydel_array,
matmul,
matmul_2d,
matmul_3D,
matmul_shape,
matmul_single_row,
matmul_2d,
matmul,
T_AXIS_0_2_1, # LOW LEVEL AND PARALLELIZED , VECTORIZED
T_AXIS_2_1_0, # LOW LEVEL AND PARALLELIZED , VECTORIZED
T_AXIS_1_0_2, # LOW LEVEL AND PARALLELIZED , VECTORIZED
T_2D, # LOW LEVEL AND PARALLELIZED , VECTORIZED
CAT_3D_AXIS_2, # LOW LEVEL AND PARALLELIZED , VECTORIZED
rotate_half, # LOW LEVEL AND PARALLELIZED , VECTORIZED
arange,
# Array Utils
softmax,
silu,
base_case_matmul,
kernel_add,
kernel_div,
kernel_matmul,
kernel_mul,
kernel_pow,
kernel_sub,
array_abs,
array_acos,
array_add,
array_asin,
array_atan,
array_copy,
array_tanh,
array_tan,
array_cos,
array_cosh,
array_div,
array_exp,
array_exp2,
array_relu,
array_log,
array_log2,
array_mul,
array_pow_all,
array_sin,
array_sinh,
array_sqrt,
relu,
leaky_relu,
softmax,
silu,
sigmoid,
sample_array,
mean,
ce,
mse,
sample,
T_AXIS_0_2_1,
T_AXIS_1_0_2,
T_AXIS_2_1_0,
CAT_4D_AXIS_3,
convert_numpy_to_easydel_array,
arange,
# Funcs
PointerOperation,
# ED Struct
Expand Down
63 changes: 51 additions & 12 deletions lib/mojo/EasyDel/array/__init__.🔥
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,59 @@ Copyright (c) Erfan zare Chavoshi
EasyDel Library [MOJO/Matrix]
"""

from .array_module import Array, ArrayShape
from .array_utils import (
convert_numpy_to_easydel_array,
from .array_module import (
Array,
ArrayShape,
matmul_shape,
matmul_single_row,
matmul_2d,
matmul,
T_AXIS_0_2_1, # LOW LEVEL AND PARALLELIZED , VECTORIZED
T_AXIS_2_1_0, # LOW LEVEL AND PARALLELIZED , VECTORIZED
T_AXIS_1_0_2, # LOW LEVEL AND PARALLELIZED , VECTORIZED
T_2D, # LOW LEVEL AND PARALLELIZED , VECTORIZED
CAT_3D_AXIS_2, # LOW LEVEL AND PARALLELIZED , VECTORIZED
rotate_half, # LOW LEVEL AND PARALLELIZED , VECTORIZED
matmul_2d,
matmul_3D,
matmul_single_row,
base_case_matmul,
kernel_add,
kernel_div,
kernel_matmul,
kernel_mul,
kernel_pow,
kernel_sub,
array_abs,
array_acos,
array_add,
array_asin,
array_atan,
array_copy,
array_tanh,
array_tan,
array_cos,
array_cosh,
array_div,
array_exp,
array_exp2,
array_relu,
array_log,
array_log2,
array_mul,
array_pow_all,
array_sin,
array_sinh,
array_sqrt,
array_pow,
array_sub,
relu,
leaky_relu,
softmax,
silu,
sigmoid,
mean,
ce,
mse,
sample,
T_AXIS_0_2_1,
T_AXIS_1_0_2,
T_AXIS_2_1_0,
CAT_4D_AXIS_3,
rotate_half,
convert_numpy_to_easydel_array,
arange,
)
from .funcs import softmax, silu, relu, leaky_relu, sigmoid, sample_array
from .ed_struct import PointerOperation
Loading

0 comments on commit e828ed6

Please sign in to comment.