Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/Traits/CreatesArrays.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,20 @@ public static function full(bool|Complex|float|int $value, array $shape, ?DType
public static function fromArray(array $data, ?array $shape = null, ?DType $dtype = null): self
{
$shape ??= self::inferShape($data);
$flatData = self::flattenArray($data);

if (empty($flatData)) {
throw new ShapeException('Cannot create array from empty data');
}

$dtype ??= DType::fromArray($data);

return self::array($data, $dtype);
$lib = Lib::get();
$len = \count($flatData);

$handle = self::createTyped($lib, $dtype, $flatData, $shape, $len);

return new self($handle, new ArrayMetadata($shape), $dtype);
}

/**
Expand Down
Loading