@@ -387,6 +387,27 @@ public function toBufferArray()
387387 throw new Exception ('toBufferArray is not implemented yet ' );
388388 }
389389
390+ public static function fill (array $ shape , float |int $ value , ?int $ dtype = null ): static
391+ {
392+ $ mo = self ::mo ();
393+
394+ $ ndArray = $ mo ->full ($ shape , $ value , $ dtype );
395+
396+ return new static ($ ndArray ->buffer (), $ ndArray ->dtype (), $ ndArray ->shape (), $ ndArray ->offset ());
397+ }
398+
399+ public static function repeat (Tensor |array $ tensor , int $ repeats , ?int $ axis = null ): static
400+ {
401+ $ mo = self ::mo ();
402+
403+ if (is_array ($ tensor )) {
404+ $ tensor = $ mo ->array ($ tensor );
405+ }
406+
407+ $ ndArray = $ mo ->la ()->repeat ($ tensor , $ repeats , $ axis );
408+
409+ return new static ($ ndArray ->buffer (), $ ndArray ->dtype (), $ ndArray ->shape (), $ ndArray ->offset ());
410+ }
390411
391412 /**
392413 * Return a one matrix with the given shape.
@@ -555,7 +576,11 @@ public function add(Tensor|float|int $other): static
555576 {
556577 $ mo = self ::mo ();
557578
558- $ ndArray = is_scalar ($ other ) ? $ mo ->op ($ this , '+ ' , $ other ) : $ mo ->add ($ this , $ other );
579+ if ($ other instanceof Tensor) {
580+ $ ndArray = $ mo ->la ()->add ($ this , $ other );
581+ } else {
582+ $ ndArray = $ mo ->la ()->increment ($ this , $ other );
583+ }
559584
560585 return new static ($ ndArray ->buffer (), $ ndArray ->dtype (), $ ndArray ->shape (), $ ndArray ->offset ());
561586 }
@@ -581,20 +606,15 @@ public function sigmoid(): self
581606 *
582607 * @return self
583608 */
584- public function multiply (float |int $ scalar ): self
609+ public function multiply (Tensor | float |int $ scalar ): self
585610 {
586611 $ mo = self ::mo ();
587612
588- $ ndArray = $ mo ->la ()->scal ($ scalar , $ this );
589-
590- return new static ($ ndArray ->buffer (), $ ndArray ->dtype (), $ ndArray ->shape (), $ ndArray ->offset ());
591- }
592-
593- public function divide (float |int $ scalar ): self
594- {
595- $ mo = self ::mo ();
596-
597- $ ndArray = $ mo ->la ()->scal (1 / $ scalar , $ this );
613+ if ($ scalar instanceof Tensor) {
614+ $ ndArray = $ mo ->la ()->multiply ($ this , $ scalar );
615+ } else {
616+ $ ndArray = $ mo ->la ()->scal ($ scalar , $ this );
617+ }
598618
599619 return new static ($ ndArray ->buffer (), $ ndArray ->dtype (), $ ndArray ->shape (), $ ndArray ->offset ());
600620 }
@@ -854,7 +874,7 @@ public function meanPooling(Tensor $other): Tensor
854874 return new Tensor ($ returnedData , $ this ->dtype (), [$ batchSize , $ embedAxis ]);
855875 }
856876
857- public function newSlice (array $ start , array $ size ) : Tensor
877+ public function newSlice (array $ start , array $ size ): Tensor
858878 {
859879 $ mo = self ::mo ();
860880
@@ -972,7 +992,7 @@ protected function softmax2D(): static
972992 /**
973993 * @return Tensor[]
974994 */
975- public function topk (int $ k = null , bool $ sorted = true ) : array
995+ public function topk (int $ k = null , bool $ sorted = true ): array
976996 {
977997 if ($ k === null ) {
978998 $ k = $ this ->shape [0 ];
@@ -1052,7 +1072,7 @@ public function topk(int $k = null, bool $sorted = true) : array
10521072 // Extract top K values and indices from the heap
10531073 for ($ j = 0 ; $ j < $ k ; $ j ++) {
10541074 $ topValues ->buffer [$ this ->offset + ($ i * $ k ) + $ j ] = $ heap [$ j ]['value ' ];
1055- $ topIndices ->buffer [$ this ->offset + ($ i * $ k ) + $ j ] = $ heap [$ j ]['index ' ];
1075+ $ topIndices ->buffer [$ this ->offset + ($ i * $ k) + $ j ] = $ heap [$ j ]['index ' ];
10561076 }
10571077 }
10581078
0 commit comments