Skip to content

Commit 6f64b06

Browse files
committed
Workaround exception of gather and reduceGather
1 parent 100e630 commit 6f64b06

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/PhpMath.php

+16-3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ protected function useMath(Buffer $X)
3636
return $this->forceMath || in_array($X->dtype(),$this->floatTypes);
3737
}
3838

39+
public function logging($message)
40+
{
41+
fwrite(STDERR,$message."\n");
42+
}
43+
3944
protected function math_copy(
4045
int $n,
4146
Buffer $X, int $offsetX, int $incX,
@@ -908,6 +913,8 @@ public function gather(
908913
throw new RuntimeException('Matrix A specification too large for buffer.');
909914
if($offsetB+$n*$k>count($B))
910915
throw new RuntimeException('Matrix B specification too large for buffer.');
916+
if($numClass<=0)
917+
throw new RuntimeException('numClass must be grator than zero.');
911918

912919
$idxX = $offsetX;
913920
$idxA = $offsetA;
@@ -916,8 +923,10 @@ public function gather(
916923
for($j=0;$j<$n;$j++) {
917924
$index = $X[$idxX+$j];
918925
if($index>=$numClass) {
919-
throw new RuntimeException("index is out of range.:".$index);
920-
}
926+
//throw new RuntimeException("index is out of range.:".$index);
927+
$this->logging("gather: index is out of range.:".$index." numClass=".$numClass);
928+
$index = $numClass-1;
929+
}
921930
$iA = $idxA+$index*$ldIndex;
922931
$iB = $idxB+$j*$k;
923932
if($reverse) {
@@ -970,6 +979,8 @@ public function reduceGather(
970979
throw new RuntimeException('Matrix A specification too large for buffer.');
971980
if($offsetB+$m*$n>count($B))
972981
throw new RuntimeException('Matrix B specification too large for buffer.');
982+
if($numClass<=0)
983+
throw new RuntimeException('numClass must be grator than zero.');
973984

974985
$idxX = $offsetX;
975986
$idxA = $offsetA;
@@ -982,7 +993,9 @@ public function reduceGather(
982993
for($j=0;$j<$n;$j++) {
983994
$index = $X[$idxX+$j];
984995
if($index>=$numClass) {
985-
throw new RuntimeException("index is out of range.:".$index);
996+
//throw new RuntimeException("index is out of range.:".$index);
997+
$this->logging("reduceGather: index is out of range.:".$index." numClass=".$numClass);
998+
$index = $numClass-1;
986999
}
9871000
$iA = $idxA+$j+$index*$ldIndex;
9881001
$iB = $idxB+$j;

0 commit comments

Comments
 (0)