GPUTensor<T> constructor

GPUTensor<T>(
  1. dynamic initialValue, {
  2. GPUNode? creator,
})

Implementation

GPUTensor(dynamic initialValue, {this.creator}) : id = _generateId() {
  // 1. Determine Shape
  if (initialValue is double) {
    shape = [];
  } else if (initialValue is List<double>) {
    shape = [initialValue.length];
  } else if (initialValue is List<List<double>>) {
    int rows = initialValue.length;
    int cols = rows > 0 ? initialValue[0].length : 0;
    shape = [rows, cols];
  } else if (initialValue is List<List<List<double>>>) {
    int depth = initialValue.length;
    int height = depth > 0 ? initialValue[0].length : 0;
    int width = height > 0 ? initialValue[0][0].length : 0;
    shape = [depth, height, width];
  } else {
    throw Exception("Unsupported GPUTensor initialization type: ${initialValue.runtimeType}");
  }

  // 2. Allocate VRAM
  _allocateEmptyInVram();

  // 3. Push Initial Data if provided
  _pushInitialValue(initialValue);
}