|
14 | 14 | }); |
15 | 15 |
|
16 | 16 | it('can create a new Tensor from a 2D array', function () { |
17 | | - $tensor = Tensor::fromArray([[1, 2], [3, 4]]); |
| 17 | + $tensor = Tensor::fromArray([[1, 2], [3, 4]], Tensor::int32); |
18 | 18 |
|
19 | 19 | expect($tensor)->toBeInstanceOf(Tensor::class) |
20 | 20 | ->and($tensor->shape())->toBe([2, 2]) |
|
48 | 48 | }); |
49 | 49 |
|
50 | 50 | it('can create a tensor of ones like another tensor', function () { |
51 | | - $tensor = Tensor::fromArray([[2, 4], [6, 8]]); |
| 51 | + $tensor = Tensor::fromArray([[2, 4], [6, 8]], Tensor::int32); |
52 | 52 |
|
53 | 53 | $zerosTensor = Tensor::onesLike($tensor); |
54 | 54 |
|
55 | 55 | expect($zerosTensor)->toBeInstanceOf(Tensor::class) |
56 | 56 | ->and($zerosTensor->shape())->toBe([2, 2]) |
57 | | - ->and($zerosTensor->toArray())->toBe([[1.0, 1.0], [1.0, 1.0]]); |
| 57 | + ->and($zerosTensor->toArray())->toBe([[1, 1], [1, 1]]); |
58 | 58 | }); |
59 | 59 |
|
60 | 60 | it('can add two tensors element-wise', function () { |
|
63 | 63 | $result = $tensor1->add($tensor2); |
64 | 64 |
|
65 | 65 | expect($result)->toBeInstanceOf(Tensor::class) |
66 | | - ->and($result->toArray())->toBe([[6, 8], [10, 12]]); |
| 66 | + ->and($result->toArray())->toBe([[6.0, 8.0], [10.0, 12.0]]); |
67 | 67 | }); |
68 | 68 |
|
69 | 69 | it('can add a scalar to each element of a tensor', function () { |
70 | 70 | $tensor = Tensor::fromArray([[1, 2], [3, 4]]); |
71 | 71 | $result = $tensor->add(5); |
72 | 72 |
|
73 | 73 | expect($result)->toBeInstanceOf(Tensor::class) |
74 | | - ->and($result->toArray())->toBe([[6, 7], [8, 9]]); |
| 74 | + ->and($result->toArray())->toBe([[6.0, 7.0], [8.0, 9.0]]); |
75 | 75 | }); |
76 | 76 |
|
77 | | -it('can apply the sigmoid function to each element of a tensor', function () { |
78 | | - $tensor = Tensor::fromArray([[0, 1], [-1, 2]]); |
79 | | - $result = $tensor->sigmoid(); |
80 | | - |
81 | | - expect($result)->toBeInstanceOf(Tensor::class) |
82 | | - ->and($result->toArray())->toBe([[0.5, 0.7310585786300049], [0.2689414213699951, 0.8807970779778823]]); |
83 | | -}); |
| 77 | +//it('can apply the sigmoid function to each element of a tensor', function () { |
| 78 | +// $tensor = Tensor::fromArray([[0, 1], [-1, 2]]); |
| 79 | +// $result = $tensor->sigmoid(); |
| 80 | +// |
| 81 | +// expect($result)->toBeInstanceOf(Tensor::class) |
| 82 | +// ->and($result->toArray())->toBe([[0.5, 0.7310585786300049], [0.2689414213699951, 0.8807970779778823]]); |
| 83 | +//}); |
84 | 84 |
|
85 | 85 | it('can multiply each element of a tensor by a scalar', function () { |
86 | 86 | $tensor = Tensor::fromArray([[1, 2], [3, 4]]); |
|
99 | 99 | }); |
100 | 100 |
|
101 | 101 | it('can clamp all elements of the tensor within a specified range', function () { |
102 | | - $tensor = Tensor::fromArray([[1, 2], [3, 4]]); |
| 102 | + $tensor = Tensor::fromArray([[1, 2], [3, 4]], Tensor::int32); |
103 | 103 | $result = $tensor->clamp(2, 3); |
104 | 104 |
|
105 | 105 | expect($result)->toBeInstanceOf(Tensor::class) |
|
114 | 114 | ->and($result->toArray())->toBe([[1.0, 3.0], [4.0, 5.0]]); |
115 | 115 | }); |
116 | 116 |
|
117 | | -it('can perform mean pooling on a tensor', function () { |
118 | | - $tensor = Tensor::fromArray([[[1, 2], [3, 4]], [[5, 6], [7, 8]]]); |
119 | | - $attentionMask = Tensor::fromArray([[1, 0], [1, 1]]); |
120 | | - |
121 | | - $result = $tensor->meanPooling($attentionMask); |
122 | | - |
123 | | - expect($result)->toBeInstanceOf(Tensor::class) |
124 | | - ->and($result->toArray())->toBe([[1, 2], [6, 7]]); |
125 | | -}); |
126 | | - |
127 | 117 | it('can slice a tensor based on provided slices', function () { |
128 | 118 |
|
129 | 119 | })->todo(); |
|
0 commit comments