<commit_before>// Copyright (c) 2015, <NAME>. All rights reserved. Use of this source code
// is governed by a BSD-style license that can be found in the LICENSE file.

library Vector.V;

import 'dart:math';
import 'M.dart';

/// Vector with n elements
class V<T>{
  static final Random random = new Random();
  List<T> list;

  // Trying to keep vectors strongly typed.
  // Generic vectors have _generic = true
  // try and keep these all the same type by controlling assignments
  bool _generic = false;
  int _genericSet = -1; // Set this to the index of the first assignment. This feels like a bit of a hack.

  //------------//
  // Properties //
  //------------//

  List<T> get Elements => list;

  int get length => list.length;

  double get Magnitude => sqrt(list.map((e) => e * e).fold(0.0, (p, n) => p + n));

  //--------------//
  // Constructors //
  //--------------//

  V(List<T> vals){
    list = vals;
  }

  V.All(int size, T val){
    list = new List<T>.filled(size, val);
  }

  V.Zero(int size):this.All(size, 0.0 as T);

  V.One(int size):this.All(size, 1.0 as T);

  V.Random(int size){
    list = new List<T>();
    for(int i = 0; i<size; i++){
      list.add(random.nextDouble() as T);
    }
  }

  V.Generic(int _length){
    _generic = true;
    list = new List(_length);
  }
  
  //---------//
  // Methods //
  //---------//

  V Zip(V v, Function f){
    if(this.length != v.length) throw("Vectors have different lengths: [${this.length}], [${v.length}].");<commit_msg>Default constructor checks that input is list (omg!!)<commit_after>// Copyright (c) 2015, <NAME>. All rights reserved. Use of this source code
// is governed by a BSD-style license that can be found in the LICENSE file.

library Vector.V;

import 'dart:math';
import 'M.dart';

/// Vector with n elements
class V<T>{
  static final Random random = new Random();
  List<T> list;

  // Trying to keep vectors strongly typed.
  // Generic vectors have _generic = true
  // try and keep these all the same type by controlling assignments
  bool _generic = false;
  int _genericSet = -1; // Set this to the index of the first assignment. This feels like a bit of a hack.

  //------------//
  // Properties //
  //------------//

  List<T> get Elements => list;

  int get length => list.length;

  double get Magnitude => sqrt(list.map((e) => e * e).fold(0.0, (p, n) => p + n));

  //--------------//
  // Constructors //
  //--------------//

  V(List<T> vals){
    if(vals is! List) throw new Exception('Vector input must be a List');
    list = vals;
  }

  V.All(int size, T val){
    list = new List<T>.filled(size, val);
  }

  V.Zero(int size):this.All(size, 0.0 as T);

  V.One(int size):this.All(size, 1.0 as T);

  V.Random(int size){
    list = new List<T>();
    for(int i = 0; i<size; i++){
      list.add(random.nextDouble() as T);
    }
  }

  V.Generic(int _length){
    _generic = true;
    list = new List(_length);
  }
  
  //---------//
  // Methods //
  //---------//

  V Zip(V v, Function f){
    if(this.length != v.length) throw("Vectors have different lengths: [${this.length}], [${v.length}].");
{'fraction_non_alphanumeric': 0.19987187700192185, 'fraction_numerical': 0.007687379884689302, 'mean_word_length': 2.196519959058342, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5725036', 'n_tokens_mistral': 1080, 'n_tokens_neox': 1028, 'n_words': 353}