Vectors 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 057b69577336c488e83124f9e964953a840a2f5ef0ffca66b6679f6fa3fbdf71
4
+ data.tar.gz: 07d6e65221184002e719f666f94362b9b853bf20e7f81863bd3841d01435a32f
5
+ SHA512:
6
+ metadata.gz: a36c6f8929dfa96ab6e87a751d464f1da3aba572f523cbc906c0c3019af98f3ca5958495a1129ffe4737e3fa06da0439ace9be1c34c76338a97b2c2682c31b88
7
+ data.tar.gz: 778bc0502f69da94e5a32749af1c3d9eda550dd8bb10989162ca17f0f26709302291884b743aafee2ca4bae1d267c9dfefb639818a491141d6c2ffba038fdfd0
data/.rubocop.yml ADDED
@@ -0,0 +1,8 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.1
3
+
4
+ Style/StringLiterals:
5
+ EnforcedStyle: double_quotes
6
+
7
+ Style/StringLiteralsInInterpolation:
8
+ EnforcedStyle: double_quotes
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 inaidE
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,66 @@
1
+ # Vectors
2
+
3
+ Vectors is a Ruby gem that provides essential functions for vector arithmetic and geometric computations. It includes methods for calculating determinants, scalar products, and cross products, making it a handy tool for projects that require linear algebra operations.
4
+
5
+ ## Installation
6
+ Installation via Git:
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'Vectors', git: 'https://github.com/inaidE/projectAVOCADOS'
11
+ ```
12
+ Then run:
13
+ bundle install
14
+
15
+ Installation via RubyGems:
16
+ Install the gem and add to the application's Gemfile by executing:
17
+
18
+ ```bash
19
+ bundle add Vectors
20
+ ```
21
+
22
+ If bundler is not being used to manage dependencies, install the gem by executing:
23
+
24
+ ```bash
25
+ gem install Vectors
26
+ ```
27
+
28
+ ## Usage
29
+
30
+ Determinant Calculation
31
+
32
+ matrix = [
33
+ [1, 2],
34
+ [3, 4]
35
+ ]
36
+ result = Vectors.Determinant(matrix)
37
+ puts result # Output: -2
38
+
39
+ Scalar Product
40
+
41
+ a = [1, 2, 3]
42
+ b = [4, 5, 6]
43
+ result = Vectors.scalar_prod(a, b)
44
+ puts result # Output: 32
45
+
46
+ Cross Product
47
+
48
+ a = [1, 2, 3]
49
+ b = [4, 5, 6]
50
+ result = Vectors.cross_prod(a, b)
51
+ puts result.inspect # Output: [-3, 6, -3]
52
+
53
+
54
+ ## Development
55
+
56
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
57
+
58
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
59
+
60
+ ## Contributing
61
+
62
+ Bug reports and pull requests are welcome on GitHub at https://github.com/inaidE/projectAVOCADOS.
63
+
64
+ ## License
65
+
66
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "minitest/test_task"
5
+
6
+ Minitest::TestTask.create
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[test rubocop]
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Vectors
4
+ VERSION = "0.1.0"
5
+ end
data/lib/Vectors.rb ADDED
@@ -0,0 +1,117 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "Vectors/version"
4
+
5
+ module Vectors
6
+ class Error < StandardError; end
7
+
8
+ extend self
9
+
10
+ # input: matrix - Array of arrays size of nxn
11
+ # output: res[Int] - simple Integer
12
+ def Determinant(matrix)
13
+ raise TypeError, "Ожидался массив массивов" unless matrix.is_a?(Array)
14
+
15
+ n = matrix.size
16
+
17
+ if n == 0 || !matrix.all? { |row| row.is_a?(Array) && row.size == n }
18
+ raise ArgumentError, "Матрица должна быть квадратной и непустой"
19
+ end
20
+
21
+ matrix.each do |row|
22
+ row.each do |el|
23
+ unless el.is_a?(Numeric)
24
+ raise ArgumentError, "Все элементы матрицы должны быть числовыми"
25
+ end
26
+ end
27
+ end
28
+
29
+ if n == 1
30
+ return matrix[0][0]
31
+ elsif n == 2
32
+ return matrix[0][0] * matrix[1][1] - matrix[0][1] * matrix[1][0]
33
+ else
34
+ det = 0
35
+ matrix[0].each_with_index do |element, col|
36
+ minor = matrix[1..-1].map do |row|
37
+ row.reject.with_index { |_, index| index == col}
38
+ end
39
+ det += ((-1) ** col) * element * Determinant(minor)
40
+ end
41
+ return det
42
+ end
43
+ end
44
+
45
+
46
+ # input: a[Array], b[Array]- vectors a and b;
47
+ # output: res[Int] - simple Integer as a result of scalar prod
48
+ def scalar_prod(a, b)
49
+ unless a.is_a?(Array) && b.is_a?(Array)
50
+ raise TypeError, "Вектора должны быть массивами"
51
+ end
52
+
53
+ unless a.size == b.size
54
+ raise ArgumentError, "Вектора должны иметь одинаковую длину"
55
+ end
56
+
57
+ return 0 if a.size == 0
58
+
59
+ unless a.all? { |el| el.is_a?(Numeric) } && b.all? { |el| el.is_a?(Numeric) }
60
+ raise TypeError, "Вектора должны состоять из чисел"
61
+ end
62
+
63
+ res = 0
64
+ [a, b].transpose.each { |x, y| res += x * y }
65
+
66
+ res
67
+ end
68
+
69
+ # input: a[Array], b[Array] - vectors a and b with dimension n = 3;
70
+ # output: res[Array] - vector with the size = 3 (its dimension) as a result of cross prod
71
+ def cross_prod(a, b)
72
+ raise TypeError, "Оба аргумента должны быть массивами" unless a.is_a?(Array) && b.is_a?(Array)
73
+ raise ArgumentError, "Векторы должны быть трехмерными" unless a.size == 3 && b.size == 3
74
+ raise TypeError, "Все элементы должны быть числами" unless a.all? { |x| x.is_a?(Numeric) } && b.all? { |x| x.is_a?(Numeric) }
75
+
76
+ x_component = Determinant([
77
+ [a[1], a[2]],
78
+ [b[1], b[2]]
79
+ ])
80
+
81
+ y_component = -Determinant([
82
+ [a[0], a[2]],
83
+ [b[0], b[2]]
84
+ ])
85
+
86
+ z_component = Determinant([
87
+ [a[0], a[1]],
88
+ [b[0], b[1]]
89
+ ])
90
+
91
+ [x_component, y_component, z_component]
92
+ end
93
+
94
+ # output - String with info about gem funcs
95
+ def help
96
+ puts <<~HELP
97
+ - Determinant(matrix)
98
+
99
+ input: matrix - Array of arrays size of nxn
100
+ output: res[Int] - simple Integer
101
+
102
+ - scalar_prod(a, b)
103
+
104
+ input: a[Array], b[Array]- vectors a and b
105
+ output: res[Int] - simple Integer as a result of scalar prod
106
+
107
+ - cross_prod(a, b)
108
+
109
+ input: a[Array], b[Array] - vectors a and b with dimension n = 3;
110
+ output: res[Array] - vector with the size = 3 (its dimension) as a result of cross prod
111
+ HELP
112
+ end
113
+
114
+
115
+
116
+
117
+ end
data/sig/Vectors.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Vectors
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: Vectors
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - inaidE
8
+ - spartanec22832
9
+ - t1sh3
10
+ autorequire:
11
+ bindir: exe
12
+ cert_chain: []
13
+ date: 2025-04-07 00:00:00.000000000 Z
14
+ dependencies: []
15
+ description: "A Ruby gem for vector and matrix operations. Provides methods to calculate:\n
16
+ \ - Matrix determinant:\n\n Determinant(matrix)\n\n input: matrix - Array of
17
+ arrays size of nxn\n output: res[Int] - simple Integer\n\n - Scalar product of
18
+ vectors\n\n scalar_prod(a, b)\n\n input: a[Array], b[Array]- vectors a and b\n
19
+ \ output: res[Int] - simple Integer as a result of scalar prod\n\n - Cross product
20
+ for 3D vectors\n\n cross_prod(a, b)\n\n input: a[Array], b[Array] - vectors
21
+ a and b with dimension n = 3;\n output: res[Array] - vector with the size = 3
22
+ (its dimension) as a result of cross prod\n\n - Help function\n\n help()\n\n
23
+ \ output: String with info about gem funcs\n \n Includes comprehensive error
24
+ handling and input validation. Designed for educational use and basic linear algebra
25
+ computations.\n\n Ruby-гем для операций с векторами и матрицами. Предоставляет
26
+ методы для вычисления:\n - Определителя матрицы\n\n Determinant(matrix)\n\n
27
+ \ input: matrix - матрица (массив массивов) размера nxn\n output: res[Int]
28
+ - целое число\n\n - Скалярного произведения векторов\n\n scalar_prod(a, b)\n\n
29
+ \ input: a[Array], b[Array] - векторы (массивы) a и b\n output: res[Int] -
30
+ целое число как результат скалярного произведения\n\n - Векторного произведения
31
+ для 3D векторов\n\n cross_prod(a, b)\n\n input: a[Array], b[Array] - векторы
32
+ (массивы) a и b размером n = 3;\n output: res[Array] - вектор (массив) с размером
33
+ = 3 (его размерность) как результат векторного произведения векторов\n\n - Функция
34
+ \"помощь\"\n\n help()\n\n output: Строка с информацией про математические
35
+ методы гема\n\n Включает обработку ошибок и валидацию входных данных. Разработан
36
+ для образовательных целей и базовых вычислений линейной алгебры."
37
+ email:
38
+ - perminov@sfedu.ru
39
+ - bogovskii@sfedu.ru
40
+ - dantipov@sfedu.ru
41
+ executables: []
42
+ extensions: []
43
+ extra_rdoc_files: []
44
+ files:
45
+ - ".rubocop.yml"
46
+ - LICENSE.txt
47
+ - README.md
48
+ - Rakefile
49
+ - lib/Vectors.rb
50
+ - lib/Vectors/version.rb
51
+ - sig/Vectors.rbs
52
+ homepage: https://github.com/iginaidE/Vectors
53
+ licenses:
54
+ - MIT
55
+ metadata: {}
56
+ post_install_message:
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 3.1.0
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirements: []
71
+ rubygems_version: 3.5.22
72
+ signing_key:
73
+ specification_version: 4
74
+ summary: 'Vectors: Linear Algebra Operations for calculating determinant, cross product
75
+ and scalar product | Векторы: Операции линейной алгебры для вычисления определителя,
76
+ векторного и скалярного произведений векторов'
77
+ test_files: []