<commit_before># pytorch
POC for wrapping torch in python

# Examples

Examples of what is possible currently:
* pytorch
* pynn

# pytorch

Run by doing:
```
./build.sh
./run.sh
```

Script:
```
from __future__ import print_function
import PyTorch
import array
import numpy

A = numpy.random.rand(6).reshape(3,2).astype(numpy.float32)
B = numpy.random.rand(8).reshape(2,4).astype(numpy.float32)

C = A.dot(B)
print('C', C)

print('calling .asTensor...')
tensorA = PyTorch.asTensor(A)
tensorB = PyTorch.asTensor(B)
print(' ... asTensor called')

print('tensorA', tensorA)

tensorA.set2d(1, 1, 56.4)
tensorA.set2d(2, 0, 76.5)
print('tensorA', tensorA)
print('A', A)

tensorA += 5
print('tensorA', tensorA)
print('A', A)

tensorA2 = tensorA + 7
print('tensorA2', tensorA2)
print('tensorA', tensorA)

tensorAB = tensorA * tensorB
print('tensorAB', tensorAB)

print('A.dot(B)', A.dot(B))

print('tensorA[2]', tensorA[2])

D = PyTorch.FloatTensor(5,3).fill(1)
print('D', D)

D[2][2] = 4
print('D', D)

D[3].fill(9)
print('D', D)

D.narrow(1,2,1).fill(0)
print('D', D)
```

Output:

```
C [[ 0.07321505  0.21034354  0.35347611  0.30827984]
 [ 0.1136106   0.21236189  0.37396491  0.12081985]
 [ 0.1540852   0.34465638  0.59388119  0.34144905]]
calling .asTensor...
 ... asTensor called
tensorA 0.108945 0.397354
0.697115 0.0342486
0.683192 0.335684
[torch.FloatTensor of size 3x2]

tensorA 0.108945 0.397354
0.697115 56.4
76.5 0.335684
[torch.FloatTensor of size 3x2]

A [[  0.10894503   0.3973541 ]
 [  0.697115    56.40000153]
 [ 76.5          0.33568445]]
tensorA 5.10894 5.39735
5.69711 61.4
81.5 5.33568
[torch.FloatTensor of size 3x2]

A [[  5.10894489   5.39735413]
 [  5.69711494  61.40000153]
 [ 81.5          5.3356843 ]]
tensorA2 12.1089 12.3974
12.6971 68.4
88.5 12.3357
[torch.FloatTensor of size 3x2]

tensorA 5.10894 5.39735
5.69711 61.4
81.5 5.33568
[torch.FloatTensor of size 3x2]

tensorAB 1.56072 3.88211 6.61399 4.68479
9.57568 29.3573 49.0571 46.1098
13.4707 25.4291 44.7226 15.1082
[torch.FloatTensor of size 3x4]

A.dot(B) [[  1.56071877   3.88210678   6.61398697   4.68478727]
 [  9.57568169  29.35725784  49.05712891  46.10975647]
 [ 13.47066402  25.42912674  44.72264099  15.10820866]]
tensorA[2] 81.5 5.33568
[torch.FloatTensor of size 2]

D 1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
[torch.FloatTensor of size 5x3]

D 1 1 1
1 1 1
1 1 4
1 1 1
1 1 1
[torch.FloatTensor of size 5x3]

D 1 1 1
1 1 1
1 1 4
9 9 9
1 1 1
[torch.FloatTensor of size 5x3]

D 1 1 0
1 1 0
1 1 0
9 9 0
1 1 0
[torch.FloatTensor of size 5x3]
```

# pynn

Run by doing:
```
./build.sh
./nn_run.sh
```

Test script:
```
from __future__ import print_function
import PyTorch
import array
import numpy
import sys

A = numpy.random.rand(6).reshape(2,3).astype(numpy.float32)

tensorA = PyTorch.asTensor(A)

nn = PyTorch.Nn()
linear = nn.Linear(3, 8)
output = linear.updateOutput(tensorA)
print('output', output)
print('weight', linear.weight)<commit_msg>update readme with various random functoins<commit_after># pytorch
POC for wrapping torch in python

# Examples

Examples of what is possible currently:
* pytorch
* pynn

# pytorch

Run by doing:
```
./build.sh
./run.sh
```

Script:
```
from __future__ import print_function
import PyTorch
import array
import numpy

A = numpy.random.rand(6).reshape(3,2).astype(numpy.float32)
B = numpy.random.rand(8).reshape(2,4).astype(numpy.float32)

C = A.dot(B)
print('C', C)

print('calling .asTensor...')
tensorA = PyTorch.asTensor(A)
tensorB = PyTorch.asTensor(B)
print(' ... asTensor called')

print('tensorA', tensorA)

tensorA.set2d(1, 1, 56.4)
tensorA.set2d(2, 0, 76.5)
print('tensorA', tensorA)
print('A', A)

tensorA += 5
print('tensorA', tensorA)
print('A', A)

tensorA2 = tensorA + 7
print('tensorA2', tensorA2)
print('tensorA', tensorA)

tensorAB = tensorA * tensorB
print('tensorAB', tensorAB)

print('A.dot(B)', A.dot(B))

print('tensorA[2]', tensorA[2])

D = PyTorch.FloatTensor(5,3).fill(1)
print('D', D)

D[2][2] = 4
print('D', D)

D[3].fill(9)
print('D', D)

D.narrow(1,2,1).fill(0)
print('D', D)

print(PyTorch.FloatTensor(3,4).uniform())
print(PyTorch.FloatTensor(3,4).bernoulli())
print(PyTorch.FloatTensor(3,4).normal())
print(PyTorch.FloatTensor(3,4).cauchy())
print(PyTorch.FloatTensor(3,4).exponential())
print(PyTorch.FloatTensor(3,4).logNormal())
print(PyTorch.FloatTensor(3,4).geometric())
```

Output:

```
C [[ 0.07321505  0.21034354  0.35347611  0.30827984]
 [ 0.1136106   0.21236189  0.37396491  0.12081985]
 [ 0.1540852   0.34465638  0.59388119  0.34144905]]
calling .asTensor...
 ... asTensor called
tensorA 0.108945 0.397354
0.697115 0.0342486
0.683192 0.335684
[torch.FloatTensor of size 3x2]

tensorA 0.108945 0.397354
0.697115 56.4
76.5 0.335684
[torch.FloatTensor of size 3x2]

A [[  0.10894503   0.3973541 ]
 [  0.697115    56.40000153]
 [ 76.5          0.33568445]]
tensorA 5.10894 5.39735
5.69711 61.4
81.5 5.33568
[torch.FloatTensor of size 3x2]

A [[  5.10894489   5.39735413]
 [  5.69711494  61.40000153]
 [ 81.5          5.3356843 ]]
tensorA2 12.1089 12.3974
12.6971 68.4
88.5 12.3357
[torch.FloatTensor of size 3x2]

tensorA 5.10894 5.39735
5.69711 61.4
81.5 5.33568
[torch.FloatTensor of size 3x2]

tensorAB 1.56072 3.88211 6.61399 4.68479
9.57568 29.3573 49.0571 46.1098
13.4707 25.4291 44.7226 15.1082
[torch.FloatTensor of size 3x4]

A.dot(B) [[  1.56071877   3.88210678   6.61398697   4.68478727]
 [  9.57568169  29.35725784  49.05712891  46.10975647]
 [ 13.47066402  25.42912674  44.72264099  15.10820866]]
tensorA[2] 81.5 5.33568
[torch.FloatTensor of size 2]

D 1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
[torch.FloatTensor of size 5x3]

D 1 1 1
1 1 1
1 1 4
1 1 1
1 1 1
[torch.FloatTensor of size 5x3]

D 1 1 1
1 1 1
1 1 4
9 9 9
1 1 1
[torch.FloatTensor of size 5x3]

D 1 1 0
1 1 0
1 1 0
9 9 0
1 1 0
[torch.FloatTensor of size 5x3]

0.0069189 0.0934481 0.488816 0.989025
0.125598 0.477475 0.86955 0.0472904
0.322867 0.330087 0.931925 0.639966
[torch.FloatTensor of size 3x4]

1 1 1 1
1 1 1 1
1 1 0 0
[torch.FloatTensor of size 3x4]

-1.19303 -0.351101 -1.16909 -1.03799
-0.197524 -0.812448 0.778675 -2.12981
0.42737 0.566242 -0.970235 -0.191112
[torch.FloatTensor of size 3x4]

-1.2123 -1.77004 0.0256488 -0.246493
-0.55631 2.81549 0.85101 1.73442
6.53249 -0.252495 -2.52411 -0.0164343
[torch.FloatTensor of size 3x4]

0.214561 1.79436 0.385731 0.439792
0.67608 0.434034 1.91894 1.45847
0.0678396 1.34574 1.01357 1.06901
[torch.FloatTensor of size 3x4]

0.342984 0.124501 0.019485 1.08767
0.208956 0.412723 0.702379 0.144819
0.0494364 0.158265 0.174502 1.17602
[torch.FloatTensor of size 3x4]

2 1 3 1
1 1 1 1
3 1 4 1
[torch.FloatTensor of size 3x4]
```

# pynn

Run by doing:
```
./build.sh
./nn_run.sh
```

Test script:
```
from __future__ import print_function
import PyTorch
import array
import numpy
import sys

A = numpy.random.rand(6).reshape(2,3).astype(numpy.float32)

tensorA = PyTorch.asTensor(A)

nn = PyTorch.Nn()
linear = nn.Linear(3, 8)
output = linear.updateOutput(tensorA)
print('output', output)
print('weight', linear.weight)
{'fraction_non_alphanumeric': 0.14687812544649237, 'fraction_numerical': 0.2633233319045578, 'mean_word_length': 3.654255319148936, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2288317', 'n_tokens_mistral': 4262, 'n_tokens_neox': 3223, 'n_words': 799}