搜尋套件、儲存庫與 APP 分類

套件詳情v0.15.2

data

一個時間與空間效率高的資料結構和演算法集合,用於處理 Dart 中的資料。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
1.6萬
喜歡數
22
Pub 分數
160

安裝套件

flutter pub add data

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

該資料套件為 Dart 提供高效、輕量級的資料結構與演算法,針對時間與空間進行最佳化。提供陣列、集合與映射等集合類型,具備增強的效能特性,並附帶常用運算任務的實用函數。專為數學與演算法運作設計,支援所有主要平台(包括 Android、iOS、Web、macOS、Windows 與 Linux)的無縫整合。非常適合需要高效率資料處理,卻又不希望有大型框架開銷的應用程式。

適用情境

  • 演算法實作
  • 高效能資料處理
  • 數學計算
  • 跨平台資料操作
  • 應用中的高效記憶體使用

主要特色

  • 針對時間和空間效率進行優化
  • 輕量級集合實作
  • 支援多個平台
  • 內建演算法工具
  • 最小依賴

適合對象

  • 需要快速資料操作的開發者
  • 資料負載較重的應用程式
  • 跨平台專案
  • 效能敏感的 Dart 程式碼
  • 計算密集型應用

使用建議

  • 不是對內建 Dart 集合的完整取代
  • 最適合特定演算法需求
  • 可能需要學習新的 API 模式
  • 僅限核心資料結構
  • 不適用於使用者介面或狀態管理

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

Dart Data

Pub Package Build Status Code Coverage GitHub Issues GitHub Forks GitHub Stars GitHub License

Dart Data is a fast and space efficient library to deal with data in Dart, Flutter and the web. As of today this mostly includes data structures and algorithms for vectors and matrices, but at some point might also include graphs and other mathematical structures.

This library is open source, stable and well tested. Development happens on GitHub. Feel free to report issues or create a pull-request there. General questions are best asked on StackOverflow.

The package is hosted on dart packages. Up-to-date class documentation is created with every release.

Tutorial

Below are step-by-step instructions of how to use this library. More elaborate examples are included with the examples.

Installation

Follow the installation instructions on dart packages.

Import the core-package into your Dart code using:

import 'dart:math';

import 'package:data/data.dart';
import 'package:more/printer.dart';
How to solve a linear equation?

Solve 'A * x = b', where 'A' is a matrix and 'b' a vector:

final a = Matrix<double>.fromRows(DataType.float64, [
  [2, 1, 1],
  [1, 3, 2],
  [1, 0, 0],
]);
final b = Vector<double>.fromList(DataType.float64, [4, 5, 6]);
final x = a.solve(b.columnMatrix).column(0);
print(x.format(valuePrinter: FixedNumberPrinter())); // prints '6 15 -23'
How to find the eigenvalues of a matrix?

Find the eigenvalues of a matrix 'A':

final a = Matrix<double>.fromRows(DataType.float64, [
  [1, 0, 0, -1],
  [0, -1, 0, 0],
  [0, 0, 1, -1],
  [-1, 0, -1, 0],
]);
final decomposition = a.eigenvalue;
final eigenvalues = Vector<double>.fromList(
    DataType.float64, decomposition.realEigenvalues);
print(eigenvalues.format(valuePrinter: FixedNumberPrinter(precision: 1))); // prints '-1.0 -1.0 1.0 2.0'
How to find all the roots of a polynomial?

To find the roots of x^5 + -8x^4 + -72x^3 + 242x^2 + 1847x + 2310:

final polynomial = Polynomial.fromCoefficients(DataType.int32, [1, -8, -72, 242, 1847, 2310]);
final roots = polynomial.roots;
print(roots.map((root) => root.real)); // [-5, -3, -2, 7, 11]
print(roots.map((root) => root.imaginary)); // [0, 0, 0, 0, 0]
How to do a polynomial regression?

To find the best fitting third degree polynomial through a list of points:

final height = [1.47, 1.50, 1.52, 1.55, 1.57, 1.60, 1.63, 1.65, 1.68, 1.70, 1.73, 1.75, 1.78, 1.80, 1.83].toVector();
final mass = [52.21, 53.12, 54.48, 55.84, 57.20, 58.57, 59.93, 61.29, 63.11, 64.47, 66.28, 68.10, 69.92, 72.19, 74.46].toVector();
final fitter = PolynomialRegression(degree: 2);
final result = fitter.fit(xs: height, ys: mass);
print(result.polynomial.format(valuePrinter: FixedNumberPrinter(precision: 3))); // 61.960x^2 + -143.162x + 128.813
How to numerically integrate a function?

In both examples we specify a custom depth, since these integrals are tricky at the upper bound (very steep for the first one, very flat for the second one).

// Compute the area of a circle by iterating over a quarter circle:
final pi = 4 * integrate((x) => sqrt(1 - x * x), 0, 1, depth: 30);
print(pi); // 3.1415925673846368 ~ pi

// Compute an improper integral:
final one = integrate((x) => exp(-x), 0, double.infinity, depth: 30);
print(one); // 1.0000000904304227 ~ 1

Misc

Demos

This package includes a sandbox web dashboard in web/distributions to visualize, configure, and dynamically sample the supported continuous and discrete probability distributions in real-time.

To compile, serve, and explore the interactive distributions demo run:

dart pub global activate webdev
webdev serve --release

Then open http://localhost:8080/distributions/index.html in your web browser.

License

The MIT License, see LICENSE.

Some of the matrix decomposition algorithms are a port of the JAMA: A Java Matrix Package released under public domain.

  • In particular, the singular value decomposition algorithm comes from the Math.Net Numerics released under MIT.

Some of the distributions and special functions are a port of the JavaScript Statistical Library released under MIT.

The Levenberg-Marquardt least squares curve fitting is a port of levenberg-marquardt released under MIT.

所屬分類

依賴

依賴清單 3 項

原始碼儲存庫

使用此套件的專案