Skip to content

Commit

Permalink
Merge pull request #5 from ambaker1/null-tensor
Browse files Browse the repository at this point in the history
null tensor now supported.
  • Loading branch information
ambaker1 authored Oct 15, 2023
2 parents e840729 + 3cebb5c commit 9fce62e
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 13 deletions.
4 changes: 2 additions & 2 deletions build.tcl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package require tin 1.0
tin import assert from tin
tin import tcltest
set version 0.3
set version 0.3.1
set config ""
dict set config VERSION $version

Expand All @@ -19,7 +19,7 @@ puts "Running all tests..."
source tests/vector_test.tcl
source tests/matrix_test.tcl
source tests/tensor_test.tcl
source tests/examples.tcl
source tests/examples.tcl

# Check number of failed tests
set nFailed $::tcltest::numTests(Failed)
Expand Down
Binary file modified doc/ndlist.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion doc/template/version.tex
Original file line number Diff line number Diff line change
@@ -1 +1 @@
\newcommand{\version}{0.3}
\newcommand{\version}{0.3.1}
2 changes: 1 addition & 1 deletion install.tcl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package require tin 1.0
set dir [tin mkdir -force ndlist 0.3]
set dir [tin mkdir -force ndlist 0.3.1]
file copy pkgIndex.tcl ndlist.tcl vector.tcl matrix.tcl tensor.tcl $dir
file copy README.md LICENSE $dir
2 changes: 1 addition & 1 deletion ndlist.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ namespace eval ::ndlist {
}

# Finally, provide the package
package provide ndlist 0.3
package provide ndlist 0.3.1
2 changes: 1 addition & 1 deletion pkgIndex.tcl
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
if {![package vsatisfies [package provide Tcl] 8.6]} {return}
package ifneeded ndlist 0.3 [list source [file join $dir ndlist.tcl]]
package ifneeded ndlist 0.3.1 [list source [file join $dir ndlist.tcl]]
8 changes: 6 additions & 2 deletions src/tensor.tin
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ proc ::ndlist::IsShape {ndlist args} {
# GetShape --
#
# Private procedure to get list of dimensions of an ND-list along first index
# Returns error if there is a null dimension along an axis.
# Returns error if there is a null dimension along a non-zero axis.
#
# Syntax:
# GetShape $ndims $ndlist
Expand All @@ -125,11 +125,15 @@ proc ::ndlist::IsShape {ndlist args} {
# ndlist ND-list to get dimensions from

proc ::ndlist::GetShape {ndims ndlist} {
# Null case
if {[llength $ndlist] == 0} {
return [lrepeat $ndims 0]
}
# Get list of dimensions (along first index)
set dims ""
foreach axis [range $ndims] {
if {[llength $ndlist] == 0} {
return -code error "null dimension along axis $axis"
return -code error "null dimension along non-zero axis"
}
lappend dims [llength $ndlist]
set ndlist [lindex $ndlist 0]
Expand Down
8 changes: 6 additions & 2 deletions tensor.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ proc ::ndlist::IsShape {ndlist args} {
# GetShape --
#
# Private procedure to get list of dimensions of an ND-list along first index
# Returns error if there is a null dimension along an axis.
# Returns error if there is a null dimension along a non-zero axis.
#
# Syntax:
# GetShape $ndims $ndlist
Expand All @@ -125,11 +125,15 @@ proc ::ndlist::IsShape {ndlist args} {
# ndlist ND-list to get dimensions from

proc ::ndlist::GetShape {ndims ndlist} {
# Null case
if {[llength $ndlist] == 0} {
return [lrepeat $ndims 0]
}
# Get list of dimensions (along first index)
set dims ""
foreach axis [range $ndims] {
if {[llength $ndlist] == 0} {
return -code error "null dimension along axis $axis"
return -code error "null dimension along non-zero axis"
}
lappend dims [llength $ndlist]
set ndlist [lindex $ndlist 0]
Expand Down
6 changes: 3 additions & 3 deletions tests/tensor_test.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ test nshape {
nshape 2D {{1 2} {3 4} {5 6}}
} -result {3 2}

# Blanks must be contained within a list.
test nshape_blank0 {} -body {nshape 2D ""} -returnCodes {1} -result {null dimension along axis 0}
test nshape_blank1 {} -body {nshape 2D {{}}} -returnCodes {1} -result {null dimension along axis 1}
# Blanks must be contained within a list, unless if entire ndlist is blank.
test nshape_blank0 {} -body {nshape 2D ""} -result {0 0}
test nshape_blank1 {} -body {nshape 2D {{}}} -returnCodes {1} -result {null dimension along non-zero axis}
test nshape_blank2 {} {nshape 2D {{{}}}} {1 1}

# nsize
Expand Down

0 comments on commit 9fce62e

Please sign in to comment.