@@ -1142,20 +1142,37 @@ VALUE nm_eqeq(VALUE self, VALUE another){
11421142 Data_Get_Struct (self , nmatrix , left );
11431143 Data_Get_Struct (another , nmatrix , right );
11441144
1145- switch (right -> dtype ) {
1146- case nm_float64 : {
1147- double * left_elements = (double * )left -> elements ;
1148- double * right_elements = (double * )right -> elements ;
1145+ if (left -> count != right -> count ){
1146+ return Qfalse ;
1147+ }
1148+
1149+ switch (right -> dtype ) {
1150+ case nm_bool :
1151+ {
1152+ bool * left_elements = (bool * )left -> elements ;
1153+ bool * right_elements = (bool * )right -> elements ;
11491154
11501155 for (size_t index = 0 ; index < left -> count ; index ++ ){
1151- if (fabs ( left_elements [index ] - right_elements [index ]) > 1e-3 ){
1156+ if (left_elements [index ] != right_elements [index ]){
11521157 return Qfalse ;
11531158 }
11541159 }
11551160 break ;
11561161 }
1162+ case nm_int :
1163+ {
1164+ int * left_elements = (int * )left -> elements ;
1165+ int * right_elements = (int * )right -> elements ;
11571166
1158- case nm_float32 : {
1167+ for (size_t index = 0 ; index < left -> count ; index ++ ){
1168+ if (left_elements [index ] != right_elements [index ]){
1169+ return Qfalse ;
1170+ }
1171+ }
1172+ break ;
1173+ }
1174+ case nm_float32 :
1175+ {
11591176 float * left_elements = (float * )left -> elements ;
11601177 float * right_elements = (float * )right -> elements ;
11611178
@@ -1166,6 +1183,42 @@ VALUE nm_eqeq(VALUE self, VALUE another){
11661183 }
11671184 break ;
11681185 }
1186+ case nm_float64 :
1187+ {
1188+ double * left_elements = (double * )left -> elements ;
1189+ double * right_elements = (double * )right -> elements ;
1190+
1191+ for (size_t index = 0 ; index < left -> count ; index ++ ){
1192+ if (fabs (left_elements [index ] - right_elements [index ]) > 1e-3 ){
1193+ return Qfalse ;
1194+ }
1195+ }
1196+ break ;
1197+ }
1198+ case nm_complex32 :
1199+ {
1200+ float complex * left_elements = (float complex * )left -> elements ;
1201+ float complex * right_elements = (float complex * )right -> elements ;
1202+
1203+ for (size_t index = 0 ; index < left -> count ; index ++ ){
1204+ if (cabs (left_elements [index ] - right_elements [index ]) > 1e-3 ){
1205+ return Qfalse ;
1206+ }
1207+ }
1208+ break ;
1209+ }
1210+ case nm_complex64 :
1211+ {
1212+ double complex * left_elements = (double complex * )left -> elements ;
1213+ double complex * right_elements = (double complex * )right -> elements ;
1214+
1215+ for (size_t index = 0 ; index < left -> count ; index ++ ){
1216+ if (cabs (left_elements [index ] - right_elements [index ]) > 1e-3 ){
1217+ return Qfalse ;
1218+ }
1219+ }
1220+ break ;
1221+ }
11691222 }
11701223
11711224 return Qtrue ;
@@ -1174,7 +1227,7 @@ VALUE nm_eqeq(VALUE self, VALUE another){
11741227/*
11751228 * Greater operator.
11761229 * Returns a single true or false value indicating whether
1177- * the element in a matrix is greater or smaller
1230+ * the element in a matrix is greater or smaller than given value
11781231 *
11791232 */
11801233VALUE nm_gt (VALUE self , VALUE another ){
@@ -1194,6 +1247,33 @@ VALUE nm_gt(VALUE self, VALUE another){
11941247 bool * result_elements = ALLOC_N (bool , result -> shape [0 ] * result -> shape [1 ]);
11951248
11961249 switch (left -> dtype ) {
1250+ case nm_bool : {
1251+ double rha = NUM2DBL (another );
1252+ bool * left_elements = (bool * )left -> elements ;
1253+
1254+ for (size_t index = 0 ; index < left -> count ; index ++ ){
1255+ result_elements [index ] = (((double )left_elements [index ] > rha ) ? true : false);
1256+ }
1257+ break ;
1258+ }
1259+ case nm_int : {
1260+ double rha = NUM2DBL (another );
1261+ int * left_elements = (int * )left -> elements ;
1262+
1263+ for (size_t index = 0 ; index < left -> count ; index ++ ){
1264+ result_elements [index ] = (((double )left_elements [index ] > rha ) ? true : false);
1265+ }
1266+ break ;
1267+ }
1268+ case nm_float32 : {
1269+ double rha = NUM2DBL (another );
1270+ float * left_elements = (float * )left -> elements ;
1271+
1272+ for (size_t index = 0 ; index < left -> count ; index ++ ){
1273+ result_elements [index ] = (((double )left_elements [index ] > rha ) ? true : false);
1274+ }
1275+ break ;
1276+ }
11971277 case nm_float64 : {
11981278 double rha = NUM2DBL (another );
11991279 double * left_elements = (double * )left -> elements ;
@@ -1203,6 +1283,26 @@ VALUE nm_gt(VALUE self, VALUE another){
12031283 }
12041284 break ;
12051285 }
1286+ case nm_complex32 : {
1287+ rb_raise (rb_eSyntaxError , "SyntaxError: nm_complex32 does not support this operator." );
1288+ // float complex rha = CMPLXF(NUM2DBL(rb_funcall(another, rb_intern("real"), 0, Qnil)), NUM2DBL(rb_funcall(another, rb_intern("imaginary"), 0, Qnil)));;
1289+ // float complex* left_elements = (float complex*)left->elements;
1290+
1291+ // for(size_t index = 0; index < left->count; index++){
1292+ // result_elements[index] = ((left_elements[index] > rha) ? true : false);
1293+ // }
1294+ break ;
1295+ }
1296+ case nm_complex64 : {
1297+ rb_raise (rb_eSyntaxError , "SyntaxError: nm_complex64 does not support this operator." );
1298+ // double complex rha = CMPLXF(NUM2DBL(rb_funcall(another, rb_intern("real"), 0, Qnil)), NUM2DBL(rb_funcall(another, rb_intern("imaginary"), 0, Qnil)));
1299+ // double complex* left_elements = (double complex*)left->elements;
1300+
1301+ // for(size_t index = 0; index < left->count; index++){
1302+ // result_elements[index] = ((left_elements[index] > rha) ? true : false);
1303+ // }
1304+ break ;
1305+ }
12061306 }
12071307 result -> elements = result_elements ;
12081308 return Data_Wrap_Struct (NMatrix , NULL , nm_free , result );
@@ -1231,6 +1331,33 @@ VALUE nm_gteq(VALUE self, VALUE another){
12311331 bool * result_elements = ALLOC_N (bool , result -> shape [0 ] * result -> shape [1 ]);
12321332
12331333 switch (left -> dtype ) {
1334+ case nm_bool : {
1335+ double rha = NUM2DBL (another );
1336+ bool * left_elements = (bool * )left -> elements ;
1337+
1338+ for (size_t index = 0 ; index < left -> count ; index ++ ){
1339+ result_elements [index ] = (((double )left_elements [index ] >= rha ) ? true : false);
1340+ }
1341+ break ;
1342+ }
1343+ case nm_int : {
1344+ double rha = NUM2DBL (another );
1345+ int * left_elements = (int * )left -> elements ;
1346+
1347+ for (size_t index = 0 ; index < left -> count ; index ++ ){
1348+ result_elements [index ] = (((double )left_elements [index ] >= rha ) ? true : false);
1349+ }
1350+ break ;
1351+ }
1352+ case nm_float32 : {
1353+ double rha = NUM2DBL (another );
1354+ float * left_elements = (float * )left -> elements ;
1355+
1356+ for (size_t index = 0 ; index < left -> count ; index ++ ){
1357+ result_elements [index ] = (((double )left_elements [index ] >= rha ) ? true : false);
1358+ }
1359+ break ;
1360+ }
12341361 case nm_float64 : {
12351362 double rha = NUM2DBL (another );
12361363 double * left_elements = (double * )left -> elements ;
@@ -1240,6 +1367,26 @@ VALUE nm_gteq(VALUE self, VALUE another){
12401367 }
12411368 break ;
12421369 }
1370+ case nm_complex32 : {
1371+ rb_raise (rb_eSyntaxError , "SyntaxError: nm_complex32 does not support this operator." );
1372+ // float complex rha = CMPLXF(NUM2DBL(rb_funcall(another, rb_intern("real"), 0, Qnil)), NUM2DBL(rb_funcall(another, rb_intern("imaginary"), 0, Qnil)));;
1373+ // float complex* left_elements = (float complex*)left->elements;
1374+
1375+ // for(size_t index = 0; index < left->count; index++){
1376+ // result_elements[index] = ((left_elements[index] >= rha) ? true : false);
1377+ // }
1378+ break ;
1379+ }
1380+ case nm_complex64 : {
1381+ rb_raise (rb_eSyntaxError , "SyntaxError: nm_complex64 does not support this operator." );
1382+ // double complex rha = CMPLXF(NUM2DBL(rb_funcall(another, rb_intern("real"), 0, Qnil)), NUM2DBL(rb_funcall(another, rb_intern("imaginary"), 0, Qnil)));
1383+ // double complex* left_elements = (double complex*)left->elements;
1384+
1385+ // for(size_t index = 0; index < left->count; index++){
1386+ // result_elements[index] = ((left_elements[index] >= rha) ? true : false);
1387+ // }
1388+ break ;
1389+ }
12431390 }
12441391 result -> elements = result_elements ;
12451392 return Data_Wrap_Struct (NMatrix , NULL , nm_free , result );
@@ -1268,6 +1415,33 @@ VALUE nm_lt(VALUE self, VALUE another){
12681415 bool * result_elements = ALLOC_N (bool , result -> shape [0 ] * result -> shape [1 ]);
12691416
12701417 switch (left -> dtype ) {
1418+ case nm_bool : {
1419+ double rha = NUM2DBL (another );
1420+ bool * left_elements = (bool * )left -> elements ;
1421+
1422+ for (size_t index = 0 ; index < left -> count ; index ++ ){
1423+ result_elements [index ] = (((double )left_elements [index ] < rha ) ? true : false);
1424+ }
1425+ break ;
1426+ }
1427+ case nm_int : {
1428+ double rha = NUM2DBL (another );
1429+ int * left_elements = (int * )left -> elements ;
1430+
1431+ for (size_t index = 0 ; index < left -> count ; index ++ ){
1432+ result_elements [index ] = (((double )left_elements [index ] < rha ) ? true : false);
1433+ }
1434+ break ;
1435+ }
1436+ case nm_float32 : {
1437+ double rha = NUM2DBL (another );
1438+ float * left_elements = (float * )left -> elements ;
1439+
1440+ for (size_t index = 0 ; index < left -> count ; index ++ ){
1441+ result_elements [index ] = (((double )left_elements [index ] < rha ) ? true : false);
1442+ }
1443+ break ;
1444+ }
12711445 case nm_float64 : {
12721446 double rha = NUM2DBL (another );
12731447 double * left_elements = (double * )left -> elements ;
@@ -1277,6 +1451,26 @@ VALUE nm_lt(VALUE self, VALUE another){
12771451 }
12781452 break ;
12791453 }
1454+ case nm_complex32 : {
1455+ rb_raise (rb_eSyntaxError , "SyntaxError: nm_complex32 does not support this operator." );
1456+ // float complex rha = CMPLXF(NUM2DBL(rb_funcall(another, rb_intern("real"), 0, Qnil)), NUM2DBL(rb_funcall(another, rb_intern("imaginary"), 0, Qnil)));;
1457+ // float complex* left_elements = (float complex*)left->elements;
1458+
1459+ // for(size_t index = 0; index < left->count; index++){
1460+ // result_elements[index] = ((left_elements[index] < rha) ? true : false);
1461+ // }
1462+ break ;
1463+ }
1464+ case nm_complex64 : {
1465+ rb_raise (rb_eSyntaxError , "SyntaxError: nm_complex64 does not support this operator." );
1466+ // double complex rha = CMPLXF(NUM2DBL(rb_funcall(another, rb_intern("real"), 0, Qnil)), NUM2DBL(rb_funcall(another, rb_intern("imaginary"), 0, Qnil)));
1467+ // double complex* left_elements = (double complex*)left->elements;
1468+
1469+ // for(size_t index = 0; index < left->count; index++){
1470+ // result_elements[index] = ((left_elements[index] < rha) ? true : false);
1471+ // }
1472+ break ;
1473+ }
12801474 }
12811475 result -> elements = result_elements ;
12821476 return Data_Wrap_Struct (NMatrix , NULL , nm_free , result );
@@ -1306,6 +1500,33 @@ VALUE nm_lteq(VALUE self, VALUE another){
13061500 bool * result_elements = ALLOC_N (bool , result -> shape [0 ] * result -> shape [1 ]);
13071501
13081502 switch (left -> dtype ) {
1503+ case nm_bool : {
1504+ double rha = NUM2DBL (another );
1505+ bool * left_elements = (bool * )left -> elements ;
1506+
1507+ for (size_t index = 0 ; index < left -> count ; index ++ ){
1508+ result_elements [index ] = (((double )left_elements [index ] <= rha ) ? true : false);
1509+ }
1510+ break ;
1511+ }
1512+ case nm_int : {
1513+ double rha = NUM2DBL (another );
1514+ int * left_elements = (int * )left -> elements ;
1515+
1516+ for (size_t index = 0 ; index < left -> count ; index ++ ){
1517+ result_elements [index ] = (((double )left_elements [index ] <= rha ) ? true : false);
1518+ }
1519+ break ;
1520+ }
1521+ case nm_float32 : {
1522+ double rha = NUM2DBL (another );
1523+ float * left_elements = (float * )left -> elements ;
1524+
1525+ for (size_t index = 0 ; index < left -> count ; index ++ ){
1526+ result_elements [index ] = (((double )left_elements [index ] <= rha ) ? true : false);
1527+ }
1528+ break ;
1529+ }
13091530 case nm_float64 : {
13101531 double rha = NUM2DBL (another );
13111532 double * left_elements = (double * )left -> elements ;
@@ -1315,6 +1536,26 @@ VALUE nm_lteq(VALUE self, VALUE another){
13151536 }
13161537 break ;
13171538 }
1539+ case nm_complex32 : {
1540+ rb_raise (rb_eSyntaxError , "SyntaxError: nm_complex32 does not support this operator." );
1541+ // float complex rha = CMPLXF(NUM2DBL(rb_funcall(another, rb_intern("real"), 0, Qnil)), NUM2DBL(rb_funcall(another, rb_intern("imaginary"), 0, Qnil)));;
1542+ // float complex* left_elements = (float complex*)left->elements;
1543+
1544+ // for(size_t index = 0; index < left->count; index++){
1545+ // result_elements[index] = ((left_elements[index] <= rha) ? true : false);
1546+ // }
1547+ break ;
1548+ }
1549+ case nm_complex64 : {
1550+ rb_raise (rb_eSyntaxError , "SyntaxError: nm_complex64 does not support this operator." );
1551+ // double complex rha = CMPLXF(NUM2DBL(rb_funcall(another, rb_intern("real"), 0, Qnil)), NUM2DBL(rb_funcall(another, rb_intern("imaginary"), 0, Qnil)));
1552+ // double complex* left_elements = (double complex*)left->elements;
1553+
1554+ // for(size_t index = 0; index < left->count; index++){
1555+ // result_elements[index] = ((left_elements[index] <= rha) ? true : false);
1556+ // }
1557+ break ;
1558+ }
13181559 }
13191560 result -> elements = result_elements ;
13201561 return Data_Wrap_Struct (NMatrix , NULL , nm_free , result );
0 commit comments