power method
List
power(
- List list, {
- dynamic element = 0,
- dynamic tensor,
})
Implementation
List power(List list, {dynamic element = 0, var tensor}) {
if (tensor == null && element == 0) {
throw new Exception(
"DartTensorException : Enter either an element or a tensor for power.");
} else {
if (tensor != null && element != 0) {
throw new Exception(
"DartTensorException : Provide one either an element or a tensor for power, not both");
} else {
List shape = getDim(list);
List flat = flatten(list);
List temp = [];
if (element != 0) {
flat = flat.map((e) => maths.pow(e, element)).toList();
temp = generate(flat, shape);
return temp;
} else {
bool flag = true;
List shape1 = getDim(tensor);
List flat1 = flatten(tensor);
if (shape.length == shape1.length) {
for (int i = 0; i < shape.length; i++) {
if (shape[i] != shape1[i]) {
flag = false;
break;
}
}
if (flag) {
for (int i = 0; i < flat.length; i++) {
temp.add(maths.pow(flat[i], flat1[i]));
}
} else {
throw new Exception(
"DartTensorException : Both Tensors should be of equal shape. Got tensor of shape $shape and $shape1.");
}
} else {
throw new Exception(
"DartTensorException : Both Tensors should be of equal shape. Got tensor of shape $shape and $shape1.");
}
temp = generate(temp, shape);
return temp;
}
}
}
}