Comments (6)
Thanks, but your fix results in a lazily evaluated array-reduce
on an empty array, so for instance calling array->list*
on the result gives the error:
ERROR: (array->list* (array-inner-product (make-array (make-interval '...
Exception: assertion failed
(not (interval-empty? domain))
(domain #<Interval 134075314546304>)
on line 3589 of file "./lib/srfi/231/test.sld"
(array->list* (array-inner-product (make-array (make-interval '#(4 0)) list) list list (make-array (make-interval '#(0 4)) list)))
What is the correct semantics here?
from chibi-scheme.
That's a good question. You're making something from nothing, basically.
It appears that APL does not allow empty arrays (intrinsically).
NumPy seems to suffer from the same problem: https://stackoverflow.com/questions/45282176/numpy-dot-product-with-inner-dimension-zero-gives-unexpected-result
In Matlab, matrix products are the only type of inner product, it appears, so there are multiplicative and additive identities, so reduce gives a reasonable answer: https://www.mathworks.com/help/matlab/math/empty-arrays.html See also: https://www.mathworks.com/help/matlab/matlab_prog/compatible-array-sizes-for-basic-operations.html
So I would say "It is an error if the width of the last axis of A (the same as the first axis of B) is zero".
Then it would just be a question of where to catch that error.
I'd be inclined to add (not (zero? (interval-width B-dom 0)))
to the second (and ...)
in the assert
.
from chibi-scheme.
It seems that the sample implementation recognized that this situation could happen; accessing an entry of the result of array-inner-product
threw an error with a message beginning array-inner-product: Attempting to reduce over an empty array:
I.e., the name of the caller (array-inner-product
) was passed to the internal procedure %%array-reduce
for the error message.
So the sample implementation delayed the error until there was an attempt to access an entry of the result of array-inner-product
.
I'm not sure I agree with that point of view now.
from chibi-scheme.
In Matlab, matrix products are the only type of inner product, it appears, so there are multiplicative and additive identities, so reduce gives a reasonable answer: https://www.mathworks.com/help/matlab/math/empty-arrays.html See also: https://www.mathworks.com/help/matlab/matlab_prog/compatible-array-sizes-for-basic-operations.html
So I would say "It is an error if the width of the last axis of A (the same as the first axis of B) is zero".
Unless you have a neutral element for the addition (which you don't supply array-inner-product
with), it has to be an error.
In most natural applications, however, there is a neutral element, so array-inner-product
does not catch the common situations quite right. A better version would take a ring (e.g., modelled by a record) that encodes addition, multiplication, and neutral elements.
Then it would just be a question of where to catch that error.
I'd be inclined to add
(not (zero? (interval-width B-dom 0)))
to the second(and ...)
in theassert
.
Dimensions are never lazily calculated, are they? If so, the check should be performed eagerly.
from chibi-scheme.
Rather than introducing a ring concept, taking a neutral element as an optional parameter is easier, but the SRFI is finalized. Changed to fail fast.
from chibi-scheme.
A better version would take a ring (e.g., modelled by a record) that encodes addition, multiplication, and neutral elements.
I want to push back on this a bit.
The data in arrays have no intrinsic algebraic or mathematical structure. I haven't wanted to complicate this SRFI (it's complicated enough!) by building in the possibility of specifying algebraic structures for some of the operations.
from chibi-scheme.
Related Issues (20)
- SRFI 231: array-stack issues HOT 1
- SRFI 231: make-interval fix
- SRFI 231: array-append HOT 1
- SRFI 231: no array-fold-{left|right} HOT 4
- SRFI 231: fix for interval-contains-multi-index?
- SRFI 231: Fix interval-fold-left HOT 1
- SRFI 231: Fix flatten-vector->list
- SRFI 231: array-append redux
- Installing without sudo on Ubuntu 22.04
- SRFI 231: No error checking in storage-class-data? and storage-class-data->body HOT 2
- SRFI 231: interval-cartesian-product fix
- SRFI 231: interval-intersect fix
- SRFI 231: generic-storage-class fix
- SRFI 231: specialized-array-reshape issues HOT 2
- SRFI 231: specialized-array-reshape! "fix"
- f16<->double HOT 8
- 0.11 commit DETACHED from master?? HOT 2
- SEXP_USE_MUTABLE_STRINGS 0 is pretty broken HOT 1
- Syntactic closures behave unexpectedly (different from MIT scheme) HOT 21
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chibi-scheme.