<commit_before>package net.turtle.math.core;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

import net.turtle.math.exception.CalculationException;
import net.turtle.math.exception.DifferentDimensionsException;

public class BigVector implements FieldElement< BigVector > {

	private final List< BigRational > coordinates;

	public BigVector() {
		this.coordinates = Collections.emptyList();
	}

	public BigVector( BigRational... coordinatesToUse ) {
		this( Arrays.asList( coordinatesToUse ) , true );
	}

	public BigVector( List< BigRational > input ) {
		this( input , false );
	}

	private BigVector( List< BigRational > input , boolean trusted ) {
		if ( trusted ) {
			this.coordinates = input;
		} else {
			this.coordinates = new ArrayList< >(input);
		}
	}

	public List< BigRational > getCoordinates() {
		return Collections.unmodifiableList( this.coordinates );
	}

	@Override
	public BigVector add( BigVector augend ) throws CalculationException {
		this.checkDimensions( augend );
		final ArrayList< BigRational > coordinatesSum = new ArrayList< >( this.getDimension() );
		final Iterator< BigRational > thisCoordinatesIt = this.coordinates.iterator();
		final Iterator< BigRational > augendCoordinatesIt = augend.coordinates.iterator();
		while ( thisCoordinatesIt.hasNext() && augendCoordinatesIt.hasNext() ) {
			coordinatesSum.add( thisCoordinatesIt.next().add( augendCoordinatesIt.next() ) );
		}
		return new BigVector( coordinatesSum );
	}

	public int getDimension() {
		return this.coordinates.size();
	}

	@Override
	public BigVector subtract( BigVector subtrahend ) throws CalculationException {
		this.checkDimensions( subtrahend );
		final ArrayList< BigRational > coordinatesSum = new ArrayList< >( this.getDimension() );
		final Iterator< BigRational > thisCoordinatesIt = this.coordinates.iterator();
		final Iterator< BigRational > augendCoordinatesIt = subtrahend.coordinates.iterator();
		while ( thisCoordinatesIt.hasNext() && augendCoordinatesIt.hasNext() ) {
			coordinatesSum.add( thisCoordinatesIt.next().subtract( augendCoordinatesIt.next() ) );
		}
		return new BigVector( coordinatesSum );
	}

	@Override
	public BigVector multiply( BigVector multiplicand ) throws CalculationException {
		return null;
	}

	public BigVector multiply( BigRational multiplicand ) {
		final ArrayList< BigRational > coordinatesSum = new ArrayList< >( this.getDimension() );
		final Iterator< BigRational > thisCoordinatesIt = this.coordinates.iterator();
		while ( thisCoordinatesIt.hasNext() ) {
			coordinatesSum.add( thisCoordinatesIt.next().multiply( multiplicand ) );
		}
		return new BigVector( coordinatesSum );
	}

	@Override
	public BigVector divide( BigVector divisor ) {
		return this.multiply( divisor.inverse() );
	}

	public BigVector divide( BigRational divisor ) {
		return this.multiply( divisor.inverse() );
	}

	@Override
	public BigVector inverse() {
		final ArrayList< BigRational > resultCoordinates = new ArrayList< >( this.getDimension() );
		final Iterator< BigRational > thisCoordinatesIt = this.coordinates.iterator();
		while ( thisCoordinatesIt.hasNext() ) {
			resultCoordinates.add( thisCoordinatesIt.next().inverse() );
		}<commit_msg>BigVector small improvements.<commit_after>package net.turtle.math.core;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

import net.turtle.math.exception.CalculationException;
import net.turtle.math.exception.DifferentDimensionsException;

public class BigVector implements FieldElement< BigVector > {

	private final List< BigRational > coordinates;

	public BigVector() {
		this.coordinates = Collections.emptyList();
	}

	public BigVector( BigRational... coordinatesToUse ) {
		this( Arrays.asList( coordinatesToUse ) , true );
	}

	public BigVector( List< BigRational > input ) {
		this( input , false );
	}

	private BigVector( List< BigRational > input , boolean trusted ) {
		if ( trusted ) {
			this.coordinates = input;
		} else {
			this.coordinates = new ArrayList< >(input);
		}
	}

	public List< BigRational > getCoordinates() {
		return Collections.unmodifiableList( this.coordinates );
	}

	@Override
	public BigVector add( BigVector augend ) throws CalculationException {
		this.checkDimensions( augend );
		final ArrayList< BigRational > coordinatesSum = new ArrayList< >( this.getDimension() );
		final Iterator< BigRational > thisCoordinatesIt = this.coordinates.iterator();
		final Iterator< BigRational > augendCoordinatesIt = augend.coordinates.iterator();
		while ( thisCoordinatesIt.hasNext() && augendCoordinatesIt.hasNext() ) {
			coordinatesSum.add( thisCoordinatesIt.next().add( augendCoordinatesIt.next() ) );
		}
		assert( !( thisCoordinatesIt.hasNext() || augendCoordinatesIt.hasNext() ) );
		return new BigVector( coordinatesSum );
	}

	public int getDimension() {
		return this.coordinates.size();
	}

	@Override
	public BigVector subtract( BigVector subtrahend ) throws CalculationException {
		this.checkDimensions( subtrahend );
		final ArrayList< BigRational > coordinatesSum = new ArrayList< >( this.getDimension() );
		final Iterator< BigRational > thisCoordinatesIt = this.coordinates.iterator();
		final Iterator< BigRational > subtrahendCoordinatesIt = subtrahend.coordinates.iterator();
		while ( thisCoordinatesIt.hasNext() && subtrahendCoordinatesIt.hasNext() ) {
			coordinatesSum.add( thisCoordinatesIt.next().subtract( subtrahendCoordinatesIt.next() ) );
		}
		assert( !( thisCoordinatesIt.hasNext() || subtrahendCoordinatesIt.hasNext() ) );
		return new BigVector( coordinatesSum );
	}

	@Override
	public BigVector multiply( BigVector multiplicand ) throws CalculationException {
		return null;
	}

	public BigVector multiply( BigRational multiplicand ) {
		final ArrayList< BigRational > coordinatesSum = new ArrayList< >( this.getDimension() );
		final Iterator< BigRational > thisCoordinatesIt = this.coordinates.iterator();
		while ( thisCoordinatesIt.hasNext() ) {
			coordinatesSum.add( thisCoordinatesIt.next().multiply( multiplicand ) );
		}
		return new BigVector( coordinatesSum );
	}

	@Override
	public BigVector divide( BigVector divisor ) {
		return this.multiply( divisor.inverse() );
	}

	public BigVector divide( BigRational divisor ) {
		return this.multiply( divisor.inverse() );
	}

	/**
	 * There is no official way to inversing vector.
	 * This method just uses inversion of every coordinate.
	 * Not so usefull but...
	 */
	@Override
	public BigVector inverse() {
		final ArrayList< BigRational > resultCoordinates = new ArrayList< >( this.getDimension() );
		final Iterator< BigRational > thisCoordinatesIt = this.coordinates.iterator();
		while ( thisCoordinatesIt.hasNext() ) {
			resultCoordinates.add( thisCoordinatesIt.next().inverse() );
		}
{'fraction_non_alphanumeric': 0.10925468545692285, 'fraction_numerical': 0.0, 'mean_word_length': 4.939603106125971, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 43, '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': '6339144', 'n_tokens_mistral': 2156, 'n_tokens_neox': 2000, 'n_words': 472}