-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Vectors implemented and README update
Implemented basic vector Created files Wrote tests for vector initialize Implemented basic vector enumerables Vectors done readme update readme update
- Loading branch information
Showing
14 changed files
with
278 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--color |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
source 'https://rubygems.org' | ||
|
||
# Specify your gem's dependencies in daru.gemspec | ||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
PATH | ||
remote: . | ||
specs: | ||
daru (0.0.1) | ||
|
||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
diff-lcs (1.2.5) | ||
json (1.8.1) | ||
nmatrix (0.1.0.rc5) | ||
rdoc (~> 4.0, >= 4.0.1) | ||
rdoc (4.1.2) | ||
json (~> 1.4) | ||
rspec (3.1.0) | ||
rspec-core (~> 3.1.0) | ||
rspec-expectations (~> 3.1.0) | ||
rspec-mocks (~> 3.1.0) | ||
rspec-core (3.1.5) | ||
rspec-support (~> 3.1.0) | ||
rspec-expectations (3.1.2) | ||
diff-lcs (>= 1.2.0, < 2.0) | ||
rspec-support (~> 3.1.0) | ||
rspec-mocks (3.1.2) | ||
rspec-support (~> 3.1.0) | ||
rspec-support (3.1.1) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
bundler | ||
daru! | ||
nmatrix (~> 0.1.0.rc5) | ||
rspec (~> 3.0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# coding: utf-8 | ||
$:.unshift File.expand_path("../lib", __FILE__) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
require 'version.rb' | ||
|
||
DESCRIPTION = <<MSG | ||
Daru (Data Analysis in RUby) is a library for storage, analysis and manipulation | ||
of data. | ||
MSG | ||
|
||
Gem::Specification.new do |spec| | ||
spec.name = 'daru' | ||
spec.version = Daru::VERSION | ||
spec.authors = ['Sameer Deshmukh'] | ||
spec.email = ['sameer.deshmukh93@gmail.com'] | ||
spec.summary = %q{Data Analysis in RUby} | ||
spec.description = DESCRIPTION | ||
spec.homepage = "http://github.com/v0dro/daru" | ||
spec.license = 'BSD-2' | ||
|
||
spec.files = `git ls-files -z`.split("\x0") | ||
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } | ||
spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) | ||
spec.require_paths = ["lib"] | ||
|
||
spec.add_development_dependency 'bundler' | ||
spec.add_development_dependency 'rspec', '~> 3.0' | ||
spec.add_development_dependency 'nmatrix', '~> 0.1.0.rc5' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'securerandom' | ||
require 'matrix' | ||
|
||
require 'daru/vector.rb' | ||
require 'daru/dataframe.rb' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module Daru | ||
class DataFrame | ||
def initialize source, name=SecureRandom.uuid | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
module Daru | ||
class Vector | ||
include Enumerable | ||
|
||
def each(&block) | ||
@vector.each(&block) | ||
end | ||
|
||
attr_reader :name | ||
|
||
attr_reader :size | ||
|
||
def initialize source, name=nil | ||
|
||
if source.is_a?(Hash) | ||
initialize source.values[0], source.keys[0] | ||
else | ||
@name = name || SecureRandom.uuid | ||
|
||
@vector = | ||
case source | ||
when Range, Matrix | ||
source.to_a.flatten | ||
else | ||
source | ||
end | ||
|
||
@size = @vector.size | ||
end | ||
end | ||
|
||
def [](index) | ||
@vector[index] | ||
end | ||
|
||
def to_json | ||
@vector.to_a.to_json | ||
end | ||
|
||
def to_a | ||
@vector.to_a | ||
end | ||
|
||
def to_html threshold=15 | ||
html = '<table><tr><th>' + @name.to_s + '</th></tr>>' | ||
|
||
@vector.to_a.each_with_index do |el,i| | ||
next if threshold < i and i < @arr.length-1 | ||
content = i == threshold ? '...' : el.to_s | ||
html.concat('<tr><td>' + content + '</td></tr>') | ||
end | ||
|
||
html += '</table>' | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module Daru | ||
VERSION = "0.0.1" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Tests if interpreter is JRuby |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Tests if interpreter is JRuby | ||
|
||
# describe Daru::Vector do | ||
# context ".initialize" do | ||
# it "creates a vector object with an MDArray" do | ||
# vector = Daru::Vector.new(MDArray.new([5], [1,2,3,4,5]), :uhura) | ||
|
||
# expect(vector[1]) .to eq(2) | ||
# expect(vector.name).to eq(:uhura) | ||
# end | ||
|
||
# it "creates a vector object with a Hash with different values" do | ||
# vector = Daru::Vector.new { sulu: MDArray.new([5], [1,2,3,4,5])} | ||
|
||
# expect(vector[1]) .to eq(2) | ||
# expect(vector.name).to eq(:sulu) | ||
# end | ||
# end | ||
# end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'spec_helper.rb' | ||
|
||
describe Daru::DataFrame do | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
require 'spec_helper.rb' | ||
|
||
describe Daru::Vector do | ||
context "#initialize" do | ||
it "creates a vector object with an Array" do | ||
vector = Daru::Vector.new [1,2,3,4,5], :mowgli | ||
|
||
expect(vector[1]) .to eq(2) | ||
expect(vector.name).to eq(:mowgli) | ||
end | ||
|
||
it "creates a vector object with a Range" do | ||
vector = Daru::Vector.new 1..5, :bakasur | ||
|
||
expect(vector[1]) .to eq(2) | ||
expect(vector.name).to eq(:bakasur) | ||
end | ||
|
||
it "creates a vector object with an NMatrix" do | ||
vector = Daru::Vector.new(NMatrix.new([5], [1,2,3,4,5], | ||
dtype: :int32), :scotty) | ||
|
||
expect(vector[1]) .to eq(2) | ||
expect(vector.name).to eq(:scotty) | ||
end | ||
|
||
it "creates a vector object with a Matrix" do | ||
vector = Daru::Vector.new Matrix[[1,2,3,4,5]], :ravan | ||
|
||
expect(vector[1]) .to eq(2) | ||
expect(vector.name).to eq(:ravan) | ||
end | ||
|
||
it "creates a vector object with a Hash with different values" do | ||
vector = Daru::Vector.new({orion: [1,2,3,4,5]}) | ||
|
||
expect(vector[1]) .to eq(2) | ||
expect(vector.name).to eq(:orion) | ||
|
||
vector = Daru::Vector.new({ kirk: 1..5 }) | ||
|
||
expect(vector[1]) .to eq(2) | ||
expect(vector.name).to eq(:kirk) | ||
|
||
vector = Daru::Vector.new({ spock: NMatrix.new([5], [1,2,3,4,5], | ||
dtype: :int32) }) | ||
|
||
expect(vector[1]) .to eq(2) | ||
expect(vector.name).to eq(:spock) | ||
end | ||
|
||
it "auto assigns a name if not specified" do | ||
earth = Daru::Vector.new 1..5 | ||
organion = Daru::Vector.new 1..5 | ||
|
||
expect(earth.name == organion.name).to eq(false) | ||
end | ||
end | ||
|
||
context "tests for methods" do | ||
before do | ||
@anakin = Daru::Vector.new NMatrix.new([5], [1,2,3,4,5]), :anakin | ||
@luke = Daru::Vector.new NMatrix.new([3], [3,4,5,6]) , :luke | ||
end | ||
|
||
it "checks for an each block" do | ||
sum = 0 | ||
|
||
@anakin.each{ |e| sum += e} | ||
expect(sum).to eq(15) | ||
end | ||
|
||
it "checks for inequality of vectors" do | ||
expect(@anakin == @luke).to be(false) | ||
end | ||
|
||
it "calculates maximum value" do | ||
expect(@anakin.max).to eq(5) | ||
end | ||
|
||
it "calculates minimmum value" do | ||
expect(@anakin.min).to eq(1) | ||
end | ||
|
||
it "delegates to the internal array storage" do | ||
expect(@anakin.size).to eq(@anakin.to_a.size) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
require 'rspec' | ||
require 'nmatrix' | ||
|
||
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) | ||
$LOAD_PATH.unshift(File.dirname(__FILE__)) | ||
require 'daru' |
@v0dro What does this line do?