Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8949509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:14:06+00:00 2026-06-15T13:14:06+00:00

Looking for the proper data type (such as IndexedSeq[Double] ) to use when designing

  • 0

Looking for the proper data type (such as IndexedSeq[Double]) to use when designing a domain-specific numerical computing library. For this question, I’m limiting scope to working with 1-Dimensional arrays of Double. The library will define a number functions that are typically applied for each element in the 1D array.

Considerations:

  • Prefer immutable data types, such as Vector or IndexedSeq
  • Want to minimize data conversions
  • Reasonably efficient in space and time
  • Friendly for other people using the library
  • Elegant and clean API

Should I use something higher up the collections hierarchy, such as Seq?

Or is it better to just define the single-element functions and leave the mapping/iterating to the end user?

This seems less efficient (since some computations could be done once per set of calls), but at at the same time a more flexible API, since it would work with any type of collection.

Any recommendations?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T13:14:07+00:00Added an answer on June 15, 2026 at 1:14 pm

    If your computations are to do anything remotely computationally intensive, use Array, either raw or wrapped in your own classes. You can provide a collection-compatible wrapper, but make that an explicit wrapper for interoperability only. Everything other than Array is generic and thus boxed and thus comparatively slow and bulky.

    If you do not use Array, people will be forced to abandon whatever things you have and just use Array instead when performance matters. Maybe that’s okay; maybe you want the computations to be there for convenience not efficiency. In that case, I suggest using IndexedSeq for the interface, assuming that you want to let people know that indexing is not outrageously slow (e.g. is not List), and use Vector under the hood. You will use about 4x more memory than Array[Double], and be 3-10x slower for most low-effort operations (e.g. multiplication).

    For example, this:

    val u = v.map(1.0 / _)   //  v is Vector[Double]
    

    is about three times slower than this:

    val u = new Array[Double](v.length)
    var j = 0
    while (j<u.length) {
      u(j) = 1.0/v(j)      // v is Array[Double]
      j += 1
    }
    

    If you use the map method on Array, it’s just as slow as the Vector[Double] way; operations on Array are generic and hence boxed. (And that’s where the majority of the penalty comes from.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for the proper data structure for this scenario. I have boost available
I am looking for the proper term to describe this well-known property of collection
I tried looking this up on here but couldnt find a proper answer. I
I was looking a proper way to implment a ScaleAnimation. My purpose is to
Ive been looking for a proper rounding mechanism but nothing I find seems to
Looking to do a bit of refactoring... Using NHibernate I have this query currently
Looking for best advice on how to do this: I have an insert like
I have been looking for a solution to this problem for a while now
I am looking for a proper way to test the time it takes a
What I'm looking for is a succinct way to fetch a core-data object that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.