public static unsafe NDArray <bool> operator !(NDArray self) { var result = new NDArray(typeof(bool), self.shape); switch (self.GetTypeCode) { #if _REGEN1 case NPTypeCode.Boolean: { var from = (bool *)self.Address; var to = (bool *)result.Address; var len = result.size; for (int i = 0; i < len; i++) { *(to + i) = !*(from + i); //if val is 0 then write true } return(result.MakeGeneric <bool>()); } % foreach except(supported_dtypes, "Boolean"), except(supported_dtypes_lowercase, "bool") % case NPTypeCode.#1: { var from = (#2 *)self.Address; var to = (bool *)result.Address; var len = result.size; for (int i = 0; i < len; i++) { *(to + i) = *(from + i) == 0; //if val is 0 then write true } return(result.MakeGeneric <bool>()); }
/// NumPy signature: numpy.equal(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj]) = <ufunc 'equal'> /// <summary> /// Compare two NDArrays element wise /// </summary> /// <param name="np2">NDArray to compare with</param> /// <returns>NDArray with result of each element compare</returns> private NDArray <bool> equal(NDArray np2) { if (this.size != np2.size) { throw new ArgumentException("Different sized NDArray's in not yet supported by the equal operation", nameof(np2)); } var boolTensor = new NDArray(typeof(bool), this.shape); bool[] bools = boolTensor.Storage.GetData() as bool[]; var values1 = this.Storage.GetData(); var values2 = np2.Storage.GetData(); for (int idx = 0; idx < bools.Length; idx++) { var v1 = values1.GetValue(idx); var v2 = values2.GetValue(idx); if (v1.Equals(v2)) { bools[idx] = true; } } return(boolTensor.MakeGeneric <bool>()); }
public static NDArray <bool> operator !(NDArray np_) { var boolTensor = new NDArray(typeof(bool), np_.shape); bool[] bools = boolTensor.Storage.GetData <bool>(); bool[] np = np_.Storage.GetData <bool>(); for (int i = 0; i < bools.Length; i++) { bools[i] = !np[i]; } return(boolTensor.MakeGeneric <bool>()); }
public static NDArray <byte> operator &(NDArray lhs, byte rhs) { var result = new NDArray(typeof(byte), lhs.shape); byte[] resultBytes = result.Storage.GetData <byte>(); byte[] lhsValues = lhs.Storage.GetData <byte>(); for (int i = 0; i < resultBytes.Length; i++) { resultBytes[i] = (byte)(lhsValues[i] & rhs); } return(result.MakeGeneric <byte>()); }
public static NDArray <byte> operator &(NDArray np_, byte value) { var byteTensor = new NDArray(typeof(byte), np_.shape); byte[] bytes = byteTensor.Storage.GetData <byte>(); byte[] np = np_.Storage.GetData <byte>(); for (int i = 0; i < bytes.Length; i++) { bytes[i] = (byte)(np[i] & value); } return(byteTensor.MakeGeneric <byte>()); }
public static NDArray <bool> operator &(NDArray lhs, NDArray rhs) { var boolTensor = new NDArray(typeof(bool), lhs.shape); bool[] bools = boolTensor.Storage.GetData <bool>(); bool[] np = lhs.Storage.GetData <bool>(); bool[] obj = rhs.Storage.GetData <bool>(); for (int i = 0; i < bools.Length; i++) { bools[i] = np[i] && obj[i]; } return(boolTensor.MakeGeneric <bool>()); }
public static NumSharp.Generic.NDArray <bool> operator |(NDArray np_, NDArray obj_) { var boolTensor = new NDArray(typeof(bool), np_.shape); bool[] bools = boolTensor.Storage.GetData() as bool[]; bool[] np = np_.MakeGeneric <bool>().Storage.GetData() as bool[]; bool[] obj = obj_.MakeGeneric <bool>().Storage.GetData() as bool[]; for (int idx = 0; idx < bools.Length; idx++) { bools[idx] = np[idx] || obj[idx]; } return(boolTensor.MakeGeneric <bool>()); }
public static NDArray <bool> operator ==(NDArray np, object obj) { var boolTensor = new NDArray(typeof(bool), np.shape); bool[] bools = boolTensor.Storage.GetData() as bool[]; switch (np.Storage.GetData()) { case int[] values: { int value = Convert.ToInt32(obj); for (int idx = 0; idx < bools.Length; idx++) { if (values[idx] == value) { bools[idx] = true; } } break; } case Int64[] values: { Int64 value = Convert.ToInt64(obj); for (int idx = 0; idx < bools.Length; idx++) { if (values[idx] == value) { bools[idx] = true; } } break; } case float[] values: { float value = Convert.ToSingle(obj); for (int idx = 0; idx < bools.Length; idx++) { if (values[idx] == value) { bools[idx] = true; } } break; } case double[] values: { double value = Convert.ToDouble(obj); for (int idx = 0; idx < bools.Length; idx++) { if (values[idx] == value) { bools[idx] = true; } } break; } case Complex[] values: { Complex value = (Complex)obj; for (int idx = 0; idx < bools.Length; idx++) { if (values[idx] == value) { bools[idx] = true; } } break; } /*case Quaternion[] values : * { * Quaternion value = (Quaternion) obj; * for(int idx =0; idx < bools.Length;idx++) * { * if ( values[idx] == value ) * bools[idx] = true; * } * break; * }*/ default: { throw new IncorrectTypeException(); } } return(boolTensor.MakeGeneric <bool>()); }
public static NumSharp.Generic.NDArray <bool> operator >(NDArray np, object obj) { var boolTensor = new NDArray(typeof(bool), np.shape); var bools = boolTensor.Storage.GetData(); var npValues = np.Storage.GetData(); switch (npValues.TypeCode) { case NPTypeCode.Int32: { int value = Converts.ToInt32(obj); int idx = 0; foreach (var npValue in npValues) { if ((int)npValue > value) { bools[idx] = true; } idx++; } break; } case NPTypeCode.Int64: { long value = Converts.ToInt64(obj); int idx = 0; foreach (var npValue in npValues) { if ((long)npValue > value) { bools[idx] = true; } idx++; } break; } case NPTypeCode.Float: { float value = Converts.ToSingle(obj); int idx = 0; foreach (var npValue in npValues) { if ((float)npValue > value) { bools[idx] = true; } idx++; } break; } case NPTypeCode.Double: { double value = Converts.ToDouble(obj); int idx = 0; foreach (var npValue in npValues) { if ((double)npValue > value) { bools[idx] = true; } idx++; } break; } default: { throw new IncorrectTypeException(); } } return(boolTensor.MakeGeneric <bool>()); }
public static NumSharp.Generic.NDArray <bool> operator !=(NDArray np, object obj) { var boolTensor = new NDArray(typeof(bool), np.shape); var bools = boolTensor.Storage.GetData(); var npValues = np.Storage.GetData(); switch (npValues.TypeCode) { case NPTypeCode.Int32: { int value = Converts.ToInt32(obj); int idx = 0; foreach (var npValue in npValues) { if ((int)npValue != value) { bools[idx] = true; } idx++; } break; } case NPTypeCode.Int64: { long value = Converts.ToInt64(obj); int idx = 0; foreach (var npValue in npValues) { if ((long)npValue != value) { bools[idx] = true; } idx++; } break; } case NPTypeCode.Float: { float value = Converts.ToSingle(obj); int idx = 0; foreach (var npValue in npValues) { if ((float)npValue != value) { bools[idx] = true; } idx++; } break; } case NPTypeCode.Double: { double value = Converts.ToDouble(obj); int idx = 0; foreach (var npValue in npValues) { if ((double)npValue != value) { bools[idx] = true; } idx++; } break; } /*case Complex[] values : * { * Complex value = (Complex) obj; * for(int idx =0; idx < bools.Length;idx++) * { * if ( values[idx] != value ) * bools[idx] = true; * } * break; * }*/ /*case Quaternion[] values : * { * Quaternion value = (Quaternion) obj; * for(int idx =0; idx < bools.Length;idx++) * { * if ( values[idx] != value ) * bools[idx] = true; * } * break; * }*/ default: { throw new IncorrectTypeException(); } } return(boolTensor.MakeGeneric <bool>()); }
public static NumSharp.Generic.NDArray <bool> operator >(NDArray np, object obj) { var boolTensor = new NDArray(typeof(bool), np.shape); bool[] bools = boolTensor.Storage.GetData() as bool[]; switch (np.Storage.GetData()) { case int[] values: { int value = Convert.ToInt32(obj); for (int idx = 0; idx < bools.Length; idx++) { if (values[idx] > value) { bools[idx] = true; } } break; } case Int64[] values: { Int64 value = Convert.ToInt64(obj); for (int idx = 0; idx < bools.Length; idx++) { if (values[idx] > value) { bools[idx] = true; } } break; } case float[] values: { float value = Convert.ToSingle(obj); for (int idx = 0; idx < bools.Length; idx++) { if (values[idx] > value) { bools[idx] = true; } } break; } case double[] values: { double value = Convert.ToDouble(obj); for (int idx = 0; idx < bools.Length; idx++) { if (values[idx] > value) { bools[idx] = true; } } break; } default: { throw new IncorrectTypeException(); } } return(boolTensor.MakeGeneric <bool>()); }