Skip to content

Commit facf6d5

Browse files
committed
Add literal matrix and vector constructors
1 parent 3778d34 commit facf6d5

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

src/ricci.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
import LinearAlgebra
77

8+
export vector
9+
export matrix
10+
811
abstract type Tensor end
912

1013
Value = Union{Tensor,Real}
@@ -62,6 +65,14 @@ function Base.:(==)(left::Literal, right::Literal)
6265
return left.value == right.value && left.indices == right.indices
6366
end
6467

68+
function vector(arg::Real)
69+
return Literal(arg, Upper(1))
70+
end
71+
72+
function matrix(arg::Real)
73+
return Literal(arg, Upper(1), Lower(2))
74+
end
75+
6576
function are_unique(arg::AbstractArray)
6677
return length(unique(arg)) == length(arg)
6778
end

test/RicciTest.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ end
3838
@test Literal(2) isa Literal
3939
end
4040

41+
@testset "Literal vector constructor" begin
42+
@test vector(2) == Literal(2, Upper(1))
43+
@test vector(4.2) == Literal(4.2, Upper(1))
44+
end
45+
46+
@testset "Literal matrix constructor" begin
47+
@test matrix(2) == Literal(2, Upper(1), Lower(2))
48+
@test matrix(4.2) == Literal(4.2, Upper(1), Lower(2))
49+
end
50+
4151
@testset "index equality operator" begin
4252
left = Lower(3)
4353
right = Lower(3)

0 commit comments

Comments
 (0)